Skip to content

Commit

Permalink
chore: add e2e test coverage (#1270)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiningRush authored Jan 19, 2021
1 parent 749eeb5 commit b659dfc
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/backend-e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- master

jobs:
run-test:
backend-e2e-test:
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -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
54 changes: 54 additions & 0 deletions api/cmd/manager/main_test.go
Original file line number Diff line number Diff line change
@@ -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
}
}
6 changes: 3 additions & 3 deletions api/test/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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"]
1 change: 1 addition & 0 deletions api/test/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b659dfc

Please sign in to comment.