Skip to content

Commit e866727

Browse files
authored
feat: support to run test suite via http (#478)
* feat: support to run test suite via http * improve the extension download * download extenion in the e2e * add extension-registry into the helm values.yaml file * update helm install in e2e test * fix the k8s helm chart testing --------- Co-authored-by: rick <[email protected]>
1 parent 2e0779d commit e866727

File tree

17 files changed

+539
-297
lines changed

17 files changed

+539
-297
lines changed

cmd/extension.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"io"
2222
"path/filepath"
2323
"runtime"
24+
"time"
2425

2526
"github.com/linuxsuren/api-testing/pkg/downloader"
2627
"github.com/spf13/cobra"
@@ -33,6 +34,7 @@ type extensionOption struct {
3334
tag string
3435
os string
3536
arch string
37+
timeout time.Duration
3638
}
3739

3840
func createExtensionCommand(ociDownloader downloader.PlatformAwareOCIDownloader) (c *cobra.Command) {
@@ -52,12 +54,16 @@ func createExtensionCommand(ociDownloader downloader.PlatformAwareOCIDownloader)
5254
flags.StringVarP(&opt.registry, "registry", "", "", "The target extension image registry, supported: docker.io, ghcr.io")
5355
flags.StringVarP(&opt.os, "os", "", runtime.GOOS, "The OS")
5456
flags.StringVarP(&opt.arch, "arch", "", runtime.GOARCH, "The architecture")
57+
flags.DurationVarP(&opt.timeout, "timeout", "", time.Minute, "The timeout of downloading")
5558
return
5659
}
5760

5861
func (o *extensionOption) runE(cmd *cobra.Command, args []string) (err error) {
5962
o.ociDownloader.WithOS(o.os)
6063
o.ociDownloader.WithArch(o.arch)
64+
o.ociDownloader.WithRegistry(o.registry)
65+
o.ociDownloader.WithTimeout(o.timeout)
66+
o.ociDownloader.WithContext(cmd.Context())
6167

6268
for _, arg := range args {
6369
var reader io.Reader

cmd/extension_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ func TestExtensionCmd(t *testing.T) {
4343
server.Stop()
4444
}()
4545

46-
d.WithRegistry(fmt.Sprintf("127.0.0.1:%s", server.GetPort()))
46+
registry := fmt.Sprintf("127.0.0.1:%s", server.GetPort())
47+
d.WithRegistry(registry)
4748
d.WithInsecure(true)
4849
d.WithBasicAuth("", "")
4950
d.WithOS("linux")
@@ -56,12 +57,12 @@ func TestExtensionCmd(t *testing.T) {
5657
assert.NoError(t, err)
5758

5859
command := createExtensionCommand(d)
59-
command.SetArgs([]string{"git", "--output", tmpDownloadDir})
60+
command.SetArgs([]string{"git", "--output", tmpDownloadDir, "--registry", registry})
6061
err = command.Execute()
6162
assert.NoError(t, err)
6263

6364
// not found
64-
command.SetArgs([]string{"orm", "--output", tmpDownloadDir})
65+
command.SetArgs([]string{"orm", "--output", tmpDownloadDir, "--registry", registry})
6566
err = command.Execute()
6667
assert.Error(t, err)
6768
})

cmd/server.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func createServerCmd(execer fakeruntime.Execer, httpServer server.HTTPServer) (c
9696
flags.BoolVarP(&opt.dryRun, "dry-run", "", false, "Do not really start a gRPC server")
9797
flags.StringArrayVarP(&opt.mockConfig, "mock-config", "", nil, "The mock config files")
9898
flags.StringVarP(&opt.mockPrefix, "mock-prefix", "", "/mock", "The mock server API prefix")
99+
flags.StringVarP(&opt.extensionRegistry, "extension-registry", "", "docker.io", "The extension registry URL")
99100

100101
// gc related flags
101102
flags.IntVarP(&opt.gcPercent, "gc-percent", "", 100, "The GC percent of Go")
@@ -114,14 +115,15 @@ type serverOption struct {
114115
httpServer server.HTTPServer
115116
execer fakeruntime.Execer
116117

117-
port int
118-
httpPort int
119-
printProto bool
120-
localStorage []string
121-
consolePath string
122-
secretServer string
123-
configDir string
124-
skyWalking string
118+
port int
119+
httpPort int
120+
printProto bool
121+
localStorage []string
122+
consolePath string
123+
secretServer string
124+
configDir string
125+
skyWalking string
126+
extensionRegistry string
125127

126128
auth string
127129
oauthProvider string
@@ -241,8 +243,10 @@ func (o *serverOption) runE(cmd *cobra.Command, args []string) (err error) {
241243
template.SetSecretGetter(remote.NewGRPCSecretGetter(secretServer))
242244
}
243245

246+
extDownloader := downloader.NewStoreDownloader()
247+
extDownloader.WithRegistry(o.extensionRegistry)
244248
storeExtMgr := server.NewStoreExtManager(o.execer)
245-
storeExtMgr.WithDownloader(downloader.NewStoreDownloader())
249+
storeExtMgr.WithDownloader(extDownloader)
246250
remoteServer := server.NewRemoteServer(loader, remote.NewGRPCloaderFromStore(), secretServer, storeExtMgr, o.configDir, o.grpcMaxRecvMsgSize)
247251
kinds, storeKindsErr := remoteServer.GetStoreKinds(ctx, nil)
248252
if storeKindsErr != nil {

e2e/compose-k8s.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ services:
3535
- k8s:/output
3636
# This is just so that we get the kubeconfig file out
3737
# - .:/output
38-
ports:
39-
- 30000:30000
38+
# ports:
39+
# - 30000:30000
4040
# - 6443:6443 # Kubernetes API Server
4141
# - 80:80 # Ingress controller port 80
4242
# - 443:443 # Ingress controller port 443

e2e/entrypoint.sh

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,35 @@ set -e
44
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
55
mkdir -p /root/.config/atest
66
mkdir -p /var/data
7-
cd "/var/data"
7+
88
# Generate private key
99
openssl genrsa -out server.key 2048
1010
# Generate self-signed certificate
1111
openssl req -new -x509 -key server.key -out server.crt -days 36500 \
12-
-subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com"
12+
-subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com"
1313
# Generate Certificate Signing Request (CSR)
1414
openssl req -new -key server.key -out server.csr \
15-
-subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com"
15+
-subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com"
1616
# Generate a new private key
1717
openssl genpkey -algorithm RSA -out test.key
1818
# Generate a new CSR
1919
openssl req -new -nodes -key test.key -out test.csr -days 3650 \
20-
-subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" \
21-
-config "$SCRIPT_DIR/openssl.cnf" -extensions v3_req
20+
-subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" \
21+
-config "openssl.cnf" -extensions v3_req
2222
# Sign the new CSR with the self-signed certificate
2323
openssl x509 -req -days 365 -in test.csr \
24-
-out test.pem -CA server.crt -CAkey server.key \
25-
-CAcreateserial -extfile "$SCRIPT_DIR/openssl.cnf" -extensions v3_req
24+
-out test.pem -CA server.crt -CAkey server.key \
25+
-CAcreateserial -extfile "openssl.cnf" -extensions v3_req
26+
27+
echo "start to download extenions"
28+
atest extension --output /usr/local/bin --registry ghcr.io git
29+
atest extension --output /usr/local/bin --registry ghcr.io orm
30+
atest extension --output /usr/local/bin --registry ghcr.io etcd
31+
atest extension --output /usr/local/bin --registry ghcr.io mongodb
2632

27-
nohup atest server --tls-grpc --cert-file /var/data/test.pem --key-file /var/data/test.key&
28-
cmd="atest run -p test-suite-common.yaml --report github --report-github-identity e2e-testing --report-file /var/data/report.json --report-github-repo linuxsuren/api-testing --report-github-pr ${PULL_REQUEST:-0}"
33+
echo "start to run server"
34+
nohup atest server --tls-grpc --cert-file test.pem --key-file test.key&
35+
cmd="atest run -p test-suite-common.yaml"
2936

3037
echo "start to run testing: $cmd"
3138
kind=orm target=mysql:3306 driver=mysql $cmd
@@ -47,4 +54,3 @@ kind=orm target=postgres:5432 driver=postgres $cmd
4754
# kind=s3 target=minio:9000 atest run -p test-suite-common.yaml
4855

4956
cat /root/.config/atest/stores.yaml
50-
exit 0

e2e/k8s.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@ set -e
33

44
sleep 6
55
echo "Running k8s.sh"
6+
7+
ls -hal
8+
cd api-testing
9+
echo "build helm dependency"
10+
helm dependency build
11+
12+
echo "install helm chart"
613
helm install --kube-apiserver https://server:6443 --kube-token abcd --kube-insecure-skip-tls-verify \
7-
api-testing ./api-testing \
14+
api-testing . \
815
--set service.type=NodePort \
916
--set service.nodePort=30000 \
1017
--set persistence.enabled=false \
11-
--set image.registry=linuxsuren.docker.scarf.sh \
18+
--set image.registry=ghcr.io \
1219
--set image.repository=linuxsuren/api-testing \
13-
--set image.tag=master
20+
--set image.tag=master \
21+
--set extension.registry=ghcr.io
1422

1523
SERVER=http://server:30000 atest run -p git.yaml

e2e/start.sh

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,5 @@ then
77
fi
88

99
docker-compose version
10-
docker-compose -f "$file" up --build -d
11-
12-
while true
13-
do
14-
docker-compose -f "$file" ps | grep testing
15-
if [ $? -eq 1 ]
16-
then
17-
code=-1
18-
docker-compose -f "$file" logs | grep testing
19-
docker-compose -f "$file" logs | grep testing | grep Usage
20-
if [ $? -eq 1 ]
21-
then
22-
code=0
23-
echo "successed"
24-
fi
25-
26-
docker-compose -f "$file" down
27-
set -e
28-
exit $code
29-
fi
30-
sleep 1
31-
done
10+
docker-compose -f "$file" down
11+
docker-compose -f "$file" up --build testing --exit-code-from testing --remove-orphans

e2e/test-suite-common.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,16 @@ items:
275275
"suite": "{{.param.gRPCSuiteName}}",
276276
"testcase": "{{.param.gRPCCaseName}}"
277277
}
278+
- name: runTestSuite
279+
request:
280+
api: /RunTestSuite
281+
method: POST
282+
header:
283+
X-Store-Name: "{{.param.store}}"
284+
body: |
285+
{
286+
"name": "{{.param.gRPCSuiteName}}"
287+
}
278288
- name: version
279289
request:
280290
api: /GetVersion

helm/api-testing/templates/deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ spec:
3737
command:
3838
- atest
3939
- server
40+
- --extension-registry={{ .Values.extension.registry }}
4041
- --local-storage=/root/.atest/data/*.yaml
4142
{{- if .Values.skywalking.endpoint.http }}
4243
- --skywalking={{ .Values.skywalking.endpoint.http }}

helm/api-testing/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ persistence:
9393
size: 500Mi
9494
volumeMode: Filesystem
9595

96+
extension:
97+
registry: docker.io
98+
9699
skywalking:
97100
endpoint:
98101
http: "" # http://skywalking-skywalking-helm-oap.skywalking.svc:12800

0 commit comments

Comments
 (0)