def testDriver(self): with mock.patch.object(run_subprocess, "GetOutputJson", return_value={}), \ mock.patch.object(run_subprocess, "StreamOutputJson") as mock_stream, \ mock.patch.object(run_subprocess, "Run") as mock_run, \ kubernetes.Minikube("cluster-name", vm_driver="my-driver"): self.assertIn("--vm-driver=my-driver", mock_stream.call_args[0][0]) self.assertEqual(mock_run.call_args, self.MINIKUBE_TEARDOWN_CALL)
def testAlreadyRunning(self): with mock.patch.object(run_subprocess, "GetOutputJson", return_value={"Host": "Running"}), \ mock.patch.object(run_subprocess, "Run") as mock_run, \ kubernetes.Minikube("cluster-name"): # Assert "minikube start" is not called. mock_run.assert_not_called() self.assertEqual(self.MINIKUBE_TEARDOWN_CALL, mock_run.call_args)
def testDebug(self): with mock.patch.object(run_subprocess, "GetOutputJson", return_value={}), \ mock.patch.object(run_subprocess, "StreamOutputJson") as mock_stream, \ mock.patch.object(run_subprocess, "Run"), \ kubernetes.Minikube("cluster-name", debug=True): self.assertIn("--alsologtostderr", mock_stream.call_args[0][0]) self.assertIn("-v8", mock_stream.call_args[0][0]) self.assertIs(mock_stream.call_args[1]["show_stderr"], True)
def Minikube(): if args.IsSpecified('minikube_profile'): cluster_name = args.minikube_profile else: cluster_name = kubernetes.DEFAULT_CLUSTER_NAME return kubernetes.Minikube(cluster_name, args.stop_cluster, args.minikube_vm_driver)
def testNotYetRunning(self): with mock.patch.object(run_subprocess, "GetOutputJson", return_value={}), \ mock.patch.object(run_subprocess, "StreamOutputJson") as mock_stream, \ mock.patch.object(run_subprocess, "Run") as mock_run, \ kubernetes.Minikube("cluster-name"): self.assertIn("cluster-name", mock_stream.call_args[0][0]) self.assertIn("start", mock_stream.call_args[0][0]) self.assertEqual(mock_run.call_args, self.MINIKUBE_TEARDOWN_CALL)
def testProgressBar(self): stream_output = [ { "type": "io.k8s.sigs.minikube.step", "data": { "currentstep": "1", "totalsteps": "3" } }, { "type": "io.k8s.sigs.minikube.step", "data": { "currentstep": "2", "totalsteps": "3" } }, { "type": "io.k8s.sigs.minikube.download.progress", "data": { "progress": "0.33333", "currentstep": "2", "totalsteps": "3" } }, { "type": "io.k8s.sigs.minikube.download.progress", "data": { "progress": "0.77777", "currentstep": "2", "totalsteps": "3" } }, { "type": "io.k8s.sigs.minikube.step", "data": { "currentstep": "3", "totalsteps": "3" } }, ] with mock.patch.object(run_subprocess, "GetOutputJson", return_value={}), \ mock.patch.object(run_subprocess, "StreamOutputJson", return_value=stream_output), \ mock.patch.object(run_subprocess, "Run") as mock_run, \ mock.patch.object(console_io, "ProgressBar") as mock_progress_bar, \ kubernetes.Minikube("cluster-name"): set_progress = (mock_progress_bar.return_value.__enter__. return_value.SetProgress) expected_calls = [ mock.call(FloatMatcher(float(1) / 3)), mock.call(FloatMatcher(float(2) / 3)), mock.call(FloatMatcher(float(2.33333) / 3)), mock.call(FloatMatcher(float(2.77777) / 3)), mock.call(FloatMatcher(float(3) / 3)) ] set_progress.assert_has_calls(expected_calls) self.assertEqual(mock_run.call_args, self.MINIKUBE_TEARDOWN_CALL)
def Minikube(): if args.IsSpecified('minikube_profile'): cluster_name = args.minikube_profile else: cluster_name = kubernetes.DEFAULT_CLUSTER_NAME return kubernetes.Minikube( cluster_name, args.stop_cluster, getattr(args, 'minikube_vm_driver', 'docker'), _IsDebug())
def testNotYetRunningError(self): get_json_side_effect = subprocess.CalledProcessError(1, "cmd") with mock.patch.object(run_subprocess, "GetOutputJson", side_effect=get_json_side_effect), \ mock.patch.object(run_subprocess, "StreamOutputJson") as mock_stream, \ mock.patch.object(run_subprocess, "Run") as mock_run, \ kubernetes.Minikube("cluster-name"): self.assertIn("cluster-name", mock_stream.call_args[0][0]) self.assertIn("start", mock_stream.call_args[0][0]) self.assertEqual(mock_stream.call_args[1]["event_timeout_sec"], 90) self.assertEqual(mock_run.call_args, self.MINIKUBE_TEARDOWN_CALL)
def testNotYetRunning(self): with mock.patch.object(subprocess, "Popen") as popen: with mock.patch.object(subprocess, "check_call") as check_call: status = six.ensure_binary(json.dumps({})) popen.return_value.communicate.return_value = (status, None) with kubernetes.Minikube("cluster-name"): self.assertIn("cluster-name", check_call.call_args[0][0]) self.assertIn("start", check_call.call_args[0][0]) self.assertIn("stop", check_call.call_args[0][0])
def testAlreadyRunning(self): with mock.patch.object(subprocess, "Popen") as popen: with mock.patch.object(subprocess, "check_call") as check_call: status = six.ensure_binary(json.dumps({"Host": "Running"})) popen.return_value.communicate.return_value = (status, None) with kubernetes.Minikube("cluster-name"): # Assert "minikube start" is not called. check_call.assert_not_called() self.assertIn("stop", check_call.call_args[0][0])
def testDockerDriver(self): with mock.patch.object(subprocess, "Popen") as popen: with mock.patch.object(subprocess, "check_call") as check_call: status = six.ensure_binary(json.dumps({})) popen.return_value.communicate.return_value = (status, None) with kubernetes.Minikube("cluster-name", vm_driver="docker"): check_call.assert_called_once_with( Matcher(lambda cmd: "--vm-driver=docker" in cmd), stdout=mock.ANY, stderr=mock.ANY) check_call.assert_called_once_with(Matcher( lambda cmd: "--container-runtime=docker" in cmd), stdout=mock.ANY, stderr=mock.ANY) self.assertIn("stop", check_call.call_args[0][0])