Skip to content

Commit 2c6b186

Browse files
authored
feat: add test for HostPreflight spec read (#1227)
1 parent 944da45 commit 2c6b186

File tree

1 file changed

+52
-11
lines changed

1 file changed

+52
-11
lines changed

pkg/preflight/read_specs_test.go

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,51 @@ func TestPreflightSpecsRead(t *testing.T) {
103103
},
104104
}
105105

106-
/*
107-
expectHostPreflightSpec := troubleshootv1beta2.HostPreflight{
108-
TypeMeta: metav1.TypeMeta{
109-
Kind: "HostPreflight",
110-
APIVersion: "troubleshoot.sh/troubleshootv1beta2",
106+
// A HostPreflight spec
107+
hostpreflightFile := filepath.Join(testutils.FileDir(), "../../examples/preflight/host/block-devices.yaml")
108+
//
109+
expectHostPreflightSpec := troubleshootv1beta2.HostPreflight{
110+
TypeMeta: metav1.TypeMeta{
111+
Kind: "HostPreflight",
112+
APIVersion: "troubleshoot.sh/v1beta2",
113+
},
114+
ObjectMeta: metav1.ObjectMeta{
115+
Name: "block",
116+
},
117+
Spec: troubleshootv1beta2.HostPreflightSpec{
118+
Collectors: []*troubleshootv1beta2.HostCollect{
119+
{
120+
BlockDevices: &troubleshootv1beta2.HostBlockDevices{},
111121
},
112-
Spec: troubleshootv1beta2.HostPreflightSpec{
113-
Collectors: []*troubleshootv1beta2.HostCollect(nil),
114-
RemoteCollectors: []*troubleshootv1beta2.RemoteCollect(nil),
115-
Analyzers: []*troubleshootv1beta2.HostAnalyze(nil),
122+
},
123+
RemoteCollectors: []*troubleshootv1beta2.RemoteCollect(nil),
124+
Analyzers: []*troubleshootv1beta2.HostAnalyze{
125+
{
126+
BlockDevices: &troubleshootv1beta2.BlockDevicesAnalyze{
127+
Outcomes: []*troubleshootv1beta2.Outcome{
128+
{
129+
Pass: &troubleshootv1beta2.SingleOutcome{
130+
When: ".* == 1",
131+
Message: "One available block device",
132+
},
133+
},
134+
{
135+
Pass: &troubleshootv1beta2.SingleOutcome{
136+
When: ".* > 1",
137+
Message: "Multiple available block devices",
138+
},
139+
},
140+
{
141+
Fail: &troubleshootv1beta2.SingleOutcome{
142+
Message: "No available block devices",
143+
},
144+
},
145+
},
146+
},
116147
},
117-
}
118-
*/
148+
},
149+
},
150+
}
119151

120152
// A more complexed preflight spec, which resides in a secret
121153
preflightSecretFile := filepath.Join(testutils.FileDir(), "../../testdata/preflightspec/troubleshoot_v1beta2_preflight_secret_gotest.yaml")
@@ -193,6 +225,15 @@ func TestPreflightSpecsRead(t *testing.T) {
193225
wantHostPreflightSpec: nil,
194226
wantUploadResultSpecs: nil,
195227
},
228+
PreflightSpecsReadTest{
229+
name: "file-hostpreflight",
230+
args: []string{hostpreflightFile},
231+
customStdin: false,
232+
wantErr: false,
233+
wantPreflightSpec: nil,
234+
wantHostPreflightSpec: &expectHostPreflightSpec,
235+
wantUploadResultSpecs: nil,
236+
},
196237
PreflightSpecsReadTest{
197238
name: "file-secret",
198239
args: []string{preflightSecretFile},

0 commit comments

Comments
 (0)