-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding events for Test phase (#5573)
* Adding test trigger events * Updating Copyright year. * Updating unit tests. * Adding unit tests. * Added integration test for test events. * Adding integration test for structure test events. * Updating integration tests to verify test completed event. * Updated integration test to use profiles to reduce code duplication. * Removed unused method * Test state reset. * Remove deploy state reset.
- Loading branch information
1 parent
e74d752
commit 70cd58b
Showing
20 changed files
with
351 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
Copyright 2021 The Skaffold Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package integration | ||
|
||
const ( | ||
InProgress = "In Progress" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
Copyright 2021 The Skaffold Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package integration | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"k8s.io/apimachinery/pkg/util/wait" | ||
|
||
"github.com/GoogleContainerTools/skaffold/integration/skaffold" | ||
"github.com/GoogleContainerTools/skaffold/proto/v1" | ||
) | ||
|
||
func TestTestEvents(t *testing.T) { | ||
MarkIntegrationTest(t, CanRunWithoutGcp) | ||
|
||
tests := []struct { | ||
description string | ||
podName string | ||
testDir string | ||
config string | ||
args []string | ||
numOfTests int | ||
}{ | ||
{ | ||
description: "test events for custom test", | ||
podName: "test-events", | ||
testDir: "testdata/test-events", | ||
config: "skaffold.yaml", | ||
args: []string{"--profile", "custom"}, | ||
numOfTests: 1, | ||
}, | ||
{ | ||
description: "test events for structure test", | ||
podName: "test-events", | ||
testDir: "testdata/test-events", | ||
config: "skaffold.yaml", | ||
args: []string{"--profile", "structure"}, | ||
numOfTests: 1, | ||
}, | ||
{ | ||
description: "test events for custom & structure tests", | ||
podName: "test-events", | ||
testDir: "testdata/test-events", | ||
config: "skaffold.yaml", | ||
args: []string{"--profile", "customandstructure"}, | ||
numOfTests: 2, | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.description, func(t *testing.T) { | ||
// Run skaffold build first to fail quickly on a build failure | ||
skaffold.Build(test.args...).InDir(test.testDir).WithConfig(test.config).RunOrFail(t) | ||
|
||
ns, client := SetupNamespace(t) | ||
rpcAddr := randomPort() | ||
|
||
// test.args... | ||
args := append(test.args, "--rpc-port", rpcAddr) | ||
skaffold.Dev(args...).InDir(test.testDir).WithConfig(test.config).InNs(ns.Name).RunLive(t) | ||
|
||
client.WaitForPodsReady(test.podName) | ||
|
||
// Ensure we see a test is triggered in the event log | ||
_, entries := apiEvents(t, rpcAddr) | ||
|
||
for i := 0; i < test.numOfTests; i++ { | ||
verifyTestCompletedWithEvents(t, entries) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func verifyTestCompletedWithEvents(t *testing.T, entries chan *proto.LogEntry) { | ||
// Ensure we see a test in progress triggered in the event log | ||
err := wait.Poll(time.Millisecond*500, 2*time.Minute, func() (bool, error) { | ||
e := <-entries | ||
event := e.GetEvent().GetTestEvent() | ||
return event != nil && event.GetStatus() == InProgress, nil | ||
}) | ||
failNowIfError(t, err) | ||
|
||
// Ensure we see the test completed triggered in the event log | ||
err = wait.Poll(time.Millisecond*500, 2*time.Minute, func() (bool, error) { | ||
e := <-entries | ||
event := e.GetEvent().GetTestEvent() | ||
return event != nil && event.GetStatus() == "Complete", nil | ||
}) | ||
failNowIfError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
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 . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: test-events | ||
spec: | ||
containers: | ||
- name: test-events | ||
image: test-events |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
func main() { | ||
for { | ||
fmt.Println("Hello world!") | ||
|
||
time.Sleep(time.Second * 1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apiVersion: skaffold/v2beta13 | ||
kind: Config | ||
build: | ||
artifacts: | ||
- image: test-events | ||
deploy: | ||
kubectl: | ||
manifests: | ||
- k8s-* | ||
profiles: | ||
- name: custom | ||
test: | ||
- image: test-events | ||
custom: | ||
- command: echo Hello! | ||
- name: structure | ||
test: | ||
- image: test-events | ||
structureTests: | ||
- ./test/* | ||
- name: customandstructure | ||
test: | ||
- image: test-events | ||
custom: | ||
- command: echo Hello! | ||
structureTests: | ||
- ./test/* |
6 changes: 6 additions & 0 deletions
6
integration/testdata/test-events/test/profile_structure_test.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
schemaVersion: 2.0.0 | ||
|
||
fileExistenceTests: | ||
- name: 'no go binary' | ||
path: '/usr/bin/go' | ||
shouldExist: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
schemaVersion: 2.0.0 | ||
|
||
fileExistenceTests: | ||
- name: 'no local go binary' | ||
path: /usr/local/bin/go' | ||
shouldExist: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.