This is an automated email from the ASF dual-hosted git repository. membphis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git
The following commit(s) were added to refs/heads/master by this push: new b659dfc chore: add e2e test coverage (#1270) b659dfc is described below commit b659dfc6aff50ffbe7553824575a61aa69cbc409 Author: Vinci Xu <277040...@qq.com> AuthorDate: Tue Jan 19 23:03:31 2021 +0800 chore: add e2e test coverage (#1270) --- .github/workflows/backend-e2e-test.yml | 12 +++++++- api/cmd/manager/main_test.go | 54 ++++++++++++++++++++++++++++++++++ api/test/docker/Dockerfile | 6 ++-- api/test/docker/docker-compose.yaml | 1 + 4 files changed, 69 insertions(+), 4 deletions(-) diff --git a/.github/workflows/backend-e2e-test.yml b/.github/workflows/backend-e2e-test.yml index 7ba1cbd..6bf0fd0 100644 --- a/.github/workflows/backend-e2e-test.yml +++ b/.github/workflows/backend-e2e-test.yml @@ -9,7 +9,7 @@ on: - master jobs: - run-test: + backend-e2e-test: runs-on: ubuntu-latest steps: @@ -52,3 +52,13 @@ jobs: - name: run test for plugin skywalking working-directory: ./api/test/e2e/skywalking run: go test -v + + - name: output test coverage + working-directory: ./api/test/testdata + run: | + go tool cover -func=./integrationcover.out + + - name: upload coverage profile + working-directory: ./api/test/testdata + run: | + bash <(curl -s https://codecov.io/bash) -f ./integrationcover.out diff --git a/api/cmd/manager/main_test.go b/api/cmd/manager/main_test.go new file mode 100644 index 0000000..1e7b51d --- /dev/null +++ b/api/cmd/manager/main_test.go @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package main +import ( + "os" + "os/signal" + "strings" + "syscall" + "testing" +) +func TestMainWrapper(t *testing.T) { + if os.Getenv("ENV") == "test" { + t.Skip("skipping build binary when execute unit test") + } + + var ( + args []string + ) + for _, arg := range os.Args { + switch { + case strings.HasPrefix(arg, "-test"): + default: + args = append(args, arg) + } + } + waitCh := make(chan int, 1) + os.Args = args + go func() { + main() + close(waitCh) + }() + signalCh := make(chan os.Signal, 1) + signal.Notify(signalCh, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGHUP) + select { + case <-signalCh: + return + case <-waitCh: + return + } +} diff --git a/api/test/docker/Dockerfile b/api/test/docker/Dockerfile index 216aa53..9f8a170 100644 --- a/api/test/docker/Dockerfile +++ b/api/test/docker/Dockerfile @@ -25,7 +25,7 @@ RUN mkdir -p /go/manager-api/conf \ && mkdir -p /go/manager-api/build-tools \ && go env -w GOPROXY=https://goproxy.io,direct \ && export GOPROXY=https://goproxy.io \ - && go build -o /go/manager-api/manager-api ./cmd/manager \ + && go test -c -cover -covermode=atomic -o /go/manager-api/manager-api -coverpkg "./..." ./cmd/manager \ && mv /go/src/github.com/apisix/manager-api/entry.sh /go/manager-api/ \ && mv /go/src/github.com/apisix/manager-api/build-tools/* /go/manager-api/build-tools/ \ && mv /go/src/github.com/apisix/manager-api/conf/conf.yaml /go/manager-api/conf/conf.yaml \ @@ -60,5 +60,5 @@ RUN mkdir logs EXPOSE 9000 RUN chmod +x ./entry.sh - -CMD ["/bin/ash", "-c", "/go/manager-api/entry.sh"] +ENTRYPOINT ["/go/manager-api/manager-api"] +CMD ["-test.coverprofile=./testdata/integrationcover.out"] diff --git a/api/test/docker/docker-compose.yaml b/api/test/docker/docker-compose.yaml index cb2d67e..e5762c8 100644 --- a/api/test/docker/docker-compose.yaml +++ b/api/test/docker/docker-compose.yaml @@ -179,6 +179,7 @@ services: restart: always volumes: - ./manager-api-conf.yaml:/go/manager-api/conf/conf.yaml:ro + - ../testdata:/go/manager-api/testdata depends_on: - node1 - node2