Skip to content

Commit

Permalink
feat(preset): add preset_test.go
Browse files Browse the repository at this point in the history
Signed-off-by: Vaughn Dice <vaughn.dice@fermyon.com>
  • Loading branch information
vdice committed Oct 25, 2024
1 parent 8688fe0 commit 0703753
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
97 changes: 97 additions & 0 deletions internal/preset/preset_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package preset_test

import (
"testing"

"github.com/spf13/afero"
"github.com/spinkube/runtime-class-manager/internal/preset"
tests "github.com/spinkube/runtime-class-manager/tests/node-installer"
"github.com/stretchr/testify/require"
)

func Test_WithSetup(t *testing.T) {
type args struct {
settings preset.Settings
hostFs afero.Fs
}
tests := []struct {
name string
args args
wantErr bool
wantContents string
}{
{
"rke2_err",
args{
preset.RKE2,
tests.FixtureFs("../../testdata/node-installer/distros/unsupported"),
},
true,
"",
},
{
"rke2_config_exists",
args{
preset.RKE2,
tests.FixtureFs("../../testdata/node-installer/containerd/rke2-existing-config-tmpl"),
},
false,
"version = 2\npreexisting-config = true",
},
{
"rke2_config_is_created",
args{
preset.RKE2,
tests.FixtureFs("../../testdata/node-installer/distros/rke2"),
},
false,
"version = 2",
},
{
"k3s",
args{
preset.K3s,
tests.FixtureFs("../../testdata/node-installer/distros/k3s"),
},
false,
"version = 2",
},
{
"k0s",
args{
preset.K0s,
tests.FixtureFs("../../testdata/node-installer/distros/k0s"),
},
false,
"",
},
{
"microk8s",
args{
preset.MicroK8s,
tests.FixtureFs("../../testdata/node-installer/distros/microk8s"),
},
false,
"",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.args.settings.Setup(
preset.Env{
ConfigPath: tt.args.settings.ConfigPath,
HostFs: tt.args.hostFs,
},
)

if tt.wantErr {
require.Error(t, err)
} else {
require.NoError(t, err)
bytes, err := afero.ReadFile(tt.args.hostFs, tt.args.settings.ConfigPath)
require.NoError(t, err)
require.Equal(t, tt.wantContents, string(bytes))
}
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = 2
preexisting-config = true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = 2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = 2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = 2

0 comments on commit 0703753

Please sign in to comment.