forked from LaconicNetwork/kompose
add unit test for loadEnvVar
This commit is contained in:
parent
a881f5cca0
commit
7556f6f9fa
@ -16,7 +16,12 @@ limitations under the License.
|
|||||||
|
|
||||||
package compose
|
package compose
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/kubernetes-incubator/kompose/pkg/kobject"
|
||||||
|
)
|
||||||
|
|
||||||
// Test if service types are parsed properly on user input
|
// Test if service types are parsed properly on user input
|
||||||
// give a service type and expect correct input
|
// give a service type and expect correct input
|
||||||
@ -41,3 +46,69 @@ func TestHandleServiceType(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user