Skip to content

Commit 6a35df1

Browse files
committed
feat(preset): add preset_test.go
Signed-off-by: Vaughn Dice <[email protected]>
1 parent 8688fe0 commit 6a35df1

File tree

5 files changed

+108
-0
lines changed
  • internal/preset
  • testdata/node-installer
    • containerd
      • rke2-existing-config-tmpl/var/lib/rancher/rke2/agent/etc/containerd
      • rke2-only-base-config-exists/var/lib/rancher/rke2/agent/etc/containerd
    • distros
      • k3s/var/lib/rancher/k3s/agent/etc/containerd
      • rke2/var/lib/rancher/rke2/agent/etc/containerd

5 files changed

+108
-0
lines changed

internal/preset/preset_test.go

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package preset
2+
3+
import (
4+
"testing"
5+
6+
"github.com/spf13/afero"
7+
tests "github.com/spinkube/runtime-class-manager/tests/node-installer"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func Test_WithSetup(t *testing.T) {
12+
type args struct {
13+
settings Settings
14+
hostFs afero.Fs
15+
}
16+
tests := []struct {
17+
name string
18+
args args
19+
wantErr bool
20+
wantFile string
21+
wantContents string
22+
}{
23+
{
24+
"rke2_err",
25+
args{
26+
RKE2,
27+
tests.FixtureFs("../../testdata/node-installer/distros/unsupported"),
28+
},
29+
true,
30+
"",
31+
"",
32+
},
33+
{
34+
"rke2_config_exists",
35+
args{
36+
RKE2,
37+
tests.FixtureFs("../../testdata/node-installer/containerd/rke2-existing-config-tmpl"),
38+
},
39+
false,
40+
"/var/lib/rancher/rke2/agent/etc/containerd/config.toml.tmpl",
41+
"version = 2\npreexisting-config = true",
42+
},
43+
{
44+
"rke2_config_is_created",
45+
args{
46+
RKE2,
47+
tests.FixtureFs("../../testdata/node-installer/distros/rke2"),
48+
},
49+
false,
50+
"/var/lib/rancher/rke2/agent/etc/containerd/config.toml.tmpl",
51+
"version = 2",
52+
},
53+
{
54+
"k3s",
55+
args{
56+
K3s,
57+
tests.FixtureFs("../../testdata/node-installer/distros/k3s"),
58+
},
59+
false,
60+
"/var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl",
61+
"version = 2",
62+
},
63+
{
64+
"k0s",
65+
args{
66+
K0s,
67+
tests.FixtureFs("../../testdata/node-installer/distros/k0s"),
68+
},
69+
false,
70+
"/etc/k0s/containerd.d/config.toml",
71+
"",
72+
},
73+
{
74+
"microk8s",
75+
args{
76+
MicroK8s,
77+
tests.FixtureFs("../../testdata/node-installer/distros/microk8s"),
78+
},
79+
false,
80+
"/var/snap/microk8s/current/args/containerd-template.toml",
81+
"",
82+
},
83+
}
84+
for _, tt := range tests {
85+
t.Run(tt.name, func(t *testing.T) {
86+
err := tt.args.settings.Setup(
87+
Env{
88+
ConfigPath: tt.args.settings.ConfigPath,
89+
HostFs: tt.args.hostFs,
90+
},
91+
)
92+
93+
if tt.wantErr {
94+
require.Error(t, err)
95+
} else {
96+
require.NoError(t, err)
97+
bytes, err := afero.ReadFile(tt.args.hostFs, tt.wantFile)
98+
require.NoError(t, err)
99+
require.Equal(t, tt.wantContents, string(bytes))
100+
}
101+
})
102+
}
103+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version = 2
2+
preexisting-config = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version = 2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version = 2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version = 2

0 commit comments

Comments
 (0)