| 1 | // Copyright 2015 Google Inc. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package gcsfake_testscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ |
| 16 | |
| 17 | import ( |
| 18 | "testingscip-go gomod github.com/golang/go/src go1.20 testing/" |
| 19 | "timescip-go gomod github.com/golang/go/src go1.20 time/" |
| 20 | |
| 21 | "golang.org/x/net/contextscip-go gomod golang.org/x/net fe4d6282115f `golang.org/x/net/context`/" |
| 22 | |
| 23 | "github.com/jacobsa/gcloud/gcsscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs`/" |
| 24 | "github.com/jacobsa/gcloud/gcs/gcsfakescip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake`/" |
| 25 | "github.com/jacobsa/gcloud/gcs/gcsutilscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsutil`/" |
| 26 | . "github.com/jacobsa/ogletestscip-go gomod github.com/jacobsa/ogletest 80d50a735a11 `github.com/jacobsa/ogletest`/" |
| 27 | "github.com/jacobsa/timeutilscip-go gomod github.com/jacobsa/timeutil 577e5acbbcf6 `github.com/jacobsa/timeutil`/" |
| 28 | ) |
| 29 | |
| 30 | func TestConnscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/TestConn().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { RunTestsscip-go gomod github.com/jacobsa/ogletest 80d50a735a11 `github.com/jacobsa/ogletest`/RunTests().(t) } |
| 31 | |
| 32 | //////////////////////////////////////////////////////////////////////// |
| 33 | // Boilerplate |
| 34 | //////////////////////////////////////////////////////////////////////// |
| 35 | |
| 36 | type ConnTestscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest# struct { |
| 37 | ctxscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#ctx. contextscip-go gomod golang.org/x/net fe4d6282115f `golang.org/x/net/context`/.Contextscip-go gomod golang.org/x/net fe4d6282115f `golang.org/x/net/context`/Context# |
| 38 | clockscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#clock. timeutilscip-go gomod github.com/jacobsa/timeutil 577e5acbbcf6 `github.com/jacobsa/timeutil`/.SimulatedClockscip-go gomod github.com/jacobsa/timeutil 577e5acbbcf6 `github.com/jacobsa/timeutil`/SimulatedClock# |
| 39 | connscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#conn. gcsscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs`/.Connscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs`/Conn# |
| 40 | } |
| 41 | |
| 42 | func initscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/init().() { RegisterTestSuitescip-go gomod github.com/jacobsa/ogletest 80d50a735a11 `github.com/jacobsa/ogletest`/RegisterTestSuite().(&ConnTestscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#{}) } |
| 43 | |
| 44 | var _ SetUpInterfacescip-go gomod github.com/jacobsa/ogletest 80d50a735a11 `github.com/jacobsa/ogletest`/SetUpInterface# = &ConnTestscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#{} |
| 45 | |
| 46 | func (t *ConnTestscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#) SetUpscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#SetUp().(ti *TestInfoscip-go gomod github.com/jacobsa/ogletest 80d50a735a11 `github.com/jacobsa/ogletest`/TestInfo#) { |
| 47 | t.ctxscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#ctx. = ti.Ctxscip-go gomod github.com/jacobsa/ogletest 80d50a735a11 `github.com/jacobsa/ogletest`/TestInfo#Ctx. |
| 48 | t.clockscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#clock..SetTimescip-go gomod github.com/jacobsa/timeutil 577e5acbbcf6 `github.com/jacobsa/timeutil`/SimulatedClock#SetTime().(timescip-go gomod github.com/golang/go/src go1.20 time/.Datescip-go gomod github.com/golang/go/src go1.20 time/Date().(2012, 8, 15, 22, 56, 0, 0, timescip-go gomod github.com/golang/go/src go1.20 time/.Localscip-go gomod github.com/golang/go/src go1.20 time/Local.)) |
| 49 | t.connscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#conn. = gcsfakescip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake`/.NewConnscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake`/NewConn().(&t.clockscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#clock.) |
| 50 | } |
| 51 | |
| 52 | //////////////////////////////////////////////////////////////////////// |
| 53 | // Tests |
| 54 | //////////////////////////////////////////////////////////////////////// |
| 55 | |
| 56 | func (t *ConnTestscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#) BucketContentsAreStablescip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#BucketContentsAreStable().() { |
| 57 | const bucketName = "foo" |
| 58 | const objName = "bar" |
| 59 | |
| 60 | var err error |
| 61 | |
| 62 | // Open the bucket. |
| 63 | bucket, err := t.connscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#conn..OpenBucketscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs`/Conn#OpenBucket.(t.ctxscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#ctx., &gcsscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs`/.OpenBucketOptionsscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs`/OpenBucketOptions#{Namescip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs`/OpenBucketOptions#Name.: bucketName}) |
| 64 | AssertEqscip-go gomod github.com/jacobsa/ogletest 80d50a735a11 `github.com/jacobsa/ogletest`/AssertEq().(nil, err) |
| 65 | |
| 66 | // Add an object to a bucket. |
| 67 | _, err = gcsutilscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsutil`/.CreateObjectscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsutil`/CreateObject().( |
| 68 | t.ctxscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#ctx., |
| 69 | bucket, |
| 70 | objName, |
| 71 | []byte("taco")) |
| 72 | |
| 73 | AssertEqscip-go gomod github.com/jacobsa/ogletest 80d50a735a11 `github.com/jacobsa/ogletest`/AssertEq().(nil, err) |
| 74 | |
| 75 | // Grab the bucket again. It should still be there. |
| 76 | contents, err := gcsutilscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsutil`/.ReadObjectscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsutil`/ReadObject().( |
| 77 | t.ctxscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#ctx., |
| 78 | bucket, |
| 79 | objName) |
| 80 | |
| 81 | AssertEqscip-go gomod github.com/jacobsa/ogletest 80d50a735a11 `github.com/jacobsa/ogletest`/AssertEq().(nil, err) |
| 82 | ExpectEqscip-go gomod github.com/jacobsa/ogletest 80d50a735a11 `github.com/jacobsa/ogletest`/ExpectEq().("taco", string(contents)) |
| 83 | } |
| 84 | |
| 85 | func (t *ConnTestscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#) BucketsAreSegregatedByNamescip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#BucketsAreSegregatedByName().() { |
| 86 | const objName = "baz" |
| 87 | var contents []byte |
| 88 | var err error |
| 89 | |
| 90 | b0, err := t.connscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#conn..OpenBucketscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs`/Conn#OpenBucket.(t.ctxscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#ctx., &gcsscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs`/.OpenBucketOptionsscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs`/OpenBucketOptions#{Namescip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs`/OpenBucketOptions#Name.: "foo"}) |
| 91 | AssertEqscip-go gomod github.com/jacobsa/ogletest 80d50a735a11 `github.com/jacobsa/ogletest`/AssertEq().(nil, err) |
| 92 | |
| 93 | b1, err := t.connscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#conn..OpenBucketscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs`/Conn#OpenBucket.(t.ctxscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#ctx., &gcsscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs`/.OpenBucketOptionsscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs`/OpenBucketOptions#{Namescip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs`/OpenBucketOptions#Name.: "bar"}) |
| 94 | AssertEqscip-go gomod github.com/jacobsa/ogletest 80d50a735a11 `github.com/jacobsa/ogletest`/AssertEq().(nil, err) |
| 95 | |
| 96 | // Add an object with the same name but different contents to each of two |
| 97 | // buckets. |
| 98 | _, err = gcsutilscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsutil`/.CreateObjectscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsutil`/CreateObject().(t.ctxscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#ctx., b0, objName, []byte("taco")) |
| 99 | AssertEqscip-go gomod github.com/jacobsa/ogletest 80d50a735a11 `github.com/jacobsa/ogletest`/AssertEq().(nil, err) |
| 100 | |
| 101 | _, err = gcsutilscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsutil`/.CreateObjectscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsutil`/CreateObject().(t.ctxscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#ctx., b1, objName, []byte("burrito")) |
| 102 | AssertEqscip-go gomod github.com/jacobsa/ogletest 80d50a735a11 `github.com/jacobsa/ogletest`/AssertEq().(nil, err) |
| 103 | |
| 104 | // Each should have stored it independently. |
| 105 | contents, err = gcsutilscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsutil`/.ReadObjectscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsutil`/ReadObject().(t.ctxscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#ctx., b0, objName) |
| 106 | AssertEqscip-go gomod github.com/jacobsa/ogletest 80d50a735a11 `github.com/jacobsa/ogletest`/AssertEq().(nil, err) |
| 107 | ExpectEqscip-go gomod github.com/jacobsa/ogletest 80d50a735a11 `github.com/jacobsa/ogletest`/ExpectEq().("taco", string(contents)) |
| 108 | |
| 109 | contents, err = gcsutilscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsutil`/.ReadObjectscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsutil`/ReadObject().(t.ctxscip-go gomod github.com/jacobsa/gcloud . `github.com/jacobsa/gcloud/gcs/gcsfake_test`/ConnTest#ctx., b1, objName) |
| 110 | AssertEqscip-go gomod github.com/jacobsa/ogletest 80d50a735a11 `github.com/jacobsa/ogletest`/AssertEq().(nil, err) |
| 111 | ExpectEqscip-go gomod github.com/jacobsa/ogletest 80d50a735a11 `github.com/jacobsa/ogletest`/ExpectEq().("burrito", string(contents)) |
| 112 | } |