Fix unit tests
parent
b3d4750c05
commit
950110280d
|
@ -17,15 +17,13 @@ limitations under the License.
|
|||
package config
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"k8s.io/minikube/pkg/minikube/tests"
|
||||
|
||||
"k8s.io/minikube/pkg/minikube/out"
|
||||
"k8s.io/minikube/pkg/minikube/tests"
|
||||
)
|
||||
|
||||
func TestListDefaults(t *testing.T) {
|
||||
func TestGetDefaults(t *testing.T) {
|
||||
tcs := []struct {
|
||||
property string
|
||||
expectedContents string
|
||||
|
@ -33,7 +31,7 @@ func TestListDefaults(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
property: "driver",
|
||||
expectedContents: "* docker\n*",
|
||||
expectedContents: "docker",
|
||||
}, {
|
||||
property: "invalid",
|
||||
shouldErr: true,
|
||||
|
@ -41,18 +39,52 @@ func TestListDefaults(t *testing.T) {
|
|||
}
|
||||
for _, tc := range tcs {
|
||||
t.Run(tc.property, func(t *testing.T) {
|
||||
f := tests.NewFakeFile()
|
||||
out.SetOutFile(f)
|
||||
err := listDefaults(tc.property)
|
||||
defaults, err := getDefaults(tc.property)
|
||||
if err != nil && !tc.shouldErr {
|
||||
t.Fatalf("test shouldn't have failed, error listing defaults: %v", err)
|
||||
}
|
||||
if err == nil && tc.shouldErr {
|
||||
t.Fatal("test should have failed but did not")
|
||||
}
|
||||
actual := f.String()
|
||||
if !strings.Contains(actual, tc.expectedContents) {
|
||||
t.Fatalf("actual contents don't contain expected contents. Actual: %v\nExpected: %v\n", actual, tc.expectedContents)
|
||||
if tc.shouldErr {
|
||||
return
|
||||
}
|
||||
for _, d := range defaults {
|
||||
if d == tc.expectedContents {
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Fatalf("defaults didn't contain expected default. Actual: %v\nExpected: %v\n", defaults, tc.expectedContents)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintDefaults(t *testing.T) {
|
||||
defaults := []string{"a", "b", "c"}
|
||||
tcs := []struct {
|
||||
description string
|
||||
format string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
description: "print to stdout",
|
||||
expected: "* a\n* b\n* c\n",
|
||||
}, {
|
||||
description: "print in json",
|
||||
format: "json",
|
||||
expected: "[\"a\",\"b\",\"c\"]\n",
|
||||
},
|
||||
}
|
||||
for _, tc := range tcs {
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
output = tc.format
|
||||
f := tests.NewFakeFile()
|
||||
out.SetOutFile(f)
|
||||
if err := printDefaults(defaults); err != nil {
|
||||
t.Fatalf("error printing defaults: %v", err)
|
||||
}
|
||||
if f.String() != tc.expected {
|
||||
t.Fatalf("Expected: %v\n Actual: %v\n", tc.expected, f.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
1
go.sum
1
go.sum
|
@ -405,6 +405,7 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de
|
|||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.5 h1:UImYN5qQ8tuGpGE16ZmjvcTtTw24zw1QAp/SlnNrZhI=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
||||
github.com/hashicorp/go-cleanhttp v0.5.0 h1:wvCrVc9TjDls6+YGAF2hAifE1E5U1+b4tH6KdvN3Gig=
|
||||
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
||||
|
|
Loading…
Reference in New Issue