From 35b0b56e9e5a37c41321b990cd526942048d4206 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Mon, 20 Mar 2023 16:59:47 -0700 Subject: [PATCH] tests: fix unit test failing if docker not running --- pkg/drivers/kic/oci/info.go | 2 +- pkg/minikube/registry/drvs/docker/docker_test.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/drivers/kic/oci/info.go b/pkg/drivers/kic/oci/info.go index 5f9166d67789..ce3f3fef0f22 100644 --- a/pkg/drivers/kic/oci/info.go +++ b/pkg/drivers/kic/oci/info.go @@ -44,7 +44,7 @@ var ( ) // CachedDaemonInfo will run and return a docker/podman info only once per minikube run time. to avoid performance -func CachedDaemonInfo(ociBin string) (SysInfo, error) { +var CachedDaemonInfo = func(ociBin string) (SysInfo, error) { if cachedSysInfo == nil { si, err := DaemonInfo(ociBin) cachedSysInfo = &si diff --git a/pkg/minikube/registry/drvs/docker/docker_test.go b/pkg/minikube/registry/drvs/docker/docker_test.go index d8123eaa8cf8..2dcf69b2f4f8 100644 --- a/pkg/minikube/registry/drvs/docker/docker_test.go +++ b/pkg/minikube/registry/drvs/docker/docker_test.go @@ -22,6 +22,7 @@ import ( "testing" "github.com/blang/semver/v4" + "k8s.io/minikube/pkg/drivers/kic/oci" "k8s.io/minikube/pkg/minikube/driver" "k8s.io/minikube/pkg/minikube/registry" ) @@ -185,6 +186,7 @@ func TestStatus(t *testing.T) { } for _, tt := range tests { dockerVersionOrState = func() (string, registry.State) { return tt.input, registry.State{} } + oci.CachedDaemonInfo = func(string) (oci.SysInfo, error) { return oci.SysInfo{}, nil } state := status() err := state.Error if (err == nil && tt.shouldReturnError) || (err != nil && !tt.shouldReturnError) {