Skip to content

Commit

Permalink
add unit test for loadEnvVar
Browse files Browse the repository at this point in the history
  • Loading branch information
ngtuna committed Dec 16, 2016
1 parent 5db7399 commit cc95f96
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion pkg/loader/compose/compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ limitations under the License.

package compose

import "testing"
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
Expand All @@ -41,3 +46,45 @@ 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",
}

tests := []struct {
envvars []string
results kobject.EnvVar
}{
{ev1, rs1},
{ev2, rs2},
{ev3, rs3},
{ev4, rs4},
}

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])
}
}
}

0 comments on commit cc95f96

Please sign in to comment.