-
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathci_exit_codes_test.go
More file actions
91 lines (86 loc) · 2.27 KB
/
ci_exit_codes_test.go
File metadata and controls
91 lines (86 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package exec
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/cloudposse/atmos/pkg/schema"
)
func TestMapCIExitCode(t *testing.T) {
tests := []struct {
name string
ci schema.CIConfig
tf schema.TerraformCI
exitCode int
expected int
}{
{
name: "CI disabled preserves exit code",
ci: schema.CIConfig{Enabled: false},
tf: schema.TerraformCI{ExitCodes: map[int]bool{2: true}},
exitCode: 2,
expected: 2,
},
{
name: "CI enabled but no exit_codes map uses defaults (exit 2 → success)",
ci: schema.CIConfig{Enabled: true},
tf: schema.TerraformCI{},
exitCode: 2,
expected: 0,
},
{
name: "CI enabled but no exit_codes map uses defaults (exit 1 → failure)",
ci: schema.CIConfig{Enabled: true},
tf: schema.TerraformCI{},
exitCode: 1,
expected: 1,
},
{
name: "CI enabled with code mapped true returns 0",
ci: schema.CIConfig{Enabled: true},
tf: schema.TerraformCI{ExitCodes: map[int]bool{0: true, 2: true}},
exitCode: 2,
expected: 0,
},
{
name: "CI enabled with code mapped false preserves exit code",
ci: schema.CIConfig{Enabled: true},
tf: schema.TerraformCI{ExitCodes: map[int]bool{1: false}},
exitCode: 1,
expected: 1,
},
{
name: "CI enabled with unmapped code preserves exit code",
ci: schema.CIConfig{Enabled: true},
tf: schema.TerraformCI{ExitCodes: map[int]bool{0: true, 2: true}},
exitCode: 1,
expected: 1,
},
{
name: "CI enabled with exit 0 mapped true returns 0",
ci: schema.CIConfig{Enabled: true},
tf: schema.TerraformCI{ExitCodes: map[int]bool{0: true}},
exitCode: 0,
expected: 0,
},
{
name: "exit code 0 without mapping preserves 0",
ci: schema.CIConfig{Enabled: true},
tf: schema.TerraformCI{ExitCodes: map[int]bool{2: true}},
exitCode: 0,
expected: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
config := &schema.AtmosConfiguration{
CI: tt.ci,
Components: schema.Components{
Terraform: schema.Terraform{
CI: tt.tf,
},
},
}
result := mapCIExitCode(config, tt.exitCode)
assert.Equal(t, tt.expected, result)
})
}
}