<commit_before>// +build integration

/*
Copyright 2016 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package integration

import (
	"fmt"
	"net"
	"strings"
	"testing"
	"time"

	"github.com/docker/machine/libmachine/state"
	"k8s.io/minikube/pkg/minikube/constants"
	"k8s.io/minikube/test/integration/util"
)

func TestStartStop(t *testing.T) {
	p := profile(t) // profile name
	if isTestNoneDriver() {
		p = "minikube"
	} else {
		t.Parallel()
	}
	mk := NewMinikubeRunner(t, p)
	if !isTestNoneDriver() { // none driver doesn't need to be deleted
		defer mk.TearDown(t)
	}

	tests := []struct {
		name string
		args []string
	}{
		{"nocache_oldest", []string{
			"--cache-images=false",
			fmt.Sprintf("--kubernetes-version=%s", constants.OldestKubernetesVersion),
			// default is the network created by libvirt, if we change the name minikube won't boot
			// because the given network doesn't exist
			"--kvm-network=default",
			"--kvm-qemu-uri=qemu:///system",
		}},
		{"feature_gates_newest_cni", []string{
			"--feature-gates",
			"ServerSideApply=true",
			"--network-plugin=cni",
			"--extra-config=kubelet.network-plugin=cni",
			"--extra-config=kubeadm.pod-network-cidr=192.168.111.111/16",
			fmt.Sprintf("--kubernetes-version=%s", constants.NewestKubernetesVersion),
		}},
		{"containerd_and_non_default_apiserver_port", []string{
			"--container-runtime=containerd",
			"--docker-opt containerd=/var/run/containerd/containerd.sock",
			"--apiserver-port=8444",
		}},
		{"crio_ignore_preflights", []string{
			"--container-runtime=crio",
			"--extra-config",
			"kubeadm.ignore-preflight-errors=SystemVerification",
		}},
	}

	for _, tc := range tests {
		t.Run(tc.name, func(t *testing.T) {
			mk := NewMinikubeRunner(t, p)
			// TODO : check does this ever happen ?
			if !strings.Contains(tc.name, "docker") && isTestNoneDriver() {
				t.Skipf("skipping %s - incompatible with none driver", tc.name)
			}

			mk.RunCommand("config set WantReportErrorPrompt false", true)
			mk.RunCommand("delete", false)
			mk.CheckStatus(state.None.String())

			stdout, stderr, err := mk.Start(tc.args...)
			if err != nil {
				t.Fatalf("%s minikube start failed : %v\nstdout: %s\nstderr: %s", p, err, stdout, stderr)
			}

			mk.CheckStatus(state.Running.String())

			ip := mk.RunCommand("ip", true)
			ip = strings.TrimRight(ip, "\n")
			if net.ParseIP(ip) == nil {
				t.Fatalf("IP command returned an invalid address: %s", ip)
			}

			// check for the current-context before and after the stop
			// TODO: medya move this test to a non-parallel test so we can do more parallel
			// kr := util.NewKubectlRunner(t, p)
			// currentContext, err := kr.RunCommand([]string{"config", "current-context"}, false)
			// if err != nil {
			// 	t.Fatalf("Failed to fetch current-context")
			// }
			// if strings.TrimRight(string(currentContext), "\n") != p {
			// 	t.Fatalf("got current-context - %q, want  current-context %q", string(currentContext), p)
			// }

			checkStop := func() error {
				mk.RunCommand("stop", true)
				return mk.CheckStatusNoFail(state.Stopped.String())
			}

			if err := util.Retry(t, checkStop, 10*time.Second, 3); err != nil {
				t.Fatalf("timed out while checking stopped status: %v", err)
			}

			// TODO medyagh:  the commented code beollow was not correct ! I leave it for another PR
			// https://github.com/kubernetes/minikube/issues/4854

			// running this command results in error when the current-context is not set
			// if err := mk.Run("config current-context"); err != nil {
			// 	t.Logf("current-context is not set to minikube")
			// }

			stdout, stderr, err = mk.Start(tc.args...)
			if err != nil {
				t.Fatalf("%s minikube start failed : %v\nstdout: %s\nstderr: %s", t.Name(), err, stdout, stderr)
			}

			mk.CheckStatus(state.Running.String())

			mk.RunCommand("delete", true)
			mk.CheckStatus(state.None.String())
		})
	}
}<commit_msg>Create a new run group for start_stop_delete tests<commit_after>// +build integration

/*
Copyright 2016 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package integration

import (
	"fmt"
	"net"
	"strings"
	"testing"
	"time"

	"github.com/docker/machine/libmachine/state"
	"k8s.io/minikube/pkg/minikube/constants"
	"k8s.io/minikube/test/integration/util"
)

func TestStartStop(t *testing.T) {
	p := profile(t) // profile name
	if isTestNoneDriver() {
		p = "minikube"
	} else {
		t.Parallel()
	}
	mk := NewMinikubeRunner(t, p)
	if !isTestNoneDriver() { // none driver doesn't need to be deleted
		defer mk.TearDown(t)
	}

	tests := []struct {
		name string
		args []string
	}{
		{"nocache_oldest", []string{
			"--cache-images=false",
			fmt.Sprintf("--kubernetes-version=%s", constants.OldestKubernetesVersion),
			// default is the network created by libvirt, if we change the name minikube won't boot
			// because the given network doesn't exist
			"--kvm-network=default",
			"--kvm-qemu-uri=qemu:///system",
		}},
		{"feature_gates_newest_cni", []string{
			"--feature-gates",
			"ServerSideApply=true",
			"--network-plugin=cni",
			"--extra-config=kubelet.network-plugin=cni",
			"--extra-config=kubeadm.pod-network-cidr=192.168.111.111/16",
			fmt.Sprintf("--kubernetes-version=%s", constants.NewestKubernetesVersion),
		}},
		{"containerd_and_non_default_apiserver_port", []string{
			"--container-runtime=containerd",
			"--docker-opt containerd=/var/run/containerd/containerd.sock",
			"--apiserver-port=8444",
		}},
		{"crio_ignore_preflights", []string{
			"--container-runtime=crio",
			"--extra-config",
			"kubeadm.ignore-preflight-errors=SystemVerification",
		}},
	}
	t.Run("group", func(t *testing.T) {
		for _, tc := range tests {
			t.Run(tc.name, func(t *testing.T) {
				t.Parallel()
				mk := NewMinikubeRunner(t, p+tc.name)
				// TODO : redundant first clause, this test never happens for none
				if !strings.Contains(tc.name, "docker") && isTestNoneDriver() {
					t.Skipf("skipping %s - incompatible with none driver", tc.name)
				}

				mk.RunCommand("config set WantReportErrorPrompt false", true)
				mk.RunCommand("delete", false)
				mk.CheckStatus(state.None.String())

				stdout, stderr, err := mk.Start(tc.args...)
				if err != nil {
					t.Fatalf("%s minikube start failed : %v\nstdout: %s\nstderr: %s", p, err, stdout, stderr)
				}

				mk.CheckStatus(state.Running.String())

				ip := mk.RunCommand("ip", true)
				ip = strings.TrimRight(ip, "\n")
				if net.ParseIP(ip) == nil {
					t.Fatalf("IP command returned an invalid address: %s", ip)
				}

				// check for the current-context before and after the stop
				// TODO: medya move this test to a non-parallel test so we can do more parallel
				// kr := util.NewKubectlRunner(t, p)
				// currentContext, err := kr.RunCommand([]string{"config", "current-context"}, false)
				// if err != nil {
				// 	t.Fatalf("Failed to fetch current-context")
				// }
				// if strings.TrimRight(string(currentContext), "\n") != p {
				// 	t.Fatalf("got current-context - %q, want  current-context %q", string(currentContext), p)
				// }

				checkStop := func() error {
					mk.RunCommand("stop", true)
					return mk.CheckStatusNoFail(state.Stopped.String())
				}

				if err := util.Retry(t, checkStop, 10*time.Second, 3); err != nil {
					t.Fatalf("timed out while checking stopped status: %v", err)
				}

				// TODO medyagh:  the commented code beollow was not correct ! I leave it for another PR
				// https://github.com/kubernetes/minikube/issues/4854

				// running this command results in error when the current-context is not set
				// if err := mk.Run("config current-context"); err != nil {
				// 	t.Logf("current-context is not set to minikube")
				// }

				stdout, stderr, err = mk.Start(tc.args...)
				if err != nil {
					t.Fatalf("%s minikube start failed : %v\nstdout: %s\nstderr: %s", t.Name(), err, stdout, stderr)
				}

				mk.CheckStatus(state.Running.String())

				mk.RunCommand("delete", true)
				mk.CheckStatus(state.None.String())
			})
		}
	})
}
{'fraction_non_alphanumeric': 0.14937437714538812, 'fraction_numerical': 0.007751079614660613, 'mean_word_length': 3.401559454191033, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1549796', 'n_tokens_mistral': 3448, 'n_tokens_neox': 2973, 'n_words': 791}