|
1 | 1 | // |
2 | | -// Copyright 2023 The Chainloop Authors. |
| 2 | +// Copyright 2023-2026 The Chainloop Authors. |
3 | 3 | // |
4 | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | // you may not use this file except in compliance with the License. |
@@ -99,3 +99,42 @@ func TestExtractMaterials(t *testing.T) { |
99 | 99 | }) |
100 | 100 | } |
101 | 101 | } |
| 102 | + |
| 103 | +func TestExtractEnvVariables(t *testing.T) { |
| 104 | + testCases := []struct { |
| 105 | + name string |
| 106 | + input map[string]string |
| 107 | + want []*cpAPI.AttestationItem_EnvVariable |
| 108 | + }{ |
| 109 | + { |
| 110 | + name: "returns env vars sorted by name", |
| 111 | + input: map[string]string{ |
| 112 | + "Z_VAR": "z", |
| 113 | + "A_VAR": "a", |
| 114 | + "M_VAR": "m", |
| 115 | + }, |
| 116 | + want: []*cpAPI.AttestationItem_EnvVariable{ |
| 117 | + {Name: "A_VAR", Value: "a"}, |
| 118 | + {Name: "M_VAR", Value: "m"}, |
| 119 | + {Name: "Z_VAR", Value: "z"}, |
| 120 | + }, |
| 121 | + }, |
| 122 | + { |
| 123 | + name: "empty input", |
| 124 | + input: map[string]string{}, |
| 125 | + want: []*cpAPI.AttestationItem_EnvVariable{}, |
| 126 | + }, |
| 127 | + { |
| 128 | + name: "nil input", |
| 129 | + input: nil, |
| 130 | + want: []*cpAPI.AttestationItem_EnvVariable{}, |
| 131 | + }, |
| 132 | + } |
| 133 | + |
| 134 | + for _, tc := range testCases { |
| 135 | + t.Run(tc.name, func(t *testing.T) { |
| 136 | + got := extractEnvVariables(tc.input) |
| 137 | + assert.Equal(t, tc.want, got) |
| 138 | + }) |
| 139 | + } |
| 140 | +} |
0 commit comments