Repository: kubernetes/minikube
Pull request #16109 (2023-03-21 00:05:07)

tests: Fix unit test failing if docker not running
The `TestStatus` test would call `docker system info --format "{{json .}}"` which if Docker wasn't running, would fail and result in the test failing. Mocked the call to `CachedDaemonInfo` to prevent the docker call from happening.


Patch:
diff --git a/pkg/drivers/kic/oci/info.go b/pkg/drivers/kic/oci/info.go
index 5f9166d67..ce3f3fef0 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/translations/de.json b/translations/de.json
index 1645ba39e..680c8558e 100644
--- a/translations/de.json
+++ b/translations/de.json
@@ -573,7 +573,6 @@
 	"Run a kubectl binary matching the cluster version": "Starten Sie ein kubectl Binärprogramm das zur Cluster Version passt",
 	"Run minikube from the C: drive.": "Start Minikube von Laufwerk C:",
 	"Run the Kubernetes client, download it if necessary. Remember -- after kubectl!\n\nThis will run the Kubernetes client (kubectl) with the same version as the cluster\n\nNormally it will download a binary matching the host operating system and architecture,\nbut optionally you can also run it directly on the control plane over the ssh connection.\nThis can be useful if you cannot run kubectl locally for some reason, like unsupported\nhost. Please be aware that when using --ssh all paths will apply to the remote machine.": "Starte den Kubernetes Client, lade ihn herunter, falls notwendig. Bedenke -- nach kubectl!\n\nDies wird den Kubernetes Client (kubectl) mit der selben Version des Clusters ausführen.\n\nNormalerweise wird es das Binärprogramm herunterladen, welches zum Host Betriebssystem und Architektur passt\naber optional kann man es auch direkt auf der Control Plane über die SSH-Verbindung ausführen.\nDas kann nützlich sein, wenn man kubectl aus Gründen nicht lokal laufen lassen kann, weil z.B. der Host unsupported ist.\nBitte beachten Sie, dass alle Pfade die man mit --ssh verwendet, auf die entfernte Maschine angewendet werden.",
-	"Run the following:\n$ sudo mkdir -p /etc/systemd/system/user@.service.d\n$ cat \u003c\u003cEOF | sudo tee /etc/systemd/system/user@.service.d/delegate.conf\n[Service]\nDelegate=cpu cpuset io memory pids\nEOF\n$ sudo systemctl daemon-reload": "",
 	"Run: 'Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Tools-All -All'": "Führe 'Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Tools-All -All' aus",
 	"Run: 'kubectl delete clusterrolebinding kubernetes-dashboard'": "Führe 'kubectl delete clusterrolebinding kubernetes-dashboard' aus",
 	"Run: 'minikube delete --all' to clean up all the abandoned networks.": "Führe 'minikube delete --all' aus um alle nicht mehr verwendeten Netzwerke zu bereinigen.",
diff --git a/translations/es.json b/translations/es.json
index 4f561ea7e..bac8f74fe 100644
--- a/translations/es.json
+++ b/translations/es.json
@@ -579,7 +579,6 @@
 	"Run a kubectl binary matching the cluster version": "",
 	"Run minikube from the C: drive.": "",
 	"Run the Kubernetes client, download it if necessary. Remember -- after kubectl!\n\nThis will run the Kubernetes client (kubectl) with the same version as the cluster\n\nNormally it will download a binary matching the host operating system and architecture,\nbut optionally you can also run it directly on the control plane over the ssh connection.\nThis can be useful if you cannot run kubectl locally for some reason, like unsupported\nhost. Please be aware that when using --ssh all paths will apply to the remote machine.": "",
-	"Run the following:\n$ sudo mkdir -p /etc/systemd/system/user@.service.d\n$ cat \u003c\u003cEOF | sudo tee /etc/systemd/system/user@.service.d/delegate.conf\n[Service]\nDelegate=cpu cpuset io memory pids\nEOF\n$ sudo systemctl daemon-reload": "",
 	"Run: 'Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Tools-All -All'": "",
 	"Run: 'kubectl delete clusterrolebinding kubernetes-dashboard'": "",
 	"Run: 'minikube delete --all' to clean up all the abandoned networks.": "",
diff --git a/translations/fr.json b/translations/fr.json
index 6ef240e3b..0d8b391a1 100644
--- a/translations/fr.json
+++ b/translations/fr.json
@@ -560,7 +560,6 @@
 	"Run a kubectl binary matching the cluster version": "Exécuter un binaire kubectl correspondant à la version du cluster",
 	"Run minikube from the C: drive.": "Exécutez minikube à partir du lecteur C:.",
 	"Run the Kubernetes client, download it if necessary. Remember -- after kubectl!\n\nThis will run the Kubernetes client (kubectl) with the same version as the cluster\n\nNormally it will download a binary matching the host operating system and architecture,\nbut optionally you can also run it directly on the control plane over the ssh connection.\nThis can be useful if you cannot run kubectl locally for some reason, like unsupported\nhost. Please be aware that when using --ssh all paths will apply to the remote machine.": "Exécutez le client Kubernetes, téléchargez-le si nécessaire. N'oubliez pas -- après kubectl !\n\nCela exécutera le client Kubernetes (kubectl) avec la même version que le cluster\n\nNormalement, il téléchargera un binaire correspondant au système d'exploitation et à l'architecture de l'hôte,\nmais vous pouvez également l'exécuter en option directement sur le plan de contrôle via la connexion ssh.\nCela peut être utile si vous ne pouvez pas exécuter kubectl localement pour une raison quelconque, comme un hôte non pris en charge. Veuillez noter que lors de l'utilisation de --ssh, tous les chemins s'appliqueront à la machine distante.",
-	"Run the following:\n$ sudo mkdir -p /etc/systemd/system/user@.service.d\n$ cat \u003c\u003cEOF | sudo tee /etc/systemd/system/user@.service.d/delegate.conf\n[Service]\nDelegate=cpu cpuset io memory pids\nEOF\n$ sudo systemctl daemon-reload": "",
 	"Run: 'Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Tools-All -All'": "Exécutez : 'Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Tools-All -All'",
 	"Run: 'kubectl delete clusterrolebinding kubernetes-dashboard'": "Exécutez : 'kubectl delete clusterrolebinding kubernetes-dashboard'",
 	"Run: 'minikube delete --all' to clean up all the abandoned networks.": "Exécutez : 'minikube delete --all' pour nettoyer tous les réseaux abandonnés.",
diff --git a/translations/ja.json b/translations/ja.json
index e2e040df5..548f70b6b 100644
--- a/translations/ja.json
+++ b/translations/ja.json
@@ -542,7 +542,6 @@
 	"Run a kubectl binary matching the cluster version": "クラスターのバージョンに一致する kubectl バイナリーを実行します",
 	"Run minikube from the C: drive.": "C: ドライブから minikube を実行してください。",
 	"Run the Kubernetes client, download it if necessary. Remember -- after kubectl!\n\nThis will run the Kubernetes client (kubectl) with the same version as the cluster\n\nNormally it will download a binary matching the host operating system and architecture,\nbut optionally you can also run it directly on the control plane over the ssh connection.\nThis can be useful if you cannot run kubectl locally for some reason, like unsupported\nhost. Please be aware that when using --ssh all paths will apply to the remote machine.": "Kubernetes クライアントを実行します (必要であればクライアントをダウンロードします)。kubectl の後に -- を忘れないでください！\n\nこれは、クラスターと同じバージョンの Kubernetes クライアント (kubectl) を実行します\n\n通常、ホスト OS とアーキテクチャに一致するバイナリーをダウンロードしますが、\nそのほかに SSH 接続経由でコントロールプレーン上で kubectl を直接実行することもできます。\nこれは、未サポートホストなど、いくつかの理由によりローカルで kubectl を実行できない場合に便利です。\n--ssh を使用する場合、全パスがリモートマシンに適用されることに注意してください。",
-	"Run the following:\n$ sudo mkdir -p /etc/systemd/system/user@.service.d\n$ cat \u003c\u003cEOF | sudo tee /etc/systemd/system/user@.service.d/delegate.conf\n[Service]\nDelegate=cpu cpuset io memory pids\nEOF\n$ sudo systemctl daemon-reload": "",
 	"Run: 'Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Tools-All -All'": "'Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Tools-All -All' を実行してください",
 	"Run: 'kubectl delete clusterrolebinding kubernetes-dashboard'": "'kubectl delete clusterrolebinding kubernetes-dashboard' を実行してください",
 	"Run: 'minikube delete --all' to clean up all the abandoned networks.": "破棄された全ネットワークを一掃するため、'minikube delete --all' を実行してください。",
diff --git a/translations/ko.json b/translations/ko.json
index 0a3137e99..8da4b6f8e 100644
--- a/translations/ko.json
+++ b/translations/ko.json
@@ -588,7 +588,6 @@
 	"Run kubectl": "kubectl 을 실행합니다",
 	"Run minikube from the C: drive.": "",
 	"Run the Kubernetes client, download it if necessary. Remember -- after kubectl!\n\nThis will run the Kubernetes client (kubectl) with the same version as the cluster\n\nNormally it will download a binary matching the host operating system and architecture,\nbut optionally you can also run it directly on the control plane over the ssh connection.\nThis can be useful if you cannot run kubectl locally for some reason, like unsupported\nhost. Please be aware that when using --ssh all paths will apply to the remote machine.": "",
-	"Run the following:\n$ sudo mkdir -p /etc/systemd/system/user@.service.d\n$ cat \u003c\u003cEOF | sudo tee /etc/systemd/system/user@.service.d/delegate.conf\n[Service]\nDelegate=cpu cpuset io memory pids\nEOF\n$ sudo systemctl daemon-reload": "",
 	"Run the minikube command as an Administrator": "minikube 명령어를 관리자 권한으로 실행합니다",
 	"Run: 'Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Tools-All -All'": "",
 	"Run: 'kubectl delete clusterrolebinding kubernetes-dashboard'": "",
diff --git a/translations/pl.json b/translations/pl.json
index 53701ab75..748221711 100644
--- a/translations/pl.json
+++ b/translations/pl.json
@@ -591,7 +591,6 @@
 	"Run kubectl": "Uruchamia kubectl",
 	"Run minikube from the C: drive.": "",
 	"Run the Kubernetes client, download it if necessary. Remember -- after kubectl!\n\nThis will run the Kubernetes client (kubectl) with the same version as the cluster\n\nNormally it will download a binary matching the host operating system and architecture,\nbut optionally you can also run it directly on the control plane over the ssh connection.\nThis can be useful if you cannot run kubectl locally for some reason, like unsupported\nhost. Please be aware that when using --ssh all paths will apply to the remote machine.": "",
-	"Run the following:\n$ sudo mkdir -p /etc/systemd/system/user@.service.d\n$ cat \u003c\u003cEOF | sudo tee /etc/systemd/system/user@.service.d/delegate.conf\n[Service]\nDelegate=cpu cpuset io memory pids\nEOF\n$ sudo systemctl daemon-reload": "",
 	"Run: 'Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Tools-All -All'": "",
 	"Run: 'kubectl delete clusterrolebinding kubernetes-dashboard'": "",
 	"Run: 'minikube delete --all' to clean up all the abandoned networks.": "",
diff --git a/translations/ru.json b/translations/ru.json
index 514e69433..9f7e3585b 100644
--- a/translations/ru.json
+++ b/translations/ru.json
@@ -537,7 +537,6 @@
 	"Run a kubectl binary matching the cluster version": "",
 	"Run minikube from the C: drive.": "",
 	"Run the Kubernetes client, download it if necessary. Remember -- after kubectl!\n\nThis will run the Kubernetes client (kubectl) with the same version as the cluster\n\nNormally it will download a binary matching the host operating system and architecture,\nbut optionally you can also run it directly on the control plane over the ssh connection.\nThis can be useful if you cannot run kubectl locally for some reason, like unsupported\nhost. Please be aware that when using --ssh all paths will apply to the remote machine.": "",
-	"Run the following:\n$ sudo mkdir -p /etc/systemd/system/user@.service.d\n$ cat \u003c\u003cEOF | sudo tee /etc/systemd/system/user@.service.d/delegate.conf\n[Service]\nDelegate=cpu cpuset io memory pids\nEOF\n$ sudo systemctl daemon-reload": "",
 	"Run: 'Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Tools-All -All'": "",
 	"Run: 'kubectl delete clusterrolebinding kubernetes-dashboard'": "",
 	"Run: 'minikube delete --all' to clean up all the abandoned networks.": "",
diff --git a/translations/strings.txt b/translations/strings.txt
index 60b6beb3c..7405b1c2b 100644
--- a/translations/strings.txt
+++ b/translations/strings.txt
@@ -537,7 +537,6 @@
 	"Run a kubectl binary matching the cluster version": "",
 	"Run minikube from the C: drive.": "",
 	"Run the Kubernetes client, download it if necessary. Remember -- after kubectl!\n\nThis will run the Kubernetes client (kubectl) with the same version as the cluster\n\nNormally it will download a binary matching the host operating system and architecture,\nbut optionally you can also run it directly on the control plane over the ssh connection.\nThis can be useful if you cannot run kubectl locally for some reason, like unsupported\nhost. Please be aware that when using --ssh all paths will apply to the remote machine.": "",
-	"Run the following:\n$ sudo mkdir -p /etc/systemd/system/user@.service.d\n$ cat \u003c\u003cEOF | sudo tee /etc/systemd/system/user@.service.d/delegate.conf\n[Service]\nDelegate=cpu cpuset io memory pids\nEOF\n$ sudo systemctl daemon-reload": "",
 	"Run: 'Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Tools-All -All'": "",
 	"Run: 'kubectl delete clusterrolebinding kubernetes-dashboard'": "",
 	"Run: 'minikube delete --all' to clean up all the abandoned networks.": "",
diff --git a/translations/zh-CN.json b/translations/zh-CN.json
index 68c3ee4b2..6f1ad7f8c 100644
--- a/translations/zh-CN.json
+++ b/translations/zh-CN.json
@@ -670,7 +670,6 @@
 	"Run kubectl": "运行 kubectl",
 	"Run minikube from the C: drive.": "",
 	"Run the Kubernetes client, download it if necessary. Remember -- after kubectl!\n\nThis will run the Kubernetes client (kubectl) with the same version as the cluster\n\nNormally it will download a binary matching the host operating system and architecture,\nbut optionally you can also run it directly on the control plane over the ssh connection.\nThis can be useful if you cannot run kubectl locally for some reason, like unsupported\nhost. Please be aware that when using --ssh all paths will apply to the remote machine.": "",
-	"Run the following:\n$ sudo mkdir -p /etc/systemd/system/user@.service.d\n$ cat \u003c\u003cEOF | sudo tee /etc/systemd/system/user@.service.d/delegate.conf\n[Service]\nDelegate=cpu cpuset io memory pids\nEOF\n$ sudo systemctl daemon-reload": "",
 	"Run: 'Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Tools-All -All'": "",
 	"Run: 'chmod 600 $HOME/.kube/config'": "执行 'chmod 600 $HOME/.kube/config'",
 	"Run: 'kubectl delete clusterrolebinding kubernetes-dashboard'": "",


Test patch:
diff --git a/pkg/minikube/registry/drvs/docker/docker_test.go b/pkg/minikube/registry/drvs/docker/docker_test.go
index d8123eaa8..2dcf69b2f 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) {