Skip to content

Commit

Permalink
test: add more server e2e test (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
sysulq committed Nov 28, 2022
1 parent 661dcba commit 2dab55a
Show file tree
Hide file tree
Showing 13 changed files with 1,381 additions and 27 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: e2e-test

on:
push:
paths-ignore:
- "website/**"
branches:
- "master"
pull_request:
paths-ignore:
- "website/**"
branches:
- "master"

jobs:
e2e-test:
name: Test on ubuntu
strategy:
fail-fast: true
matrix:
go: ["1.18.x"]
runs-on: ubuntu-latest

steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3.1.0

- name: docker-compose
run: docker-compose -f test/docker-compose.yaml up -d

- uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
id: go

- name: Install ginkgo
run: |
go install github.com/onsi/ginkgo/v2/ginkgo@latest
sudo cp ~/go/bin/ginkgo /usr/local/bin
- name: Get dependencies
run: |
go env
go mod tidy && git diff --exit-code go.mod go.sum
- name: E2E test
run: |
make e2e-test
40 changes: 22 additions & 18 deletions .github/workflows/go.yml → .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Go
name: unit-test

on:
push:
Expand All @@ -13,13 +13,13 @@ on:
- "master"

jobs:
lint-and-build:
name: Build
lint:
name: Lint
strategy:
fail-fast: false
fail-fast: true
matrix:
go: ["1.18.x", "1.19.x"]
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}

steps:
Expand All @@ -40,33 +40,26 @@ jobs:
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-
- name: Get dependencies
run: |
go env
go get -v -t -d ./...
go mod tidy && git diff --exit-code go.mod go.sum
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.3.1
with:
version: v1.50.1

- name: Build
run: go build -v .

test:
name: Test on ubuntu
strategy:
fail-fast: false
fail-fast: true
matrix:
go: ["1.18.x", "1.19.x"]
runs-on: ubuntu-latest

steps:
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v3.1.0

Expand All @@ -82,14 +75,25 @@ jobs:
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
id: go

- name: Install ginkgo
run: |
go install github.com/onsi/ginkgo/v2/ginkgo@latest
sudo cp ~/go/bin/ginkgo /usr/local/bin
- name: Get dependencies
run: |
go env
go get -v -t -d ./...
go mod tidy && git diff --exit-code go.mod go.sum
- name: Test
run: |
go test -race -coverprofile=coverage.txt -covermode=atomic ./...
make unit-test
- name: Codecov
uses: codecov/codecov-action@v3
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,11 @@ lintl:

lintmd:
markdownlint -c .github/markdown_lint_config.json website/docs README.md pkg

e2e-test:
cd test/e2e \
&& ginkgo -r -race -cover -covermode=atomic -coverprofile=coverage.txt -r --randomize-all --randomize-suites --trace -coverpkg=github.com/douyu/jupiter/... .\
&& cd -

unit-test:
go test -race -coverprofile=coverage.txt -covermode=atomic ./...
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ require (
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa
google.golang.org/grpc v1.51.0
google.golang.org/protobuf v1.28.1
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/mysql v1.4.4
gorm.io/gorm v1.24.2
)
Expand Down Expand Up @@ -152,5 +153,4 @@ require (
golang.org/x/tools v0.2.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
16 changes: 13 additions & 3 deletions pkg/core/tests/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/proto"
)

Expand All @@ -32,8 +33,9 @@ type GRPCTestCase struct {
Method string
Args interface{}

ExpectError error
ExpectReply interface{}
ExpectError error
ExpectMetadata metadata.MD
ExpectReply interface{}
}

// RunGRPCTestCase runs a test case against the given handler.
Expand All @@ -52,7 +54,11 @@ func RunGRPCTestCase(gtc GRPCTestCase) {
assert.Nil(ginkgoT, err)

reply := reflect.New(reflect.TypeOf(gtc.ExpectReply).Elem())
err = clientConn.Invoke(ctx, gtc.Method, gtc.Args, reply.Interface())

metadata := metadata.New(nil)

err = clientConn.Invoke(ctx, gtc.Method, gtc.Args, reply.Interface(),
grpc.Header(&metadata))
assert.Equal(ginkgoT, gtc.ExpectError, err)

replyData, err := proto.Marshal(reply.Interface().(proto.Message))
Expand All @@ -61,6 +67,10 @@ func RunGRPCTestCase(gtc GRPCTestCase) {
expectReplyData, err := proto.Marshal(gtc.ExpectReply.(proto.Message))
assert.Nil(ginkgoT, err)

if gtc.ExpectMetadata != nil {
assert.EqualValues(ginkgoT, gtc.ExpectMetadata, metadata)
}

assert.Equal(ginkgoT, string(expectReplyData), string(replyData))

assert.Nil(ginkgoT, clientConn.Close())
Expand Down
8 changes: 7 additions & 1 deletion pkg/core/tests/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package tests

import (
"context"
"net/http"
"time"

"github.com/go-resty/resty/v2"
Expand All @@ -31,6 +32,7 @@ type HTTPTestCase struct {
Timeout time.Duration
Header map[string]string
Query string
ExpectHeader http.Header
ExpectStatus int
ExpectBody string
}
Expand All @@ -53,11 +55,15 @@ func RunHTTPTestCase(htc HTTPTestCase) {

res, err := req.Execute(htc.Method, htc.Host+htc.Path)

assert.Nil(ginkgoT, err)
assert.Nil(ginkgoT, err, err)

if htc.ExpectStatus > 0 {
assert.Equal(ginkgoT, htc.ExpectStatus, res.StatusCode())
}

if len(htc.ExpectHeader) > 0 {
assert.EqualValues(ginkgoT, htc.ExpectHeader, res.Header())
}

assert.Equal(ginkgoT, htc.ExpectBody, res.String())
}
104 changes: 104 additions & 0 deletions test/e2e/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
module github.com/douyu/jupiter/test/e2e

go 1.18

replace github.com/douyu/jupiter => ../../

require (
github.com/douyu/jupiter v0.0.0-00010101000000-000000000000
github.com/gin-gonic/gin v1.8.1
github.com/gogf/gf v1.16.9
github.com/labstack/echo/v4 v4.9.1
github.com/onsi/ginkgo/v2 v2.5.1
github.com/onsi/gomega v1.24.1
github.com/valyala/fasthttp v1.42.0
google.golang.org/grpc v1.51.0
)

require (
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/alibaba/sentinel-golang v1.0.4 // indirect
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/clbanning/mxj v1.8.5-0.20200714211355-ff02cfb8ea28 // indirect
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.10.0 // indirect
github.com/go-resty/resty/v2 v2.7.0 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gomodule/redigo v2.0.0+incompatible // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grokify/html-strip-tags-go v0.0.1 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/shirou/gopsutil/v3 v3.21.7 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/testify v1.8.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tklauser/go-sysconf v0.3.7 // indirect
github.com/tklauser/numcpus v0.2.3 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
go.etcd.io/etcd/api/v3 v3.5.6 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.6 // indirect
go.etcd.io/etcd/client/v3 v3.5.6 // indirect
go.opentelemetry.io/otel v1.11.1 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.11.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.11.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.11.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.11.1 // indirect
go.opentelemetry.io/otel/sdk v1.11.1 // indirect
go.opentelemetry.io/otel/trace v1.11.1 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.23.0 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/net v0.2.0 // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 2dab55a

Please sign in to comment.