Skip to content

Commit 315b545

Browse files
authored
add e2e test (#41)
Signed-off-by: laminar <[email protected]>
1 parent bbeb42f commit 315b545

35 files changed

+1460
-30
lines changed

.github/workflows/go.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Main CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v2
18+
with:
19+
go-version: 1.15
20+
21+
- name: Build
22+
run: go build -v ./...
23+
24+
- name: Test
25+
run: go test -v ./...
26+
27+
e2e_test:
28+
runs-on: ubuntu-latest
29+
timeout-minutes: 30
30+
name: E2E Tests
31+
strategy:
32+
matrix:
33+
case:
34+
- name: Bindings e2e test
35+
e2e: "test/bindings/e2e.yaml"
36+
- name: Pubsub e2e test
37+
e2e: "test/pubsub/e2e.yaml"
38+
- name: Sync HTTP e2e test
39+
e2e: "test/sync-http/e2e.yaml"
40+
- name: Sync Cloudevent e2e test
41+
e2e: "test/sync-cloudevent/e2e.yaml"
42+
steps:
43+
- uses: actions/checkout@v2
44+
45+
- name: install yq
46+
env:
47+
VERSION: v4.22.1
48+
BINARY: yq_linux_amd64
49+
run: |
50+
wget https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY}.tar.gz -O - |\
51+
tar xz && mv ${BINARY} /usr/local/bin/yq
52+
53+
- uses: apache/skywalking-infra-e2e@main
54+
with:
55+
e2e-file: ${{matrix.case.e2e}}
56+
57+
- name: Cleanup
58+
if: ${{ failure() }}
59+
run: e2e cleanup -c ${{matrix.case.e2e}}

framework/framework.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
ofctx "github.com/OpenFunction/functions-framework-go/context"
1212
"github.com/OpenFunction/functions-framework-go/plugin"
1313
plgExample "github.com/OpenFunction/functions-framework-go/plugin/plugin-example"
14+
"github.com/OpenFunction/functions-framework-go/plugin/skywalking"
1415
"github.com/OpenFunction/functions-framework-go/runtime"
1516
"github.com/OpenFunction/functions-framework-go/runtime/async"
1617
"github.com/OpenFunction/functions-framework-go/runtime/knative"
@@ -93,6 +94,7 @@ func (fwk *functionsFrameworkImpl) RegisterPlugins(customPlugins map[string]plug
9394
// Register default plugins
9495
fwk.pluginMap = map[string]plugin.Plugin{
9596
plgExample.Name: plgExample.New(),
97+
skywalking.Name: skywalking.New(),
9698
}
9799

98100
// Register custom plugins

plugin/plugin-example/plugin-example.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package plugin_example
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67

78
"github.com/fatih/structs"
@@ -80,6 +81,10 @@ func preHookLogic(ctx context.Context) context.Context {
8081

8182
func postHookLogic(numA int64, numB int64) int64 {
8283
sum := numA + numB
83-
klog.Infof("the sum is: %d", sum)
84+
result := map[string]int64{
85+
"sum": sum,
86+
}
87+
resultBytes, _ := json.Marshal(result)
88+
klog.Infof("plugin - Result: %s", resultBytes)
8489
return sum
8590
}

plugin/skywalking/plugin-skywalking.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
)
1616

1717
const (
18-
name = "skywalking"
19-
version = "v1"
18+
Name = "skywalking"
19+
Version = "v1"
2020

2121
componentIDOpenFunction = 5013 // https://github.com/apache/skywalking/blob/master/oap-server/server-starter/src/main/resources/component-libraries.yml#L515
2222
)
@@ -75,6 +75,10 @@ func initGo2sky(ofCtx ofctx.RuntimeContext, p *PluginSkywalking) {
7575

7676
var _ plugin.Plugin = &PluginSkywalking{}
7777

78+
func New() *PluginSkywalking {
79+
return &PluginSkywalking{}
80+
}
81+
7882
type PluginSkywalking struct {
7983
tracer *go2sky.Tracer
8084
}
@@ -84,11 +88,11 @@ func (p *PluginSkywalking) Init() plugin.Plugin {
8488
}
8589

8690
func (p PluginSkywalking) Name() string {
87-
return name
91+
return Name
8892
}
8993

9094
func (p PluginSkywalking) Version() string {
91-
return version
95+
return Version
9296

9397
}
9498

test/bindings/e2e.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
setup:
2+
env: kind
3+
file: ../kind.yaml
4+
steps:
5+
- name: install dapr
6+
command: |
7+
dapr -v || (wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash)
8+
dapr init -k --log-as-json
9+
10+
- name: install helm
11+
command: |
12+
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
13+
14+
- name: install kafka operator
15+
command: |
16+
helm repo add strimzi https://strimzi.io/charts/
17+
helm install kafka-operator -n default strimzi/strimzi-kafka-operator
18+
19+
- name: install kafka
20+
path: ../kafka.yaml
21+
22+
- name: build and load image
23+
command: |
24+
docker build -t bindings_e2e_sender:latest -f test/bindings/sender/Dockerfile.bindings.sender .
25+
kind load docker-image bindings_e2e_sender:latest
26+
docker build -t bindings_e2e_target:latest -f test/bindings/target/Dockerfile.bindings.target .
27+
kind load docker-image bindings_e2e_target:latest
28+
29+
- name: setup manifests
30+
path: manifests.yaml
31+
wait:
32+
- namespace: default
33+
resource: pod
34+
label-selector: app=bindings-sender
35+
for: condition=Ready
36+
- namespace: default
37+
resource: pod
38+
label-selector: app=bindings-target
39+
for: condition=Ready
40+
41+
timeout: 30m
42+
43+
cleanup:
44+
# always never success failure
45+
on: success
46+
47+
trigger:
48+
action: ""
49+
50+
verify:
51+
# verify with retry strategy
52+
retry:
53+
# max retry count
54+
count: 60
55+
# the interval between two attempts, e.g. 10s, 1m.
56+
interval: 10s
57+
cases:
58+
- query: bash test/bindings/verify.sh | yq
59+
expected: expected.data.yaml

test/bindings/expected.data.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
hello: world
2+
sum: 2

test/bindings/manifests.yaml

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: bindings-target
5+
labels:
6+
app: bindings-target
7+
case: bindings
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
app: bindings-target
13+
case: bindings
14+
template:
15+
metadata:
16+
labels:
17+
app: bindings-target
18+
case: bindings
19+
annotations:
20+
dapr.io/enabled: "true"
21+
dapr.io/app-id: "bindings-target"
22+
dapr.io/app-port: "50003"
23+
dapr.io/log-as-json: "true"
24+
dapr.io/app-protocol: "grpc"
25+
spec:
26+
containers:
27+
- name: target
28+
image: bindings_e2e_target:latest
29+
imagePullPolicy: IfNotPresent
30+
env:
31+
- name: FUNC_CONTEXT
32+
value: |
33+
{
34+
"name": "bindings-target",
35+
"version": "v1",
36+
"requestID": "a0f2ad8d-5062-4812-91e9-95416489fb01",
37+
"port": "50003",
38+
"prePlugins": ["plugin-custom", "plugin-example"],
39+
"postPlugins": ["plugin-custom", "plugin-example"],
40+
"inputs": {
41+
"sender": {
42+
"componentName": "bindings-target",
43+
"componentType": "bindings.kafka"
44+
}
45+
},
46+
"outputs": {},
47+
"runtime": "Async"
48+
}
49+
- name: POD_NAME
50+
valueFrom:
51+
fieldRef:
52+
apiVersion: v1
53+
fieldPath: metadata.name
54+
- name: POD_NAMESPACE
55+
value: default
56+
ports:
57+
- containerPort: 50003
58+
name: function-port
59+
protocol: TCP
60+
---
61+
apiVersion: apps/v1
62+
kind: Deployment
63+
metadata:
64+
name: bindings-sender
65+
labels:
66+
app: bindings-sender
67+
case: bindings
68+
spec:
69+
replicas: 1
70+
selector:
71+
matchLabels:
72+
app: bindings-sender
73+
case: bindings
74+
template:
75+
metadata:
76+
labels:
77+
app: bindings-sender
78+
case: bindings
79+
annotations:
80+
dapr.io/enabled: "true"
81+
dapr.io/app-id: "bindings-sender"
82+
dapr.io/app-port: "50003"
83+
dapr.io/log-as-json: "true"
84+
dapr.io/app-protocol: "grpc"
85+
spec:
86+
containers:
87+
- name: sender
88+
image: bindings_e2e_sender:latest
89+
imagePullPolicy: IfNotPresent
90+
env:
91+
- name: FUNC_CONTEXT
92+
value: |
93+
{
94+
"name": "bindings-sender",
95+
"version": "v1",
96+
"requestID": "a0f2ad8d-5062-4812-91e9-95416489fb01",
97+
"port": "50003",
98+
"inputs": {
99+
"cron": {
100+
"componentName": "cron-for-bindings",
101+
"componentType": "bindings.cron"
102+
}
103+
},
104+
"outputs": {
105+
"target": {
106+
"componentName": "bindings-sender",
107+
"componentType": "bindings.kafka",
108+
"operation": "create"
109+
}
110+
},
111+
"runtime": "Async"
112+
}
113+
- name: POD_NAME
114+
valueFrom:
115+
fieldRef:
116+
apiVersion: v1
117+
fieldPath: metadata.name
118+
- name: POD_NAMESPACE
119+
value: default
120+
ports:
121+
- containerPort: 50003
122+
name: function-port
123+
protocol: TCP
124+
---
125+
apiVersion: dapr.io/v1alpha1
126+
kind: Component
127+
metadata:
128+
name: bindings-target
129+
spec:
130+
type: bindings.kafka
131+
version: v1
132+
metadata:
133+
- name: brokers
134+
value: "kafka-server-kafka-brokers:9092"
135+
- name: consumerGroup
136+
value: "bindings-target"
137+
- name: authRequired
138+
value: "false"
139+
- name: topics
140+
value: "bindings-topic"
141+
- name: publishTopic
142+
value: "bindings-topic"
143+
---
144+
apiVersion: dapr.io/v1alpha1
145+
kind: Component
146+
metadata:
147+
name: bindings-sender
148+
spec:
149+
type: bindings.kafka
150+
version: v1
151+
metadata:
152+
- name: brokers
153+
value: "kafka-server-kafka-brokers:9092"
154+
- name: consumerGroup
155+
value: "bindings-sender"
156+
- name: authRequired
157+
value: "false"
158+
- name: topics
159+
value: "bindings-topic"
160+
- name: publishTopic
161+
value: "bindings-topic"
162+
---
163+
apiVersion: dapr.io/v1alpha1
164+
kind: Component
165+
metadata:
166+
name: cron-for-bindings
167+
spec:
168+
type: bindings.cron
169+
version: v1
170+
metadata:
171+
- name: schedule
172+
value: "@every 2s"

0 commit comments

Comments
 (0)