go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/auth/integration/gsutil/boto_test.go (about) 1 // Copyright 2017 The LUCI Authors. 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 gsutil 16 17 import ( 18 "fmt" 19 "io/ioutil" 20 "os" 21 "path/filepath" 22 "testing" 23 24 . "github.com/smartystreets/goconvey/convey" 25 ) 26 27 func TestBoto(t *testing.T) { 28 t.Parallel() 29 30 Convey("Works", t, func(c C) { 31 tmpDir, err := ioutil.TempDir("", "luci_boto_test") 32 So(err, ShouldBeNil) 33 Reset(func() { os.RemoveAll(tmpDir) }) 34 35 write := func(b *Boto) { 36 b.StateDir = tmpDir 37 _, err := PrepareStateDir(b) 38 So(err, ShouldBeNil) 39 } 40 41 read := func() string { 42 buf, err := os.ReadFile(filepath.Join(tmpDir, ".boto")) 43 So(err, ShouldBeNil) 44 return string(buf) 45 } 46 47 Convey("Minimal", func() { 48 write(&Boto{}) 49 So(read(), ShouldEqual, fmt.Sprintf(`# Autogenerated by LUCI. Do not edit. 50 51 [GSUtil] 52 software_update_check_period = 0 53 state_dir = %s 54 `, tmpDir)) 55 }) 56 57 Convey("Full", func() { 58 write(&Boto{ 59 RefreshToken: "zzz", 60 GCEServiceAccount: "default", 61 ProviderLabel: "Some label", 62 ProviderAuthURI: "http://127.0.0.1/auth_uri", 63 ProviderTokenURI: "http://127.0.0.1/token_uri", 64 }) 65 So(read(), ShouldEqual, fmt.Sprintf(`# Autogenerated by LUCI. Do not edit. 66 67 [GSUtil] 68 software_update_check_period = 0 69 state_dir = %s 70 71 [Credentials] 72 gs_oauth2_refresh_token = zzz 73 74 [GoogleCompute] 75 service_account = default 76 77 [OAuth2] 78 provider_label = Some label 79 provider_authorization_uri = http://127.0.0.1/auth_uri 80 provider_token_uri = http://127.0.0.1/token_uri 81 `, tmpDir)) 82 }) 83 }) 84 }