Skip to content

Commit ddf4ab8

Browse files
committed
feat: integration tests target
1 parent f1a6561 commit ddf4ab8

8 files changed

+82
-5
lines changed

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ test-go:
6161
cd templates/go/events && go test
6262
cd templates/go/http && go test
6363

64+
test-integration:
65+
go test -tags integration ./...
66+
6467
image: Dockerfile
6568
docker build -t $(REPO):latest \
6669
-t $(REPO):$(VERS) \

client_int_test.go

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// +build integration
2+
3+
package function_test
4+
5+
import (
6+
boson "github.com/boson-project/func"
7+
"github.com/boson-project/func/knative"
8+
"testing"
9+
)
10+
11+
/*
12+
NOTE: Running integration tests locally requires a configured test cluster.
13+
Test failures may require manual removal of dangling resources.
14+
15+
## Integration Cluster
16+
17+
These integration tests require a properly configured cluster,
18+
such as that which is setup and configured in CI (see .github/workflows).
19+
A local KinD cluster can be started via:
20+
./hack/allocate.sh && ./hack/configure.sh
21+
22+
## Integration Testing
23+
24+
These tests can be run via the make target:
25+
make integration
26+
or manually by specifying the tag
27+
go test -v -tags integration ./...
28+
29+
## Teardown and Cleanup
30+
31+
Tests should clean up after themselves. In the event of failures, one may
32+
need to manually remove files:
33+
rm -rf ./testdata/example.com
34+
The test cluster is not automatically removed, as it can be reused. To remove:
35+
./hack/delete.sh
36+
*/
37+
38+
const DefaultNamespace = "func"
39+
40+
func TestList(t *testing.T) {
41+
verbose := true
42+
43+
// Assemble
44+
lister, err := knative.NewLister(DefaultNamespace)
45+
if err != nil {
46+
t.Fatal(err)
47+
}
48+
client := boson.New(
49+
boson.WithLister(lister),
50+
boson.WithVerbose(verbose))
51+
52+
// Act
53+
names, err := client.List()
54+
if err != nil {
55+
t.Fatal(err)
56+
}
57+
58+
// Assert
59+
if len(names) != 0 {
60+
t.Fatalf("Expected no Functions, got %v", names)
61+
}
62+
}

client_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build !integration
2+
13
package function_test
24

35
import (

docker/runner_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build !integration
2+
13
package docker_test
24

35
import (

function_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build !integration
2+
13
package function
24

35
import "testing"
@@ -13,17 +15,17 @@ func TestFunction_ImageWithDigest(t *testing.T) {
1315
want string
1416
}{
1517
{
16-
name: "Full path with port",
18+
name: "Full path with port",
1719
fields: fields{Image: "image-registry.openshift-image-registry.svc.cluster.local:5000/default/bar", ImageDigest: "42"},
1820
want: "image-registry.openshift-image-registry.svc.cluster.local:5000/default/bar@42",
1921
},
2022
{
21-
name: "Path with namespace",
23+
name: "Path with namespace",
2224
fields: fields{Image: "johndoe/bar", ImageDigest: "42"},
2325
want: "johndoe/bar@42",
2426
},
2527
{
26-
name: "Just image name",
28+
name: "Just image name",
2729
fields: fields{Image: "bar:latest", ImageDigest: "42"},
2830
want: "bar@42",
2931
},

k8s/names_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build !integration
2+
13
package k8s
24

35
import "testing"
@@ -10,8 +12,8 @@ func TestToK8sAllowedName(t *testing.T) {
1012
Out string
1113
Err bool
1214
}{
13-
{"", "", true}, // invalid name
14-
{"*", "", true}, // invalid name
15+
{"", "", true}, // invalid name
16+
{"*", "", true}, // invalid name
1517
{"example", "example", true},
1618
{"example.com", "example-com", false},
1719
{"my-domain.com", "my--domain-com", false},

prompt/prompt_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build !integration
2+
13
package prompt_test
24

35
import (

templates_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build !integration
2+
13
package function
24

35
import (

0 commit comments

Comments
 (0)