Skip to content

Commit

Permalink
update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
nvanthao committed Jul 5, 2024
1 parent 86f2828 commit 05c4725
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions pkg/analyze/host_kernel_configs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,20 @@ import (
"testing"

troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
"github.com/replicatedhq/troubleshoot/pkg/collect"
"github.com/stretchr/testify/assert"
)

func TestAnalyzeKernelConfigs(t *testing.T) {
kConfigs := collect.KConfigs{
"CONFIG_CGROUP_FREEZER": "y",
"CONFIG_NETFILTER_XTABLES": "m",
"CONFIG_BRIDGE": "y",
}

tests := []struct {
name string
kConfigs collect.KConfigs
selectedConfigs []string
outcomes []*troubleshootv1beta2.Outcome
results []*AnalyzeResult
expectErr bool
}{
{
name: "all pass",
kConfigs: kConfigs,
selectedConfigs: []string{"CONFIG_CGROUP_FREEZER=y", "CONFIG_NETFILTER_XTABLES=m"},
outcomes: []*troubleshootv1beta2.Outcome{
{
Expand All @@ -45,7 +37,6 @@ func TestAnalyzeKernelConfigs(t *testing.T) {
},
{
name: "has fail",
kConfigs: kConfigs,
selectedConfigs: []string{"CONFIG_UTS_NS=y"},
outcomes: []*troubleshootv1beta2.Outcome{
{
Expand All @@ -65,7 +56,6 @@ func TestAnalyzeKernelConfigs(t *testing.T) {
},
{
name: "kernel config disabled",
kConfigs: kConfigs,
selectedConfigs: []string{"CONFIG_CGROUP_FREEZER=n"},
outcomes: []*troubleshootv1beta2.Outcome{
{
Expand All @@ -85,13 +75,11 @@ func TestAnalyzeKernelConfigs(t *testing.T) {
},
{
name: "invalid kernel config",
kConfigs: kConfigs,
selectedConfigs: []string{"foobar=n"},
expectErr: true,
},
{
name: "select multiple kernel config values",
kConfigs: kConfigs,
selectedConfigs: []string{"CONFIG_BRIDGE=my"},
outcomes: []*troubleshootv1beta2.Outcome{
{
Expand All @@ -114,7 +102,7 @@ func TestAnalyzeKernelConfigs(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

fn := func(_ string) ([]byte, error) {
mockKernelFile := func(_ string) ([]byte, error) {
return []byte(`{"CONFIG_CGROUP_FREEZER": "y", "CONFIG_NETFILTER_XTABLES": "m", "CONFIG_BRIDGE": "y"}`), nil
}

Expand All @@ -128,7 +116,7 @@ func TestAnalyzeKernelConfigs(t *testing.T) {
},
}

results, err := analyzer.Analyze(fn, nil)
results, err := analyzer.Analyze(mockKernelFile, nil)

if tt.expectErr {
assert.Error(t, err)
Expand Down

0 comments on commit 05c4725

Please sign in to comment.