| // Copyright 2017 The LUCI Authors. |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| package gsutil |
| |
| import ( |
| "fmt" |
| "io/ioutil" |
| "os" |
| "path/filepath" |
| "testing" |
| |
| . "github.com/smartystreets/goconvey/convey" |
| ) |
| |
| func TestBoto(t *testing.T) { |
| t.Parallel() |
| |
| Convey("Works", t, func(c C) { |
| tmpDir, err := ioutil.TempDir("", "luci_boto_test") |
| So(err, ShouldBeNil) |
| Reset(func() { os.RemoveAll(tmpDir) }) |
| |
| write := func(b *Boto) { |
| b.StateDir = tmpDir |
| _, err := PrepareStateDir(b) |
| So(err, ShouldBeNil) |
| } |
| |
| read := func() string { |
| buf, err := os.ReadFile(filepath.Join(tmpDir, ".boto")) |
| So(err, ShouldBeNil) |
| return string(buf) |
| } |
| |
| Convey("Minimal", func() { |
| write(&Boto{}) |
| So(read(), ShouldEqual, fmt.Sprintf(`# Autogenerated by LUCI. Do not edit. |
| |
| [GSUtil] |
| software_update_check_period = 0 |
| state_dir = %s |
| `, tmpDir)) |
| }) |
| |
| Convey("Full", func() { |
| write(&Boto{ |
| RefreshToken: "zzz", |
| GCEServiceAccount: "default", |
| ProviderLabel: "Some label", |
| ProviderAuthURI: "http://127.0.0.1/auth_uri", |
| ProviderTokenURI: "http://127.0.0.1/token_uri", |
| }) |
| So(read(), ShouldEqual, fmt.Sprintf(`# Autogenerated by LUCI. Do not edit. |
| |
| [GSUtil] |
| software_update_check_period = 0 |
| state_dir = %s |
| |
| [Credentials] |
| gs_oauth2_refresh_token = zzz |
| |
| [GoogleCompute] |
| service_account = default |
| |
| [OAuth2] |
| provider_label = Some label |
| provider_authorization_uri = http://127.0.0.1/auth_uri |
| provider_token_uri = http://127.0.0.1/token_uri |
| `, tmpDir)) |
| }) |
| }) |
| } |