go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/auth/authctx/git_test.go (about) 1 // Copyright 2019 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 authctx 16 17 import ( 18 "io/ioutil" 19 "os" 20 "path/filepath" 21 "testing" 22 23 . "github.com/smartystreets/goconvey/convey" 24 ) 25 26 func TestGitConfig(t *testing.T) { 27 t.Parallel() 28 29 Convey("Works", t, func() { 30 tmp, err := ioutil.TempDir("", "") 31 So(err, ShouldBeNil) 32 defer os.RemoveAll(tmp) 33 34 gen := func(name string, cfg gitConfig) string { 35 So(cfg.Write(filepath.Join(tmp, name)), ShouldBeNil) 36 body, err := os.ReadFile(filepath.Join(tmp, name)) 37 So(err, ShouldBeNil) 38 return string(body) 39 } 40 41 cfg := gitConfig{ 42 IsWindows: false, 43 UserEmail: "email@example.com", 44 UserName: "name", 45 UseCredentialHelper: true, 46 KnownGerritHosts: []string{"host-a", "host-b"}, 47 } 48 49 So(gen("unix", cfg), ShouldEqual, `# Autogenerated. 50 51 [user] 52 email = email@example.com 53 name = name 54 55 [core] 56 deltaBaseCacheLimit = 2g 57 58 [pack] 59 packSizeLimit = 2g 60 61 # Reduce noise. 62 [advice] 63 detachedHead = false 64 65 [http] 66 version = HTTP/1.1 67 # Request the GFE return debug headers as an encrypted blob in 68 # X-Encrypted-Debug-Headers. 69 extraheader = X-Return-Encrypted-Headers: all 70 71 [gc] 72 autodetach = false 73 74 [credential] 75 helper = 76 helper = luci 77 78 [url "https://host-a/a/"] 79 insteadOf = https://host-a/a/ 80 insteadOf = https://host-a/ 81 82 [url "https://host-b/a/"] 83 insteadOf = https://host-b/a/ 84 insteadOf = https://host-b/ 85 `) 86 87 cfg.IsWindows = true 88 So(gen("win", cfg), ShouldEqual, `# Autogenerated. 89 90 [user] 91 email = email@example.com 92 name = name 93 94 [core] 95 deltaBaseCacheLimit = 2g 96 fscache = true 97 symlinks = false 98 autocrlf = false 99 filemode = false 100 101 [pack] 102 packSizeLimit = 2g 103 104 # Reduce noise. 105 [advice] 106 detachedHead = false 107 108 [http] 109 version = HTTP/1.1 110 # Request the GFE return debug headers as an encrypted blob in 111 # X-Encrypted-Debug-Headers. 112 extraheader = X-Return-Encrypted-Headers: all 113 114 [diff "astextplain"] 115 textconv = astextplain 116 117 [gc] 118 autodetach = false 119 120 [credential] 121 helper = 122 helper = luci 123 124 [url "https://host-a/a/"] 125 insteadOf = https://host-a/a/ 126 insteadOf = https://host-a/ 127 128 [url "https://host-b/a/"] 129 insteadOf = https://host-b/a/ 130 insteadOf = https://host-b/ 131 `) 132 }) 133 }