-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubsystem_test.go
103 lines (85 loc) · 1.81 KB
/
subsystem_test.go
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
92
93
94
95
96
97
98
99
100
101
102
103
// SPDX-FileCopyrightText: 2025 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package haelu
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/suite"
)
type SubsystemTestSuite struct {
suite.Suite
}
func (suite *SubsystemTestSuite) testAsSubsystemsEmpty() {
s := AsSubsystems()
suite.Zero(s.Len())
suite.Panics(func() {
s.Get(0)
})
var called bool
for range s.All() {
called = true
}
suite.False(called)
}
func (suite *SubsystemTestSuite) testAsSubsystemsNotEmpty() {
original := []Subsystem{
{
Name: "first",
Metadata: Values(
"test", "value",
),
},
{
Name: "second",
NonCritical: true,
},
}
s := AsSubsystems(original...)
suite.Equal(2, s.Len())
suite.Equal(original[0], s.Get(0))
suite.Equal(original[1], s.Get(1))
suite.Panics(func() {
s.Get(2)
})
var called bool
i := 0
for sub := range s.All() {
suite.Equal(original[i], sub)
i++
called = true
}
suite.True(called)
var count int
for range s.All() {
count++
break
}
suite.Equal(1, count, "All needs to honor early return")
}
func (suite *SubsystemTestSuite) testAsSubsystemsMarshalJSON() {
original := []Subsystem{
{
Name: "first",
Metadata: Values(
"test", "value",
),
},
{
Name: "second",
NonCritical: true,
},
}
expected, err := json.Marshal(original)
suite.Require().NoError(err)
actual, err := AsSubsystems(original...).MarshalJSON()
suite.Require().NoError(err)
suite.JSONEq(string(expected), string(actual))
}
func (suite *SubsystemTestSuite) TestAsSubsystems() {
suite.Run("Empty", suite.testAsSubsystemsEmpty)
suite.Run("NotEmpty", suite.testAsSubsystemsNotEmpty)
suite.Run("MarshalJSON", suite.testAsSubsystemsMarshalJSON)
}
func TestSubsystem(t *testing.T) {
suite.Run(t, new(SubsystemTestSuite))
}