Skip to content

Commit 7d1fdab

Browse files
committed
Add unit test for container runtime version
This only tests the happy path of the current iso versions.
1 parent 112a66c commit 7d1fdab

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

pkg/minikube/cruntime/cruntime_test.go

+53
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ func (f *FakeRunner) CombinedOutput(cmd string) (string, error) {
134134
return f.docker(args, root)
135135
case "crictl":
136136
return f.crictl(args, root)
137+
case "crio":
138+
return f.crio(args, root)
139+
case "containerd":
140+
return f.containerd(args, root)
137141
default:
138142
return "", nil
139143
}
@@ -181,7 +185,29 @@ func (f *FakeRunner) docker(args []string, root bool) (string, error) {
181185
delete(f.containers, id)
182186

183187
}
188+
case "version":
189+
if args[1] == "--format" && args[2] == "'{{.Server.Version}}'" {
190+
return "18.06.2-ce", nil
191+
}
192+
193+
}
194+
return "", nil
195+
}
184196

197+
// crio is a fake implementation of crio
198+
func (f *FakeRunner) crio(args []string, root bool) (string, error) {
199+
switch cmd := args[0]; cmd {
200+
case "--version":
201+
return "crio version 1.13.0", nil
202+
}
203+
return "", nil
204+
}
205+
206+
// containerd is a fake implementation of containerd
207+
func (f *FakeRunner) containerd(args []string, root bool) (string, error) {
208+
switch cmd := args[0]; cmd {
209+
case "--version":
210+
return "containerd github.com/containerd/containerd v1.2.0 c4446665cb9c30056f4998ed953e6d4ff22c7c39", nil
185211
}
186212
return "", nil
187213
}
@@ -284,6 +310,33 @@ func (f *FakeRunner) systemctl(args []string, root bool) (string, error) {
284310
return out, nil
285311
}
286312

313+
func TestVersion(t *testing.T) {
314+
var tests = []struct {
315+
runtime string
316+
want string
317+
}{
318+
{"docker", "18.06.2-ce"},
319+
{"cri-o", "1.13.0"},
320+
{"containerd", "1.2.0"},
321+
}
322+
for _, tc := range tests {
323+
t.Run(tc.runtime, func(t *testing.T) {
324+
runner := NewFakeRunner(t)
325+
r, err := New(Config{Type: tc.runtime, Runner: runner})
326+
if err != nil {
327+
t.Fatalf("New(%s): %v", tc.runtime, err)
328+
}
329+
got, err := r.Version()
330+
if err != nil {
331+
t.Fatalf("Version(%s): %v", tc.runtime, err)
332+
}
333+
if got != tc.want {
334+
t.Errorf("Version(%s) = %q, want: %q", tc.runtime, got, tc.want)
335+
}
336+
})
337+
}
338+
}
339+
287340
// defaultServices reflects the default boot state for the minikube VM
288341
var defaultServices = map[string]serviceState{
289342
"docker": Running,

0 commit comments

Comments
 (0)