forked from GoogleCloudPlatform/functions-framework-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧪 test(e2e): fiinish knative openfunction state
Signed-off-by: yi-ge-dian <1085266008@qq.com>
- Loading branch information
1 parent
ce5a781
commit ea7f2e9
Showing
25 changed files
with
871 additions
and
12 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
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,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', | ||
}, | ||
}, | ||
}), | ||
}, | ||
}; |
19 changes: 19 additions & 0 deletions
19
test/e2e/knative-openfunction-state/delete/Dockerfile.knative.state.delete
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,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"] |
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,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, | ||
}; |
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,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 |
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,9 @@ | ||
results: | ||
- key: "1" | ||
data: | ||
city: Seattle | ||
state: WA | ||
person: | ||
id: "1036" | ||
org: Dev Ops | ||
token: "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,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', | ||
}, | ||
}, | ||
}), | ||
}, | ||
}; |
19 changes: 19 additions & 0 deletions
19
test/e2e/knative-openfunction-state/get/Dockerfile.knative.state.get
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,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"] |
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,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, | ||
}; |
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,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', | ||
}, | ||
}, | ||
}), | ||
}, | ||
}; |
19 changes: 19 additions & 0 deletions
19
test/e2e/knative-openfunction-state/getbulk/Dockerfile.knative.state.getbulk
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,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"] |
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,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, | ||
}; |
Oops, something went wrong.