Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect tag in BuildConfig. #613

Merged
merged 1 commit into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/transformer/openshift/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func initBuildConfig(name string, service kobject.ServiceConfig, repo string, br
Output: buildapi.BuildOutput{
To: &kapi.ObjectReference{
Kind: "ImageStreamTag",
Name: name + ":latest",
Name: name + ":" + getImageTag(service.Image),
},
},
},
Expand Down
84 changes: 54 additions & 30 deletions pkg/transformer/openshift/openshift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,43 +281,67 @@ func TestGetAbsBuildContext(t *testing.T) {

// Test initializing buildconfig for a service
func TestInitBuildConfig(t *testing.T) {
dir := testutils.CreateLocalGitDirectory(t)
testutils.CreateSubdir(t, dir, "a/build")
defer os.RemoveAll(dir)

serviceName := "serviceA"
repo := "https://git.test.com/org/repo"
repo := "https://git.test.com/org/repo1"
branch := "somebranch"
buildArgs := []kapi.EnvVar{{Name: "name", Value: "value"}}
value := "value"
sc := kobject.ServiceConfig{
Build: filepath.Join(dir, "a/build"),
Dockerfile: "Dockerfile-alternate",
BuildArgs: map[string]*string{"name": &value},
}
bc, err := initBuildConfig(serviceName, sc, repo, branch)
if err != nil {
t.Error(errors.Wrap(err, "initBuildConfig failed"))
}
testDir := "a/build"

testCases := map[string]struct {
field string
value string
dir := testutils.CreateLocalGitDirectory(t)
testutils.CreateSubdir(t, dir, testDir)
defer os.RemoveAll(dir)

testCases := []struct {
Name string
ServiceConfig kobject.ServiceConfig
}{
"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 context dir": {bc.Spec.CommonSpec.Source.ContextDir, "a/build/"},
"Assert buildconfig output name": {bc.Spec.CommonSpec.Output.To.Name, serviceName + ":latest"},
"Assert buildconfig dockerfilepath": {bc.Spec.CommonSpec.Strategy.DockerStrategy.DockerfilePath, "Dockerfile-alternate"},
}
for name, test := range testCases {
t.Log("Test case: ", name)
if test.field != test.value {
t.Errorf("Expected: %#v, got: %#v", test.value, test.field)
{
Name: "Service config without image key",
ServiceConfig: kobject.ServiceConfig{
Build: filepath.Join(dir, testDir),
Dockerfile: "Dockerfile-alternate",
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",
},
},
}

for _, test := range testCases {

bc, err := initBuildConfig(serviceName, test.ServiceConfig, repo, branch)
if err != nil {
t.Error(errors.Wrap(err, "initBuildConfig failed"))
}

assertions := map[string]struct {
field string
value string
}{
"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 context dir": {bc.Spec.CommonSpec.Source.ContextDir, testDir + "/"},
// BuildConfig output image is named after service name. If image key is set than tag from that is used.
"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, assertionTest := range assertions {
if assertionTest.field != assertionTest.value {
t.Errorf("%s Expected: %#v, got: %#v", name, assertionTest.value, assertionTest.field)
}
}
if !reflect.DeepEqual(bc.Spec.CommonSpec.Strategy.DockerStrategy.Env, buildArgs) {
t.Errorf("Expected: %#v, got: %#v", 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)
}
}

Expand Down