Skip to content

Commit

Permalink
test: integration test to validate tags output when running verify
Browse files Browse the repository at this point in the history
  • Loading branch information
renzodavid9 committed Jun 5, 2023
1 parent f4838f0 commit 7c05f58
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 1 deletion.
13 changes: 13 additions & 0 deletions integration/testdata/verify-succeed/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM golang:1.15 as builder
COPY main.go .

# `skaffold debug` sets SKAFFOLD_GO_GCFLAGS to disable compiler optimizations
ARG SKAFFOLD_GO_GCFLAGS
RUN go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -o /app main.go

FROM alpine:3
# Define GOTRACEBACK to mark this container as using the Go language runtime
# for `skaffold debug` (https://skaffold.dev/docs/workflows/debug/).
ENV GOTRACEBACK=single
CMD ["./app"]
COPY --from=builder /app .
17 changes: 17 additions & 0 deletions integration/testdata/verify-succeed/app/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
"fmt"
"os"
"time"
)

func main() {
seconds := 0
env := os.Getenv("FOO")
for seconds < 5 {
fmt.Printf("Hello world %v! %v\n", env, seconds)
seconds++
time.Sleep(time.Second * 1)
}
}
25 changes: 24 additions & 1 deletion integration/testdata/verify-succeed/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,27 @@ profiles:
name: alpine-1
image: alpine:3.15.4
command: ["/bin/sh"]
args: ["-c", "echo alpine-1; sleep 2; echo bye alpine-1"]
args: ["-c", "echo alpine-1; sleep 2; echo bye alpine-1"]

- name: local-built-artifact

build:
artifacts:
- image: localtask
context: ./app
- image: img-not-used-in-verify
context: ./app


verify:
- name: alpine-1
container:
name: alpine-1
image: alpine:3.15.4
command: ["/bin/sh"]
args: ["-c", "echo alpine-1; sleep 2; echo bye alpine-1"]

- name: localtask
container:
name: localtask
image: localtask
49 changes: 49 additions & 0 deletions integration/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,52 @@ func checkUniqueLogs(t *testutil.T, logs string, expectedUniqueLogs []string) {
}
}
}

func TestVerify_WithLocalArtifact(t *testing.T) {
tests := []struct {
description string
dir string
profile string
expectedMsgs []string
notExpectedMsgs []string
}{
{
description: "build and verify",
dir: "testdata/verify-succeed",
profile: "local-built-artifact",
expectedMsgs: []string{
"Tags used in verification:",
"- localtask ->",
"[localtask] Hello world ! 0",
"[alpine-1] alpine-1",
},
notExpectedMsgs: []string{
"- img-not-used-in-verify ->",
},
},
}

for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
MarkIntegrationTest(t.T, CanRunWithoutGcp)

args := []string{"-p", test.profile}

tmpfile := testutil.TempFile(t.T, "", []byte{})
skaffold.Build(append(args, "--file-output", tmpfile)...).InDir(test.dir).RunOrFail(t.T)

out, err := skaffold.Verify(append(args, "--build-artifacts", tmpfile)...).InDir(test.dir).RunWithCombinedOutput(t.T)
logs := string(out)

t.CheckNoError(err)

for _, expectedMsg := range test.expectedMsgs {
t.CheckContains(expectedMsg, logs)
}

for _, notExpectedMsg := range test.notExpectedMsgs {
testutil.CheckNotContains(t.T, notExpectedMsg, logs)
}
})
}
}

0 comments on commit 7c05f58

Please sign in to comment.