Skip to content

Commit

Permalink
test: add testing shell yaml file
Browse files Browse the repository at this point in the history
  • Loading branch information
Geun-Oh committed Mar 28, 2024
1 parent f022a14 commit 4798a58
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 19 deletions.
101 changes: 101 additions & 0 deletions .github/scripts/initialize-wrangler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash

# generate index.ts
cat <<EOF > index.ts
export default { async fetch(Request, env) {
const namespace = env.TEST_NAMESPACE1;
if (Request.url === "http://localhost:8787/writeworkerskvkeyvaluepair") {
const res = await Request.json();
const { key, val } = res;
WriteWorkersKVKeyValuePair(namespace, key, val);
return new Response("Success");
}
else if (Request.url === "http://localhost:8787/listworkerskvkeys") {
const resp = await Request.json();
const { limit, prefix, cursor } = resp;
const list = await ListWorkersKVKeys(namespace, limit, prefix, cursor);
return new Response(list);
}
else if (Request.url === "http://localhost:8787/deleteworkerskvpairbykey") {
const res = await Request.json();
const { key } = res;
await DeleteWorkersKVPairByKey(namespace, key);
return new Response(key)
}
else if (Request.url === "http://localhost:8787/getworkerskvvaluebykey") {
const key = (await Request.json()).key;
const res = await GetWorkersKVValueByKey(namespace, key);
return new Response(res);
}
else if (Request.url === "http://localhost:8787/deleteworkerskventries") {
const res = await Request.json();
const { keys } = res;
const newKeys = keys.filter(x => x.length > 0);
await DeleteWorkersKVEntries(namespace, newKeys);
return new Response("Success")
}
}
}
const GetWorkersKVValueByKey = async (NAMESPACE, key) => {
const val = await NAMESPACE.get(key);
return val;
}
const WriteWorkersKVKeyValuePair = async (NAMESPACE, key, val) => {
await NAMESPACE.put(key, val);
return "Wrote Successfully"
}
const DeleteWorkersKVPairByKey = async (NAMESPACE, key) => {
await NAMESPACE.delete(key);
return "Delete Successfully"
}
const ListWorkersKVKeys = async (NAMESPACE, limit, prefix, cursor) => {
const resp = await NAMESPACE.list({ limit, prefix, cursor });
return JSON.stringify(resp.keys);
}
const DeleteWorkersKVEntries = async (NAMESPACE, keys) => {
for (let key of keys) {
await NAMESPACE.delete(key);
}
return "Delete Successfully"
}
EOF

echo "wrangler.toml generated"

# generate wrangler.toml
cat <<EOF > wrangler.toml
main = "index.ts"
kv_namespaces = [
{ binding = "TEST_NAMESPACE1", id = "hello", preview_id = "world" },
]
workers_dev = true
compatibility_date = "2024-03-20"
port = 8787
EOF

echo "wrangler.toml generated"
52 changes: 33 additions & 19 deletions .github/workflows/test-cloudflarekv.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
name: Run CloudflareKV Tests

on:
push:
branches:
- master
- main
paths:
- "cloudflarekv/**"
pull_request:
paths:
- "cloudflarekv/**"
name: "Tests Cloudflare KV"
branches:
- main

jobs:
Tests:
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
strategy:
matrix:
go-version:
- 1.21.x
- 1.22.x

steps:
- name: Fetch Repository
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
- name: Checkout Repository
uses: actions/checkout@v2

- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.22.x

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- uses: JarvusInnovations/background-action@v1
name: Bootstrap System Under Test (SUT)
with:
go-version: "${{ matrix.go-version }}"
- name: Run Test
run: cd ./cloudflarekv && go test ./... -v -race
run: .github/scripts/initialize-wrangler.sh

wait-on: |
http://localhost:8787
- name: Go to cloudflarekv directory
run: cd cloudflarekv

- name: Run Go Tests
run: go test

0 comments on commit 4798a58

Please sign in to comment.