add tests

pull/5289/head
Marcin Niemira 2019-09-07 20:26:57 +10:00
parent 0b986bd044
commit e9517ec69b
No known key found for this signature in database
GPG Key ID: 5395D4A81A3FA475
1 changed files with 56 additions and 0 deletions

View File

@ -17,7 +17,11 @@ limitations under the License.
package cmd
import (
"os"
"testing"
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/constants"
)
func Test_extractVMDriverVersion(t *testing.T) {
@ -43,3 +47,55 @@ func Test_extractVMDriverVersion(t *testing.T) {
t.Errorf("Expected version: %s, got: %s", expectedVersion, v)
}
}
func TestGenerateCfgFromFlagsHTTPProxyHandling(t *testing.T) {
originalEnv := os.Getenv("HTTP_PROXY")
defer func() {
err := os.Setenv("HTTP_PROXY", originalEnv)
if err != nil {
t.Fatalf("Error reverting env HTTP_PROXY to it's original value. Got err (%s)", err)
}
}()
k8sVersion := constants.NewestKubernetesVersion
var tests = []struct {
description string
proxy string
proxyIgnored bool
}{
{
description: "no http_proxy",
},
{
description: "http_proxy=127.0.0.1:3128",
proxy: "127.0.0.1:3128",
proxyIgnored: true,
},
{
description: "http_proxy=localhost:3128",
proxy: "localhost:3128",
proxyIgnored: true,
},
{
description: "http_proxy=1.2.3.4:3128",
proxy: "1.2.3.4:3128",
},
}
for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
cmd := cobra.Command{}
if err := os.Setenv("HTTP_PROXY", test.proxy); err != nil {
t.Fatalf("Unexpected error setting HTTP_PROXY: %v", err)
}
config, err := generateCfgFromFlags(&cmd, k8sVersion)
if err != nil {
t.Fatalf("Got unexpected error %v during config generation", err)
}
// ignored proxy should not be in config
for _, v := range config.MachineConfig.DockerEnv {
if v == test.proxy && test.proxyIgnored {
t.Fatalf("Value %v not expected in dockerEnv but occured", v)
}
}
})
}
}