Skip to content

Commit

Permalink
🧪 test(e2e): fiinish knative openfunction state
Browse files Browse the repository at this point in the history
Signed-off-by: yi-ge-dian <1085266008@qq.com>
  • Loading branch information
yi-ge-dian committed Aug 14, 2023
1 parent ce5a781 commit ea7f2e9
Show file tree
Hide file tree
Showing 25 changed files with 871 additions and 12 deletions.
25 changes: 13 additions & 12 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ name: Node.js E2E CI

on:
push:
branches: [ master ]
branches: [master]
paths:
- '.github/workflows/**'
- 'docs/**'
- 'src/**'
- 'test/**'
- 'package.json'
- 'package-lock.json'
- ".github/workflows/**"
- "docs/**"
- "src/**"
- "test/**"
- "package.json"
- "package-lock.json"
# pull_request:
# branches: [ master ]
# paths:
Expand Down Expand Up @@ -38,10 +38,12 @@ jobs:
# e2e: "test/e2e/knative-openfunction-bindings/e2e.yaml"
# - name: knative openfunction pubsub e2e test
# e2e: "test/e2e/knative-openfunction-pubsub/e2e.yaml"
- name: async openfunction bindings e2e test
e2e: "test/e2e/async-openfunction-bindings/e2e.yaml"
- name: async openfunction pubsub e2e test
e2e: "test/e2e/async-openfunction-pubsub/e2e.yaml"
# - name: async openfunction bindings e2e test
# e2e: "test/e2e/async-openfunction-bindings/e2e.yaml"
# - name: async openfunction pubsub e2e test
# e2e: "test/e2e/async-openfunction-pubsub/e2e.yaml"
- name: knative openfunction state e2e test
e2e: "test/e2e/knative-openfunction-state/e2e.yaml"
steps:
- uses: actions/checkout@v2

Expand All @@ -52,7 +54,6 @@ jobs:
run: |
wget https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY}.tar.gz -O - |\
tar xz && mv ${BINARY} /usr/local/bin/yq
- uses: apache/skywalking-infra-e2e@main
with:
Expand Down
20 changes: 20 additions & 0 deletions test/e2e/kind.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,23 @@ nodes:
# optional: set the protocol to one of TCP, UDP, SCTP.
# TCP is the default
protocol: TCP
- containerPort: 31235
hostPort: 81
listenAddress: "127.0.0.1"
protocol: TCP
- containerPort: 31236
hostPort: 82
listenAddress: "127.0.0.1"
protocol: TCP
- containerPort: 31237
hostPort: 83
listenAddress: "127.0.0.1"
protocol: TCP
- containerPort: 31238
hostPort: 84
listenAddress: "127.0.0.1"
protocol: TCP
- containerPort: 31239
hostPort: 85
listenAddress: "127.0.0.1"
protocol: TCP
18 changes: 18 additions & 0 deletions test/e2e/knative-openfunction-state/delete/.env-cmdrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
knative: {
FUNC_CONTEXT: JSON.stringify({
name: 'my-knative-openfunction-state-delete-context',
version: '1.0.0',
runtime: 'knative',
states: {
// there is a policy, if you don't specify the state component, we will use the first one
// or you need specify the state name, then the context will use the one you specify
// hint : specify the name is the record key, not the component name
pg: {
componentName: 'knative-openfunction-state-component',
componentType: 'state.postgresql',
},
},
}),
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Use Node.js 14 as the base image
FROM node:14

# Set working directory
WORKDIR /ff

# Copy project files to container
COPY package.json tsconfig.json /ff/
COPY src /ff/src
COPY test /ff/test

# Install dependencies
RUN npm install

# Set working directory to /ff/test/e2e/knative-openfunction-state/delete
WORKDIR /ff/test/e2e/knative-openfunction-state/delete

# Run the ts-node command to execute src/main.ts
CMD ["../../../../node_modules/.bin/env-cmd", "-e", "knative", "../../../../node_modules/.bin/ts-node", "../../../../src/main.ts", "--target=tryKnativeStateDelete","--signature-type=openfunction"]
16 changes: 16 additions & 0 deletions test/e2e/knative-openfunction-state/delete/function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
async function tryKnativeStateDelete(ctx, data) {
console.log('✅ Function should receive request: %o', data);
await ctx.state
.delete(data)
.then(res => {
console.log('✅ Success delete');
console.log(JSON.stringify(res));
})
.catch(err => {
console.log('❌ Failure occurred: %o', err);
});
}

module.exports = {
tryKnativeStateDelete,
};
90 changes: 90 additions & 0 deletions test/e2e/knative-openfunction-state/e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
setup:
env: kind
file: ../kind.yaml
steps:
- name: install dapr
command: |
dapr -v || (wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash)
dapr init -k -n dapr-system --runtime-version 1.11.0 --log-as-json --wait --timeout 600
wait:
- namespace: dapr-system
resource: pod
label-selector: app.kubernetes.io/name=dapr
for: condition=Ready

- name: install helm
command: |
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
- name: install postgres
command: |
helm repo add bitnami https://charts.bitnami.com/bitnami
helm install postgres -n default bitnami/postgresql -f test/e2e/knative-openfunction-state/pg-values.yaml
# - name: build and load image
# command: |
# docker build -t knative-openfunction-state-save:latest -f test/e2e/knative-openfunction-state/save/Dockerfile.knative.state.save .
# docker build -t knative-openfunction-state-get:latest -f test/e2e/knative-openfunction-state/get/Dockerfile.knative.state.get .
# docker build -t knative-openfunction-state-getbulk:latest -f test/e2e/knative-openfunction-state/getbulk/Dockerfile.knative.state.getbulk .
# docker build -t knative-openfunction-state-delete:latest -f test/e2e/knative-openfunction-state/delete/Dockerfile.knative.state.delete .
# docker build -t knative-openfunction-state-transaction:latest -f test/e2e/knative-openfunction-state/transaction/Dockerfile.knative.state.transaction .
# docker build -t knative-openfunction-state-query:latest -f test/e2e/knative-openfunction-state/query/Dockerfile.knative.state.query .
# kind load docker-image knative-openfunction-state-save:latest
# kind load docker-image knative-openfunction-state-get:latest
# kind load docker-image knative-openfunction-state-getbulk:latest
# kind load docker-image knative-openfunction-state-delete:latest
# kind load docker-image knative-openfunction-state-transaction:latest
# kind load docker-image knative-openfunction-state-query:latest
- name: build and load image
command: |
kind load docker-image knative-openfunction-state-save:latest
kind load docker-image knative-openfunction-state-get:latest
kind load docker-image knative-openfunction-state-getbulk:latest
kind load docker-image knative-openfunction-state-delete:latest
kind load docker-image knative-openfunction-state-transaction:latest
kind load docker-image knative-openfunction-state-query:latest
- name: setup manifests
path: manifests.yaml
wait:
- namespace: default
resource: deployment/knative-openfunction-state-get-deployment
for: condition=Available
- namespace: default
resource: deployment/knative-openfunction-state-save-deployment
for: condition=Available
- namespace: default
resource: deployment/knative-openfunction-state-getbulk-deployment
for: condition=Available
- namespace: default
resource: deployment/knative-openfunction-state-delete-deployment
for: condition=Available
- namespace: default
resource: deployment/knative-openfunction-state-transaction-deployment
for: condition=Available
- namespace: default
resource: deployment/knative-openfunction-state-query-deployment
for: condition=Available
- namespace: default
resource: pod
for: condition=Ready

timeout: 60m

cleanup:
# always never success failure
on: success

trigger:
action: ""

verify:
# verify with retry strategy
retry:
# max retry count
count: 60
# the interval between two attempts, e.g. 10s, 1m.
interval: 10s
cases:
- query: bash test/e2e/knative-openfunction-state/verify.sh 127.0.0.1 80 81 82 83 84 85| yq eval -P
expected: expected.data.yaml
9 changes: 9 additions & 0 deletions test/e2e/knative-openfunction-state/expected.data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
results:
- key: "1"
data:
city: Seattle
state: WA
person:
id: "1036"
org: Dev Ops
token: "1"
18 changes: 18 additions & 0 deletions test/e2e/knative-openfunction-state/get/.env-cmdrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
knative: {
FUNC_CONTEXT: JSON.stringify({
name: 'my-knative-openfunction-state-get-context',
version: '1.0.0',
runtime: 'knative',
states: {
// there is a policy, if you don't specify the state component, we will use the first one
// or you need specify the state name, then the context will use the one you specify
// hint : specify the name is the record key, not the component name
pg: {
componentName: 'knative-openfunction-state-component',
componentType: 'state.postgresql',
},
},
}),
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Use Node.js 14 as the base image
FROM node:14

# Set working directory
WORKDIR /ff

# Copy project files to container
COPY package.json tsconfig.json /ff/
COPY src /ff/src
COPY test /ff/test

# Install dependencies
RUN npm install

# Set working directory to /ff/test/e2e/knative-openfunction-state/get
WORKDIR /ff/test/e2e/knative-openfunction-state/get

# Run the ts-node command to execute src/main.ts
CMD ["../../../../node_modules/.bin/env-cmd", "-e", "knative", "../../../../node_modules/.bin/ts-node", "../../../../src/main.ts", "--target=tryKnativeStateGet","--signature-type=openfunction"]
19 changes: 19 additions & 0 deletions test/e2e/knative-openfunction-state/get/function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
async function tryKnativeStateGet(ctx, data) {
console.log('✅ Function should receive request: %o', data);
await ctx.state
.get(data)
.then(res => {
console.log('✅ Success get');
res.results.forEach(result => {
delete result.etag;
});
console.log(JSON.stringify(res));
})
.catch(err => {
console.log('❌ Failure occurred: %o', err);
});
}

module.exports = {
tryKnativeStateGet,
};
18 changes: 18 additions & 0 deletions test/e2e/knative-openfunction-state/getbulk/.env-cmdrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
knative: {
FUNC_CONTEXT: JSON.stringify({
name: 'my-knative-openfunction-state-getbulk-context',
version: '1.0.0',
runtime: 'knative',
states: {
// there is a policy, if you don't specify the state component, we will use the first one
// or you need specify the state name, then the context will use the one you specify
// hint : specify the name is the record key, not the component name
pg: {
componentName: 'knative-openfunction-state-component',
componentType: 'state.postgresql',
},
},
}),
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Use Node.js 14 as the base image
FROM node:14

# Set working directory
WORKDIR /ff

# Copy project files to container
COPY package.json tsconfig.json /ff/
COPY src /ff/src
COPY test /ff/test

# Install dependencies
RUN npm install

# Set working directory to /ff/test/e2e/knative-openfunction-state/getbulk
WORKDIR /ff/test/e2e/knative-openfunction-state/getbulk

# Run the ts-node command to execute src/main.ts
CMD ["../../../../node_modules/.bin/env-cmd", "-e", "knative", "../../../../node_modules/.bin/ts-node", "../../../../src/main.ts", "--target=tryKnativeStateGetBulk","--signature-type=openfunction"]
16 changes: 16 additions & 0 deletions test/e2e/knative-openfunction-state/getbulk/function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
async function tryKnativeStateGetBulk(ctx, data) {
console.log('✅ Function should receive request: %o', data);
await ctx.state
.getBulk(data)
.then(res => {
console.log('✅ Success getBulk');
console.log(JSON.stringify(res));
})
.catch(err => {
console.log('❌ Failure occurred: %o', err);
});
}

module.exports = {
tryKnativeStateGetBulk,
};
Loading

0 comments on commit ea7f2e9

Please sign in to comment.