Merge pull request #613 from kadel/fix-ImageStream-tag

Fix incorrect tag in BuildConfig.
This commit is contained in:
Charlie Drage 2017-05-23 15:13:34 -04:00 committed by GitHub
commit 93f5c0103c
2 changed files with 55 additions and 31 deletions

View File

@ -245,7 +245,7 @@ func initBuildConfig(name string, service kobject.ServiceConfig, repo string, br
Output: buildapi.BuildOutput{ Output: buildapi.BuildOutput{
To: &kapi.ObjectReference{ To: &kapi.ObjectReference{
Kind: "ImageStreamTag", Kind: "ImageStreamTag",
Name: name + ":latest", Name: name + ":" + getImageTag(service.Image),
}, },
}, },
}, },

View File

@ -281,44 +281,68 @@ func TestGetAbsBuildContext(t *testing.T) {
// Test initializing buildconfig for a service // Test initializing buildconfig for a service
func TestInitBuildConfig(t *testing.T) { func TestInitBuildConfig(t *testing.T) {
dir := testutils.CreateLocalGitDirectory(t)
testutils.CreateSubdir(t, dir, "a/build")
defer os.RemoveAll(dir)
serviceName := "serviceA" serviceName := "serviceA"
repo := "https://git.test.com/org/repo" repo := "https://git.test.com/org/repo1"
branch := "somebranch" branch := "somebranch"
buildArgs := []kapi.EnvVar{{Name: "name", Value: "value"}} buildArgs := []kapi.EnvVar{{Name: "name", Value: "value"}}
value := "value" value := "value"
sc := kobject.ServiceConfig{ testDir := "a/build"
Build: filepath.Join(dir, "a/build"),
dir := testutils.CreateLocalGitDirectory(t)
testutils.CreateSubdir(t, dir, testDir)
defer os.RemoveAll(dir)
testCases := []struct {
Name string
ServiceConfig kobject.ServiceConfig
}{
{
Name: "Service config without image key",
ServiceConfig: kobject.ServiceConfig{
Build: filepath.Join(dir, testDir),
Dockerfile: "Dockerfile-alternate", Dockerfile: "Dockerfile-alternate",
BuildArgs: map[string]*string{"name": &value}, BuildArgs: map[string]*string{"name": &value},
},
},
{
Name: "Service config with image key",
ServiceConfig: kobject.ServiceConfig{
Build: filepath.Join(dir, testDir),
Dockerfile: "Dockerfile-alternate",
BuildArgs: map[string]*string{"name": &value},
Image: "foo:bar",
},
},
} }
bc, err := initBuildConfig(serviceName, sc, repo, branch)
for _, test := range testCases {
bc, err := initBuildConfig(serviceName, test.ServiceConfig, repo, branch)
if err != nil { if err != nil {
t.Error(errors.Wrap(err, "initBuildConfig failed")) t.Error(errors.Wrap(err, "initBuildConfig failed"))
} }
testCases := map[string]struct { assertions := map[string]struct {
field string field string
value string value string
}{ }{
"Assert buildconfig source git URI": {bc.Spec.CommonSpec.Source.Git.URI, repo}, "Assert buildconfig source git URI": {bc.Spec.CommonSpec.Source.Git.URI, repo},
"Assert buildconfig source git Ref": {bc.Spec.CommonSpec.Source.Git.Ref, branch}, "Assert buildconfig source git Ref": {bc.Spec.CommonSpec.Source.Git.Ref, branch},
"Assert buildconfig source context dir": {bc.Spec.CommonSpec.Source.ContextDir, "a/build/"}, "Assert buildconfig source context dir": {bc.Spec.CommonSpec.Source.ContextDir, testDir + "/"},
"Assert buildconfig output name": {bc.Spec.CommonSpec.Output.To.Name, serviceName + ":latest"}, // BuildConfig output image is named after service name. If image key is set than tag from that is used.
"Assert buildconfig dockerfilepath": {bc.Spec.CommonSpec.Strategy.DockerStrategy.DockerfilePath, "Dockerfile-alternate"}, "Assert buildconfig output name": {bc.Spec.CommonSpec.Output.To.Name, serviceName + ":" + getImageTag(test.ServiceConfig.Image)},
"Assert buildconfig dockerfilepath": {bc.Spec.CommonSpec.Strategy.DockerStrategy.DockerfilePath, test.ServiceConfig.Dockerfile},
} }
for name, test := range testCases {
t.Log("Test case: ", name) for name, assertionTest := range assertions {
if test.field != test.value { if assertionTest.field != assertionTest.value {
t.Errorf("Expected: %#v, got: %#v", test.value, test.field) t.Errorf("%s Expected: %#v, got: %#v", name, assertionTest.value, assertionTest.field)
} }
} }
if !reflect.DeepEqual(bc.Spec.CommonSpec.Strategy.DockerStrategy.Env, buildArgs) { if !reflect.DeepEqual(bc.Spec.CommonSpec.Strategy.DockerStrategy.Env, buildArgs) {
t.Errorf("Expected: %#v, got: %#v", bc.Spec.CommonSpec.Strategy.DockerStrategy.Env, buildArgs) t.Errorf("Expected: %#v, got: %#v", bc.Spec.CommonSpec.Strategy.DockerStrategy.Env, buildArgs)
} }
}
} }
// TestServiceWithoutPort this tests if Headless Service is created for services without Port. // TestServiceWithoutPort this tests if Headless Service is created for services without Port.