| 7 | ) |
| 8 | |
| 9 | func TestNewStack(t *testing.T) { |
| 10 | // Initialize a new Stack from the existing env |
| 11 | originalEnv := map[string]string{ |
| 12 | "PATH": "/init-path", |
| 13 | } |
| 14 | env := make(map[string]string) |
| 15 | stack := Stack(env, originalEnv) |
| 16 | if len(stack.keys) == 0 { |
| 17 | t.Errorf("Stack has no keys but should have %s", InitPathEnv) |
| 18 | } |
| 19 | if len(stack.keys) != 1 { |
| 20 | t.Errorf("Stack has should have exactly one key (%s) but has %d keys. Keys are: %s", |
| 21 | InitPathEnv, len(stack.keys), strings.Join(stack.keys, ", ")) |
| 22 | } |
| 23 | |
| 24 | // Each testStep below is applied in order, and the resulting env |
| 25 | // is used implicitly as input into the subsequent test step. |
| 26 | // |
| 27 | // These test steps are NOT independent! These are not "test cases" that |
| 28 | // would usually be independent. |
| 29 | testSteps := []struct { |
| 30 | projectHash string |
| 31 | devboxEnvPath string |
| 32 | preservePathStack bool |
| 33 | expectedKeysLength int |
| 34 | expectedEnv map[string]string |
| 35 | }{ |
| 36 | { |
| 37 | projectHash: "fooProjectHash", |
| 38 | devboxEnvPath: "/foo1:/foo2", |
| 39 | preservePathStack: false, |
| 40 | expectedKeysLength: 2, |
| 41 | expectedEnv: map[string]string{ |
| 42 | "PATH": "/foo1:/foo2:/init-path", |
| 43 | InitPathEnv: "/init-path", |
| 44 | Key("fooProjectHash"): "/foo1:/foo2", |
| 45 | }, |
| 46 | }, |
| 47 | { |
| 48 | projectHash: "barProjectHash", |
| 49 | devboxEnvPath: "/bar1:/bar2", |
| 50 | preservePathStack: false, |
| 51 | expectedKeysLength: 3, |
| 52 | expectedEnv: map[string]string{ |
| 53 | "PATH": "/bar1:/bar2:/foo1:/foo2:/init-path", |
| 54 | InitPathEnv: "/init-path", |
| 55 | Key("fooProjectHash"): "/foo1:/foo2", |
| 56 | Key("barProjectHash"): "/bar1:/bar2", |
| 57 | }, |
| 58 | }, |
| 59 | { |
| 60 | projectHash: "fooProjectHash", |
| 61 | devboxEnvPath: "/foo3:/foo2", |
| 62 | preservePathStack: false, |
| 63 | expectedKeysLength: 3, |
| 64 | expectedEnv: map[string]string{ |
| 65 | "PATH": "/foo3:/foo2:/bar1:/bar2:/init-path", |
| 66 | InitPathEnv: "/init-path", |