Skip to content

Commit 0d10007

Browse files
committed
Modify tests for previous-image flag (#897)
Signed-off-by: Ujjwal Goyal <importujjwal@gmail.com>
1 parent c7937bf commit 0d10007

4 files changed

Lines changed: 25 additions & 67 deletions

File tree

acceptance/acceptance_test.go

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,45 +1764,6 @@ func testAcceptance(
17641764
})
17651765
})
17661766

1767-
// when("--previous-image", func() {
1768-
// var prevImage string
1769-
// it.Before(func() {
1770-
// prevImage = fmt.Sprintf("%s", repoName)
1771-
// })
1772-
1773-
// it("creates image and previous image on the registry", func() {
1774-
// buildArgs := []string{
1775-
// repoName,
1776-
// "-p", filepath.Join("testdata", "mock_app"),
1777-
// "--publish",
1778-
// "--previous-image",
1779-
// prevImage,
1780-
// }
1781-
// if imageManager.HostOS() != "windows" {
1782-
// buildArgs = append(buildArgs, "--network", "host")
1783-
// }
1784-
1785-
// output := pack.RunSuccessfully("build", buildArgs...)
1786-
// assertions.NewOutputAssertionManager(t, output).ReportsSuccessfulImageBuild(repoName)
1787-
1788-
// prevImageRef, err := name.ParseReference(prevImage, name.WeakValidation)
1789-
// assert.Nil(err)
1790-
1791-
// t.Log("checking that registry has contents")
1792-
// assertImage.CanBePulledFromRegistry(repoName)
1793-
// if imageManager.HostOS() == "windows" {
1794-
// // Cache images are automatically Linux container images, and therefore can't be pulled
1795-
// // and inspected correctly on WCOW systems
1796-
// //https://github.com/buildpacks/lifecycle/issues/529
1797-
// imageManager.PullImage(prevImageRef.Name(), registryConfig.RegistryAuth())
1798-
// } else {
1799-
// assertImage.CanBePulledFromRegistry(prevImageRef.Name())
1800-
// }
1801-
1802-
// defer imageManager.CleanupImages(prevImageRef.Name())
1803-
// })
1804-
// })
1805-
18061767
when("ctrl+c", func() {
18071768
it("stops the execution", func() {
18081769
var buf = new(bytes.Buffer)

internal/build/lifecycle_execution.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,17 @@ func (l *LifecycleExecution) Create(ctx context.Context, publish bool, dockerHos
188188
flags = append(flags, "-gid", strconv.Itoa(l.opts.GID))
189189
}
190190

191+
if l.opts.Image == nil {
192+
return errors.New("image can't be nil")
193+
}
194+
195+
// validate image name
196+
image, err := name.ParseReference(l.opts.Image.Name(), name.WeakValidation)
197+
if err != nil {
198+
return fmt.Errorf("invalid image name: %s", err)
199+
}
200+
191201
if l.opts.PreviousImage != "" {
192-
image, err := name.ParseReference(l.opts.Image.Name(), name.WeakValidation)
193-
if err != nil {
194-
return fmt.Errorf("invalid image name: %s", err)
195-
}
196202
prevImage, err := name.ParseReference(l.opts.PreviousImage, name.WeakValidation)
197203
if err != nil {
198204
return fmt.Errorf("invalid previous image name: %s", err)

internal/build/lifecycle_execution_test.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,20 @@ func testLifecycleExecution(t *testing.T, when spec.G, it spec.S) {
840840
})
841841
})
842842

843+
when("image is invalid", func() {
844+
it("errors", func() {
845+
var imageName name.Tag
846+
imageName, err := name.NewTag("/x/y/?!z", name.WeakValidation)
847+
h.AssertError(t, err, "repository can only contain the runes `abcdefghijklmnopqrstuvwxyz0123456789_-./`")
848+
lifecycle := newTestLifecycleExec(t, true, func(options *build.LifecycleOptions) {
849+
options.Image = imageName
850+
})
851+
fakePhaseFactory := fakes.NewFakePhaseFactory()
852+
err = lifecycle.Create(context.Background(), false, "", false, "test", "test", "test", fakeBuildCache, fakeLaunchCache, []string{}, []string{}, fakePhaseFactory)
853+
h.AssertError(t, err, "invalid image name")
854+
})
855+
})
856+
843857
when("-previous-image is used", func() {
844858
when("previous-image is invalid", func() {
845859
it("errors", func() {
@@ -852,25 +866,10 @@ func testLifecycleExecution(t *testing.T, when spec.G, it spec.S) {
852866
})
853867
fakePhaseFactory := fakes.NewFakePhaseFactory()
854868
err = lifecycle.Create(context.Background(), false, "", false, "test", "test", "test", fakeBuildCache, fakeLaunchCache, []string{}, []string{}, fakePhaseFactory)
855-
h.AssertError(t, err, fmt.Sprintf("%s", err))
869+
h.AssertError(t, err, "invalid previous image name")
856870
})
857871
})
858872

859-
// when("image is invalid", func() {
860-
// it("errors", func() {
861-
// var imageName name.Tag
862-
// imageName, err := name.NewTag("/x/y/z", name.WeakValidation)
863-
// h.AssertNil(t, err)
864-
// lifecycle := newTestLifecycleExec(t, true, func(options *build.LifecycleOptions) {
865-
// options.PreviousImage = "previous-image"
866-
// options.Image = imageName
867-
// })
868-
// fakePhaseFactory := fakes.NewFakePhaseFactory()
869-
// err = lifecycle.Create(context.Background(), false, "", false, "test", "test", "test", fakeBuildCache, fakeLaunchCache, []string{}, []string{}, fakePhaseFactory)
870-
// h.AssertError(t, err, fmt.Sprintf("%s", err))
871-
// })
872-
// })
873-
874873
when("--publish is false", func() {
875874
it("passes previous-image to creator", func() {
876875
var imageName name.Tag

internal/commands/build_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -734,14 +734,6 @@ builder = "my-builder"
734734
h.AssertNil(t, command.Execute())
735735
})
736736
})
737-
738-
// when("image and previous-image are not in same registry", func() {
739-
// it("fails", func() {
740-
// command.SetArgs([]string{"--builder", "my-builder", "index.docker.io/some/image:latest", "--previous-image", "example.io/some/previous-image", "--publish"})
741-
// err := command.Execute()
742-
// h.AssertError(t, err, "image and previous-image should be in the same registry when --publish is true")
743-
// })
744-
// })
745737
})
746738
})
747739
})

0 commit comments

Comments
 (0)