add more unit tests
parent
82f39d1387
commit
c48e8e5ec9
|
@ -23,6 +23,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/registry"
|
||||
)
|
||||
|
||||
|
@ -202,6 +203,60 @@ func TestSuggest(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestMachineName(t *testing.T) {
|
||||
testsCases := []struct {
|
||||
ClusterConfig config.ClusterConfig
|
||||
Want string
|
||||
}{
|
||||
{
|
||||
ClusterConfig: config.ClusterConfig{Name: "minikube",
|
||||
Nodes: []config.Node{
|
||||
config.Node{
|
||||
Name: "",
|
||||
IP: "172.17.0.3",
|
||||
Port: 8443,
|
||||
KubernetesVersion: "v1.19.2",
|
||||
ControlPlane: true,
|
||||
Worker: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
Want: "minikube",
|
||||
},
|
||||
|
||||
{
|
||||
ClusterConfig: config.ClusterConfig{Name: "p2",
|
||||
Nodes: []config.Node{
|
||||
config.Node{
|
||||
Name: "",
|
||||
IP: "172.17.0.3",
|
||||
Port: 8443,
|
||||
KubernetesVersion: "v1.19.2",
|
||||
ControlPlane: true,
|
||||
Worker: true,
|
||||
},
|
||||
config.Node{
|
||||
Name: "m2",
|
||||
IP: "172.17.0.4",
|
||||
Port: 0,
|
||||
KubernetesVersion: "v1.19.2",
|
||||
ControlPlane: false,
|
||||
Worker: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
Want: "p2-m2",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testsCases {
|
||||
got := MachineName(tc.ClusterConfig, tc.ClusterConfig.Nodes[len(tc.ClusterConfig.Nodes)-1])
|
||||
if got != tc.Want {
|
||||
t.Errorf("Expected MachineName to be %q but got %q", tc.Want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexFromMachineName(t *testing.T) {
|
||||
testCases := []struct {
|
||||
Name string
|
||||
|
@ -247,3 +302,60 @@ func TestIndexFromMachineName(t *testing.T) {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
// test against cluster config
|
||||
func TestIndexFromMachineName2(t *testing.T) {
|
||||
|
||||
testsCases := []struct {
|
||||
ClusterConfig config.ClusterConfig
|
||||
Want int
|
||||
}{
|
||||
{
|
||||
ClusterConfig: config.ClusterConfig{Name: "minikube",
|
||||
Nodes: []config.Node{
|
||||
config.Node{
|
||||
Name: "",
|
||||
IP: "172.17.0.3",
|
||||
Port: 8443,
|
||||
KubernetesVersion: "v1.19.2",
|
||||
ControlPlane: true,
|
||||
Worker: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
Want: 1,
|
||||
},
|
||||
|
||||
{
|
||||
ClusterConfig: config.ClusterConfig{Name: "p2",
|
||||
Nodes: []config.Node{
|
||||
config.Node{
|
||||
Name: "",
|
||||
IP: "172.17.0.3",
|
||||
Port: 8443,
|
||||
KubernetesVersion: "v1.19.2",
|
||||
ControlPlane: true,
|
||||
Worker: true,
|
||||
},
|
||||
config.Node{
|
||||
Name: "m2",
|
||||
IP: "172.17.0.4",
|
||||
Port: 0,
|
||||
KubernetesVersion: "v1.19.2",
|
||||
ControlPlane: false,
|
||||
Worker: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
Want: 2,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testsCases {
|
||||
got := IndexFromMachineName(MachineName(tc.ClusterConfig, tc.ClusterConfig.Nodes[len(tc.ClusterConfig.Nodes)-1]))
|
||||
if got != tc.Want {
|
||||
t.Errorf("expected IndexFromMachineName to be %d but got %d", tc.Want, got)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue