forked from LaconicNetwork/kompose
115 lines
2.4 KiB
Go
115 lines
2.4 KiB
Go
/*
|
|
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 compose
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/kubernetes-incubator/kompose/pkg/kobject"
|
|
)
|
|
|
|
// Test if service types are parsed properly on user input
|
|
// give a service type and expect correct input
|
|
func TestHandleServiceType(t *testing.T) {
|
|
tests := []struct {
|
|
labelValue string
|
|
serviceType string
|
|
}{
|
|
{"NodePort", "NodePort"},
|
|
{"nodeport", "NodePort"},
|
|
{"LoadBalancer", "LoadBalancer"},
|
|
{"loadbalancer", "LoadBalancer"},
|
|
{"ClusterIP", "ClusterIP"},
|
|
{"clusterip", "ClusterIP"},
|
|
{"", "ClusterIP"},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
result := handleServiceType(tt.labelValue)
|
|
if result != tt.serviceType {
|
|
t.Errorf("Expected %q, got %q", tt.serviceType, result)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestLoadEnvVar(t *testing.T) {
|
|
ev1 := []string{"foo=bar"}
|
|
rs1 := kobject.EnvVar{
|
|
Name: "foo",
|
|
Value: "bar",
|
|
}
|
|
ev2 := []string{"foo:bar"}
|
|
rs2 := kobject.EnvVar{
|
|
Name: "foo",
|
|
Value: "bar",
|
|
}
|
|
ev3 := []string{"foo"}
|
|
rs3 := kobject.EnvVar{
|
|
Name: "foo",
|
|
Value: "",
|
|
}
|
|
ev4 := []string{"osfoo"}
|
|
rs4 := kobject.EnvVar{
|
|
Name: "osfoo",
|
|
Value: "osbar",
|
|
}
|
|
ev5 := []string{"foo:bar=foobar"}
|
|
rs5 := kobject.EnvVar{
|
|
Name: "foo",
|
|
Value: "bar=foobar",
|
|
}
|
|
ev6 := []string{"foo=foo:bar"}
|
|
rs6 := kobject.EnvVar{
|
|
Name: "foo",
|
|
Value: "foo:bar",
|
|
}
|
|
ev7 := []string{"foo:"}
|
|
rs7 := kobject.EnvVar{
|
|
Name: "foo",
|
|
Value: "",
|
|
}
|
|
ev8 := []string{"foo="}
|
|
rs8 := kobject.EnvVar{
|
|
Name: "foo",
|
|
Value: "",
|
|
}
|
|
|
|
tests := []struct {
|
|
envvars []string
|
|
results kobject.EnvVar
|
|
}{
|
|
{ev1, rs1},
|
|
{ev2, rs2},
|
|
{ev3, rs3},
|
|
{ev4, rs4},
|
|
{ev5, rs5},
|
|
{ev6, rs6},
|
|
{ev7, rs7},
|
|
{ev8, rs8},
|
|
}
|
|
|
|
os.Setenv("osfoo", "osbar")
|
|
|
|
for _, tt := range tests {
|
|
result := loadEnvVars(tt.envvars)
|
|
if result[0] != tt.results {
|
|
t.Errorf("Expected %q, got %q", tt.results, result[0])
|
|
}
|
|
}
|
|
}
|