Skip to content

Commit c266e07

Browse files
test(controlplane): cover extractEnvVariables ordering and nil input (#2779)
Signed-off-by: Matías Insaurralde <matias@chainloop.dev>
1 parent b46ef29 commit c266e07

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

app/controlplane/internal/service/attestation_test.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2023-2026 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -99,3 +99,42 @@ func TestExtractMaterials(t *testing.T) {
9999
})
100100
}
101101
}
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

Comments
 (0)