@@ -4,27 +4,20 @@ import (
44 "testing"
55
66 troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
7- "github.com/replicatedhq/troubleshoot/pkg/collect"
87 "github.com/stretchr/testify/assert"
98)
109
1110func TestAnalyzeKernelConfigs (t * testing.T ) {
12- kConfigs := collect.KConfigs {
13- "CONFIG_CGROUP_FREEZER" : "y" ,
14- "CONFIG_NETFILTER_XTABLES" : "m" ,
15- }
1611
1712 tests := []struct {
1813 name string
19- kConfigs collect.KConfigs
2014 selectedConfigs []string
2115 outcomes []* troubleshootv1beta2.Outcome
2216 results []* AnalyzeResult
2317 expectErr bool
2418 }{
2519 {
2620 name : "all pass" ,
27- kConfigs : kConfigs ,
2821 selectedConfigs : []string {"CONFIG_CGROUP_FREEZER=y" , "CONFIG_NETFILTER_XTABLES=m" },
2922 outcomes : []* troubleshootv1beta2.Outcome {
3023 {
@@ -44,7 +37,6 @@ func TestAnalyzeKernelConfigs(t *testing.T) {
4437 },
4538 {
4639 name : "has fail" ,
47- kConfigs : kConfigs ,
4840 selectedConfigs : []string {"CONFIG_UTS_NS=y" },
4941 outcomes : []* troubleshootv1beta2.Outcome {
5042 {
@@ -64,7 +56,6 @@ func TestAnalyzeKernelConfigs(t *testing.T) {
6456 },
6557 {
6658 name : "kernel config disabled" ,
67- kConfigs : kConfigs ,
6859 selectedConfigs : []string {"CONFIG_CGROUP_FREEZER=n" },
6960 outcomes : []* troubleshootv1beta2.Outcome {
7061 {
@@ -84,17 +75,35 @@ func TestAnalyzeKernelConfigs(t *testing.T) {
8475 },
8576 {
8677 name : "invalid kernel config" ,
87- kConfigs : kConfigs ,
8878 selectedConfigs : []string {"foobar=n" },
8979 expectErr : true ,
9080 },
81+ {
82+ name : "select multiple kernel config values" ,
83+ selectedConfigs : []string {"CONFIG_BRIDGE=my" },
84+ outcomes : []* troubleshootv1beta2.Outcome {
85+ {
86+ Pass : & troubleshootv1beta2.SingleOutcome {
87+ Message : "required kernel configs are available" ,
88+ },
89+ },
90+ },
91+ results : []* AnalyzeResult {
92+ {
93+ Title : "Kernel Configs" ,
94+ IsPass : true ,
95+ Message : "required kernel configs are available" ,
96+ },
97+ },
98+ expectErr : false ,
99+ },
91100 }
92101
93102 for _ , tt := range tests {
94103 t .Run (tt .name , func (t * testing.T ) {
95104
96- fn := func (_ string ) ([]byte , error ) {
97- return []byte (`{"CONFIG_CGROUP_FREEZER": "y", "CONFIG_NETFILTER_XTABLES": "m"}` ), nil
105+ mockKernelFile := func (_ string ) ([]byte , error ) {
106+ return []byte (`{"CONFIG_CGROUP_FREEZER": "y", "CONFIG_NETFILTER_XTABLES": "m", "CONFIG_BRIDGE": "y" }` ), nil
98107 }
99108
100109 analyzer := AnalyzeHostKernelConfigs {
@@ -107,7 +116,7 @@ func TestAnalyzeKernelConfigs(t *testing.T) {
107116 },
108117 }
109118
110- results , err := analyzer .Analyze (fn , nil )
119+ results , err := analyzer .Analyze (mockKernelFile , nil )
111120
112121 if tt .expectErr {
113122 assert .Error (t , err )
0 commit comments