gunk-dev/the-valley

env_test.go

sourced472c3909b6fmain's published tip history
1.4 KiB
1package main
2
3import (
4 "slices"
5 "testing"
6)
7
8// The unit hands every controller its safe.directory exceptions as
9// command-scope configuration, and git reads those entries only up to the
10// count. Dropping everything else means renumbering what is kept, and an
11// entry left past the count would be one git silently ignores.
12func TestOnlySafeDirectoryConfigurationIsInheritedAndReplacementRefsAreOff(t *testing.T) {
13 got := gitEnvironment([]string{
14 "PATH=/bin",
15 "GIT_DIR=/elsewhere",
16 "GIT_CONFIG_COUNT=3",
17 "GIT_CONFIG_KEY_0=core.useReplaceRefs",
18 "GIT_CONFIG_VALUE_0=true",
19 "GIT_CONFIG_KEY_1=safe.directory",
20 "GIT_CONFIG_VALUE_1=/srv/git/project.git",
21 "GIT_CONFIG_KEY_2=safe.directory",
22 "GIT_CONFIG_VALUE_2=/srv/git/instance.git",
23 "GIT_CONFIG_PARAMETERS='core.usereplacerefs'='true'",
24 })
25 for _, want := range []string{
26 "PATH=/bin",
27 "GIT_CONFIG_COUNT=2",
28 "GIT_CONFIG_KEY_0=safe.directory",
29 "GIT_CONFIG_VALUE_0=/srv/git/project.git",
30 "GIT_CONFIG_KEY_1=safe.directory",
31 "GIT_CONFIG_VALUE_1=/srv/git/instance.git",
32 "GIT_NO_REPLACE_OBJECTS=1",
33 "GIT_CONFIG_GLOBAL=/dev/null",
34 } {
35 if !slices.Contains(got, want) {
36 t.Errorf("environment lacks %s: %q", want, got)
37 }
38 }
39 for _, kv := range got {
40 switch kv {
41 case "GIT_DIR=/elsewhere", "GIT_CONFIG_VALUE_0=true", "GIT_CONFIG_PARAMETERS='core.usereplacerefs'='true'":
42 t.Errorf("environment kept %s", kv)
43 }
44 }
45}