Skip to content

Commit

Permalink
WIP Tests Lock file built and resolved image 'metas'
Browse files Browse the repository at this point in the history
  • Loading branch information
cari-lynn committed Sep 8, 2021
1 parent 3d5e1d4 commit 2e7eeff
Showing 1 changed file with 107 additions and 19 deletions.
126 changes: 107 additions & 19 deletions test/e2e/lock_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

var (
imgLockWithMetas = `---
imgLockWithResolvedMetas = `---
apiVersion: imgpkg.carvel.dev/v1alpha1
images:
- annotations:
Expand All @@ -32,7 +32,61 @@ images:
image: index.docker.io/library/nginx@sha256:4a5573037f358b6cdfa2f3e8a9c33a5cf11bcd1675ca72ca76fbe5bd77d0d682
kind: ImagesLock
`
imgLockNoMetas = `---
imgLockWithBuiltMetas = `---
apiVersion: imgpkg.carvel.dev/v1alpha1
images:
- annotations:
kbld.carvel.dev/id: nginx:1.14.2
kbld.carvel.dev/metas: |
- Path: path/to/source
Type: local
- Dirty: true
RemoteURL: [email protected]:vmware-tanzu/carvel-kbld.git
SHA: f7988fb6c02e0ce69257d9bd9cf37ae20a60f1d
Type: git
image: index.docker.io/library/nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
- annotations:
kbld.carvel.dev/id: sample-app
kbld.carvel.dev/metas: |
- Path: path/to/source
Type: local
- Dirty: true
RemoteURL: [email protected]:vmware-tanzu/carvel-kbld.git
SHA: 4a5573037f358b6cdfa2f3e8a9c33a5cf11bcd1
Type: git
image: index.docker.io/library/nginx@sha256:4a5573037f358b6cdfa2f3e8a9c33a5cf11bcd1675ca72ca76fbe5bd77d0d682
kind: ImagesLock
`
imgLockWithBuiltAndPreresolvedMetas = `---
apiVersion: imgpkg.carvel.dev/v1alpha1
images:
- annotations:
kbld.carvel.dev/id: nginx:1.14.2
kbld.carvel.dev/metas: |
- Path: path/to/source
Type: local
- Dirty: true
RemoteURL: [email protected]:vmware-tanzu/carvel-kbld.git
SHA: f7988fb6c02e0ce69257d9bd9cf37ae20a60f1d
Type: git
- Type: preresolved
URL: index.docker.io/library/nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
image: index.docker.io/library/nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
- annotations:
kbld.carvel.dev/id: sample-app
kbld.carvel.dev/metas: |
- Path: path/to/source
Type: local
- Dirty: true
RemoteURL: [email protected]:vmware-tanzu/carvel-kbld.git
SHA: 4a5573037f358b6cdfa2f3e8a9c33a5cf11bcd1
Type: git
- Type: preresolved
URL: index.docker.io/library/nginx@sha256:4a5573037f358b6cdfa2f3e8a9c33a5cf11bcd1675ca72ca76fbe5bd77d0d682
image: index.docker.io/library/nginx@sha256:4a5573037f358b6cdfa2f3e8a9c33a5cf11bcd1675ca72ca76fbe5bd77d0d682
kind: ImagesLock
`
imgLock = `---
apiVersion: imgpkg.carvel.dev/v1alpha1
images:
- annotations:
Expand Down Expand Up @@ -182,16 +236,16 @@ images:
t.Fatalf("Failed while reading " + path)
}

if string(bs) != imgLockWithMetas {
t.Fatalf("Expected >>>%s<<< to match >>>%s<<<", bs, imgLockWithMetas)
if string(bs) != imgLockWithResolvedMetas {
t.Fatalf("Expected >>>%s<<< to match >>>%s<<<", bs, imgLockWithResolvedMetas)
}
}

func TestImgpkgLockFileNotInOutput(t *testing.T) {
env := BuildEnv(t)
kbld := Kbld{t, env.Namespace, env.KbldBinaryPath, Logger{}}

input := imgLockWithMetas
input := imgLock
out, _ := kbld.RunWithOpts([]string{"-f", "-", "--images-annotation=false"}, RunOpts{
StdinReader: strings.NewReader(input),
})
Expand All @@ -211,24 +265,40 @@ images:
- image: nginx:1.14.2
- image: sample-app
---
` + imgLockWithMetas
` + imgLockWithResolvedMetas

out, _ := kbld.RunWithOpts([]string{"-f", "-", "--images-annotation=false"}, RunOpts{
out, _ := kbld.RunWithOpts([]string{"-f", "-"}, RunOpts{
StdinReader: strings.NewReader(input),
})

expectedOut := `---
images:
- image: index.docker.io/library/nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
- image: index.docker.io/library/nginx@sha256:4a5573037f358b6cdfa2f3e8a9c33a5cf11bcd1675ca72ca76fbe5bd77d0d682
metadata:
annotations:
kbld.k14s.io/images: |
- Metas:
- Tag: 1.15.1
Type: resolved
URL: nginx:1.15.1
- Type: preresolved
URL: index.docker.io/library/nginx@sha256:4a5573037f358b6cdfa2f3e8a9c33a5cf11bcd1675ca72ca76fbe5bd77d0d682
URL: index.docker.io/library/nginx@sha256:4a5573037f358b6cdfa2f3e8a9c33a5cf11bcd1675ca72ca76fbe5bd77d0d682
- Metas:
- Tag: 1.14.2
Type: resolved
URL: nginx:1.14.2
- Type: preresolved
URL: index.docker.io/library/nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
URL: index.docker.io/library/nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
`
if out != expectedOut {
t.Fatalf("Expected >>>%s<<< to match >>>%s<<<", out, expectedOut)
}

}

func TestImgpkgLockFileInputSuccessfulWithAnnotations(t *testing.T) {
func TestImgpkgLockFileMetasSuccessful(t *testing.T) {
env := BuildEnv(t)
kbld := Kbld{t, env.Namespace, env.KbldBinaryPath, Logger{}}

Expand All @@ -237,9 +307,11 @@ images:
- image: nginx:1.14.2
- image: sample-app
---
` + imgLockWithMetas
` + imgLockWithBuiltMetas

out, _ := kbld.RunWithOpts([]string{"-f", "-"}, RunOpts{
path := "/tmp/kbld-test-lock-metas"
defer os.RemoveAll(path)
out, _ := kbld.RunWithOpts([]string{"-f", "-", "--imgpkg-lock-output=" + path}, RunOpts{
StdinReader: strings.NewReader(input),
})

Expand All @@ -251,23 +323,38 @@ metadata:
annotations:
kbld.k14s.io/images: |
- Metas:
- Tag: 1.15.1
Type: resolved
URL: nginx:1.15.1
- Path: path/to/source
Type: local
- Dirty: true
RemoteURL: [email protected]:vmware-tanzu/carvel-kbld.git
SHA: 4a5573037f358b6cdfa2f3e8a9c33a5cf11bcd1
Type: git
- Type: preresolved
URL: index.docker.io/library/nginx@sha256:4a5573037f358b6cdfa2f3e8a9c33a5cf11bcd1675ca72ca76fbe5bd77d0d682
URL: index.docker.io/library/nginx@sha256:4a5573037f358b6cdfa2f3e8a9c33a5cf11bcd1675ca72ca76fbe5bd77d0d682
- Metas:
- Tag: 1.14.2
Type: resolved
URL: nginx:1.14.2
- Path: path/to/source
Type: local
- Dirty: true
RemoteURL: [email protected]:vmware-tanzu/carvel-kbld.git
SHA: f7988fb6c02e0ce69257d9bd9cf37ae20a60f1d
Type: git
- Type: preresolved
URL: index.docker.io/library/nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
URL: index.docker.io/library/nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
`
if out != expectedOut {
t.Fatalf("Expected >>>%s<<< to match >>>%s<<<", out, expectedOut)
}

bs, err := ioutil.ReadFile(path)
if err != nil {
t.Fatalf("Failed while reading " + path)
}

if string(bs) != imgLockWithBuiltAndPreresolvedMetas {
t.Fatalf("Expected >>>%s<<< to match >>>%s<<<", bs, imgLockWithBuiltAndPreresolvedMetas)
}
}

func TestImgpkgLockOutputSuccessfulOnDigestedImage(t *testing.T) {
Expand Down Expand Up @@ -301,7 +388,8 @@ images:
t.Fatalf("Failed while reading " + path)
}

if string(bs) != imgLockNoMetas {
t.Fatalf("Expected >>>%s<<< to match >>>%s<<<", bs, imgLockWithMetas)
// For Digest references, Image Lock should not have metas since there is no image metadata
if string(bs) != imgLock {
t.Fatalf("Expected >>>%s<<< to match >>>%s<<<", bs, imgLock)
}
}

0 comments on commit 2e7eeff

Please sign in to comment.