Skip to content

Commit

Permalink
test improvements remove deprecates avoid nils, bump go version 1.20.x (
Browse files Browse the repository at this point in the history
#2032)

* test: improvements on e2e extended test: remove deprecates, avoid nils and improve match conditions

* update go version on ci to 1.20.x
  • Loading branch information
jrangelramos authored Oct 18, 2023
1 parent 788f18c commit 3641bfe
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Build
strategy:
matrix:
go: [1.20.2]
go: [1.20.x]
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Check Source
strategy:
matrix:
go: [1.20.2]
go: [1.20.x]
os: ["ubuntu-latest"]
runs-on: ${{ matrix.os }}
steps:
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "1.20.2"
go-version: "1.20.x"
- name: Lint
run: make check && make check-templates
- name: Check that 'func.yaml schema' is up-to-date
Expand All @@ -22,7 +22,7 @@ jobs:
test-unit:
strategy:
matrix:
go: [ 1.20.2 ]
go: [ 1.20.x ]
java: [ 17 ]
os: [ "ubuntu-latest", "windows-latest", "macos-latest" ]
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "1.20.2"
go-version: "1.20.x"
- name: Install Binaries
run: ./hack/binaries.sh
- name: Allocate Cluster
Expand All @@ -67,7 +67,7 @@ jobs:
e2e-test:
strategy:
matrix:
go: [1.20.2]
go: [1.20.x]
os: ["ubuntu-latest"]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -91,7 +91,7 @@ jobs:
e2e-on-cluster-test:
strategy:
matrix:
go: [1.20.2]
go: [1.20.x]
os: ["ubuntu-latest"]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -126,7 +126,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "1.20.2"
go-version: "1.20.x"
# Standard build tasks
- name: Build
run: make cross-platform
Expand Down Expand Up @@ -167,6 +167,6 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "1.20.2"
go-version: "1.20.x"
- uses: imjasonh/[email protected]
- run: ko build --platform=linux/ppc64le,linux/s390x,linux/amd64,linux/arm64 -B ./cmd/func
2 changes: 1 addition & 1 deletion .github/workflows/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Check Schema
strategy:
matrix:
go: [1.20.2]
go: [1.20.x]
os: ["ubuntu-latest"]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-e2e-oncluster-runtime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
continue-on-error: true
strategy:
matrix:
go: [1.20.2]
go: [1.20.x]
os: ["ubuntu-latest"]
func_builder: ["pack", "s2i"]
runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-e2e-oncluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: On Cluster Test
strategy:
matrix:
go: [1.20.2]
go: [1.20.x]
os: ["ubuntu-latest"]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-e2e-runtime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.20.2
go-version: 1.20.x
- name: Install Binaries
run: ./hack/binaries.sh
- name: Allocate Cluster
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: E2E Test
strategy:
matrix:
go: [1.20.2]
go: [1.20.x]
os: ["ubuntu-latest"]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-embedded-fs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Func Embedded FS Test
strategy:
matrix:
go: [1.20.2]
go: [1.20.x]
os: ["ubuntu-latest"]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Integration Test
strategy:
matrix:
go: [1.20.2]
go: [1.20.x]
os: ["ubuntu-latest"]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-podman.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Podman Test
strategy:
matrix:
go: [1.20.2]
go: [1.20.x]
os: ["ubuntu-latest"]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-unit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Unit Test
strategy:
matrix:
go: [1.20.2]
go: [1.20.x]
java: [17]
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
runs-on: ${{ matrix.os }}
Expand Down
1 change: 1 addition & 0 deletions hack/allocate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ networking() {

echo "Install load balancer."
kubectl apply -f "https://raw.githubusercontent.com/metallb/metallb/v0.13.7/config/manifests/metallb-native.yaml"
sleep 5
kubectl wait --namespace metallb-system \
--for=condition=ready pod \
--selector=app=metallb \
Expand Down
25 changes: 25 additions & 0 deletions pkg/functions/client_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
"testing"
"time"

"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/volume"
"github.com/docker/docker/client"

"knative.dev/func/pkg/builders/buildpacks"
"knative.dev/func/pkg/docker"
fn "knative.dev/func/pkg/functions"
Expand Down Expand Up @@ -530,6 +534,27 @@ func del(t *testing.T, c *fn.Client, name string) {
if err := c.Remove(context.Background(), fn.Function{Name: name}, false); err != nil {
t.Fatal(err)
}
cli, _, err := docker.NewClient(client.DefaultDockerHost)
if err != nil {
t.Fatal(err)
}
defer cli.Close()
opts := volume.ListOptions{
Filters: filters.NewArgs(
filters.Arg("name", fmt.Sprintf("pack-cache-func_%s_*", name)),
),
}
resp, err := cli.VolumeList(context.Background(), opts)
if err != nil {
t.Fatal(err)
}
for _, vol := range resp.Volumes {
t.Log("deleting volume:", vol.Name)
err = cli.VolumeRemove(context.Background(), vol.Name, true)
if err != nil {
t.Fatal(err)
}
}
}

// waitFor the named function to become available in List output.
Expand Down
5 changes: 3 additions & 2 deletions test/common/readycheck.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package common

import (
"context"
"testing"
"time"

"k8s.io/apimachinery/pkg/util/wait"
)

func WaitForFunctionReady(t *testing.T, functionName string) (revisionName string, functionUrl string) {
err := wait.PollImmediate(5*time.Second, 1*time.Minute, func() (done bool, err error) {
err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, 1*time.Minute, true, func(ctx context.Context) (done bool, err error) {
revisionName, functionUrl = GetKnativeServiceRevisionAndUrl(t, functionName)
t.Logf("Waiting function to get ready (revision [%v])", revisionName)
return revisionName != "", nil
Expand All @@ -21,7 +22,7 @@ func WaitForFunctionReady(t *testing.T, functionName string) (revisionName strin

// NewRevisionCheck waits for a new revision to report as ready
func WaitForNewRevisionReady(t *testing.T, previousRevision string, functionName string) (newRevision string) {
err := wait.PollImmediate(5*time.Second, 1*time.Minute, func() (done bool, err error) {
err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, 1*time.Minute, true, func(ctx context.Context) (done bool, err error) {
newRevision = GetCurrentServiceRevision(t, functionName)
t.Logf("Waiting for new revision deployment (previous revision [%v], current revision [%v])", previousRevision, newRevision)
return newRevision != "" && newRevision != previousRevision, nil
Expand Down
18 changes: 13 additions & 5 deletions test/e2e/scenario_extended_flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,19 @@ func TestFunctionExtendedFlow(t *testing.T) {
funcPort, attempts := "", 0
for funcPort == "" && attempts < 10 {
t.Logf("----Function Output:\n%v\n", stdout.String())
matches := regexp.MustCompile("Running on host port (.*)").FindStringSubmatch(stdout.String())
findPort := func(exp string, msg string) (port string) {
matches := regexp.MustCompile(exp).FindStringSubmatch(msg)
if len(matches) > 1 {
port = matches[1]
}
return
}
funcPort = findPort("Running on host port (.*)", stdout.String())
if funcPort == "" {
funcPort = findPort("Function started on port (.*)", stdout.String())
}
attempts++
if len(matches) > 1 {
funcPort = matches[1]
} else {
if funcPort == "" {
time.Sleep(200 * time.Millisecond)
}
}
Expand Down Expand Up @@ -92,7 +100,7 @@ func TestFunctionExtendedFlow(t *testing.T) {
time.Sleep(time.Second)

// GET Function HTTP Endpoint
_, bodyResp := testhttp.TestGet(t, "http://:"+funcPort+"?message=local")
_, bodyResp := testhttp.TestGet(t, "http://localhost:"+funcPort+"?message=local")
assert.Assert(t, strings.Contains(bodyResp, `{"message":"local"}`), "function response does not contain expected body.")

// ---------------------------
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/scenario_no_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestFunctionRunWithoutContainer(t *testing.T) {
time.Sleep(time.Second)

// Assert Function endpoint responds
_, bodyResp := testhttp.TestGet(t, "http://:"+funcPort+"?message=run-on-host")
_, bodyResp := testhttp.TestGet(t, "http://localhost:"+funcPort+"?message=run-on-host")
assert.Assert(t, strings.Contains(bodyResp, `GET /?message=run-on-host`), "function response does not contain expected body.")

// Assert Func were not built
Expand Down

0 comments on commit 3641bfe

Please sign in to comment.