| 1 | package runner |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestJobGitAuthScopedToProject(t *testing.T) { |
| 6 | env := map[string]string{"GIT_CONFIG_COUNT": "1", "GIT_CONFIG_KEY_0": "safe.directory", "GIT_CONFIG_VALUE_0": "*"} |
| 7 | JobGitAuth(env, "https://git.example/tim/app", "bgj_x") |
| 8 | if env["GIT_CONFIG_COUNT"] != "3" || env["GIT_CONFIG_KEY_0"] != "safe.directory" { |
| 9 | t.Fatalf("count/keep: %v", env) |
| 10 | } |
| 11 | if env["GIT_CONFIG_KEY_1"] != "http.https://git.example/tim/app.extraHeader" || env["GIT_CONFIG_KEY_2"] != "http.https://git.example/tim/app.git.extraHeader" { |
| 12 | t.Fatalf("keys: %v", env) |
| 13 | } |
| 14 | if env["GIT_CONFIG_VALUE_1"] != "Authorization: Bearer bgj_x" { |
| 15 | t.Fatalf("value: %v", env) |
| 16 | } |
| 17 | none := map[string]string{} |
| 18 | JobGitAuth(none, "", "bgj_x") |
| 19 | if len(none) != 0 { |
| 20 | t.Fatal("no URL: no config") |
| 21 | } |
| 22 | } |