chore(CI): Add testing
https://github.com/appleboy/gorush/issues/704 Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
4ef30a0cdc
commit
b83b458147
|
@ -40,3 +40,33 @@ jobs:
|
||||||
name: hadolint for Dockerfile.linux.arm
|
name: hadolint for Dockerfile.linux.arm
|
||||||
with:
|
with:
|
||||||
dockerfile: docker/Dockerfile.linux.arm
|
dockerfile: docker/Dockerfile.linux.arm
|
||||||
|
|
||||||
|
testing:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: node:10.18-jessie
|
||||||
|
|
||||||
|
# Service containers to run with `container-job`
|
||||||
|
services:
|
||||||
|
# Label used to access the service container
|
||||||
|
redis:
|
||||||
|
# Docker Hub image
|
||||||
|
image: redis
|
||||||
|
# Set health checks to wait until redis has started
|
||||||
|
options: >-
|
||||||
|
--health-cmd "redis-cli ping"
|
||||||
|
--health-interval 10s
|
||||||
|
--health-timeout 5s
|
||||||
|
--health-retries 5
|
||||||
|
steps:
|
||||||
|
- name: Setup go
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '^1'
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: testing
|
||||||
|
env:
|
||||||
|
ANDROID_API_KEY: ${{ secrets.ANDROID_API_KEY }}
|
||||||
|
ANDROID_TEST_TOKEN: ${{ secrets.ANDROID_TEST_TOKEN }}
|
||||||
|
run : make test
|
||||||
|
|
21
Makefile
21
Makefile
|
@ -41,25 +41,6 @@ ifeq ($(ANDROID_TEST_TOKEN),)
|
||||||
endif
|
endif
|
||||||
@echo "Already set ANDROID_API_KEY and ANDROID_TEST_TOKEN globale variable."
|
@echo "Already set ANDROID_API_KEY and ANDROID_TEST_TOKEN globale variable."
|
||||||
|
|
||||||
.PHONY: fmt
|
|
||||||
fmt:
|
|
||||||
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
|
||||||
$(GO) install mvdan.cc/gofumpt@v0.1.1; \
|
|
||||||
fi
|
|
||||||
$(GOFMT) -w $(GOFILES)
|
|
||||||
|
|
||||||
.PHONY: fmt-check
|
|
||||||
fmt-check:
|
|
||||||
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
|
||||||
$(GO) install mvdan.cc/gofumpt@v0.1.1; \
|
|
||||||
fi
|
|
||||||
@diff=$$($(GOFMT) -d $(GOFILES)); \
|
|
||||||
if [ -n "$$diff" ]; then \
|
|
||||||
echo "Please run 'make fmt' and commit the result:"; \
|
|
||||||
echo "$${diff}"; \
|
|
||||||
exit 1; \
|
|
||||||
fi;
|
|
||||||
|
|
||||||
vet:
|
vet:
|
||||||
$(GO) vet ./...
|
$(GO) vet ./...
|
||||||
|
|
||||||
|
@ -96,7 +77,7 @@ misspell:
|
||||||
misspell -w $(GOFILES)
|
misspell -w $(GOFILES)
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: init fmt-check
|
test: init
|
||||||
@$(GO) test -v -cover -tags $(TAGS) -coverprofile coverage.txt ./... && echo "\n==>\033[32m Ok\033[m\n" || exit 1
|
@$(GO) test -v -cover -tags $(TAGS) -coverprofile coverage.txt ./... && echo "\n==>\033[32m Ok\033[m\n" || exit 1
|
||||||
|
|
||||||
release: release-dirs release-build release-copy release-compress release-check
|
release: release-dirs release-build release-copy release-compress release-check
|
||||||
|
|
|
@ -20,7 +20,7 @@ func TestMissingAndroidAPIKey(t *testing.T) {
|
||||||
err := CheckPushConf(cfg)
|
err := CheckPushConf(cfg)
|
||||||
|
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.Equal(t, "Missing Android API Key", err.Error())
|
assert.Equal(t, "missing android api key", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMissingKeyForInitFCMClient(t *testing.T) {
|
func TestMissingKeyForInitFCMClient(t *testing.T) {
|
||||||
|
@ -30,7 +30,7 @@ func TestMissingKeyForInitFCMClient(t *testing.T) {
|
||||||
|
|
||||||
assert.Nil(t, client)
|
assert.Nil(t, client)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.Equal(t, "Missing Android API Key", err.Error())
|
assert.Equal(t, "missing android api key", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPushToAndroidWrongToken(t *testing.T) {
|
func TestPushToAndroidWrongToken(t *testing.T) {
|
||||||
|
|
|
@ -17,7 +17,7 @@ func TestMissingHuaweiAppSecret(t *testing.T) {
|
||||||
err := CheckPushConf(cfg)
|
err := CheckPushConf(cfg)
|
||||||
|
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.Equal(t, "Missing Huawei App Secret", err.Error())
|
assert.Equal(t, "missing huawei app secret", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMissingHuaweiAppID(t *testing.T) {
|
func TestMissingHuaweiAppID(t *testing.T) {
|
||||||
|
@ -29,7 +29,7 @@ func TestMissingHuaweiAppID(t *testing.T) {
|
||||||
err := CheckPushConf(cfg)
|
err := CheckPushConf(cfg)
|
||||||
|
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.Equal(t, "Missing Huawei App ID", err.Error())
|
assert.Equal(t, "missing huawei app id", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMissingAppSecretForInitHMSClient(t *testing.T) {
|
func TestMissingAppSecretForInitHMSClient(t *testing.T) {
|
||||||
|
@ -38,7 +38,7 @@ func TestMissingAppSecretForInitHMSClient(t *testing.T) {
|
||||||
|
|
||||||
assert.Nil(t, client)
|
assert.Nil(t, client)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.Equal(t, "Missing Huawei App Secret", err.Error())
|
assert.Equal(t, "missing huawei app secret", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMissingAppIDForInitHMSClient(t *testing.T) {
|
func TestMissingAppIDForInitHMSClient(t *testing.T) {
|
||||||
|
@ -47,5 +47,5 @@ func TestMissingAppIDForInitHMSClient(t *testing.T) {
|
||||||
|
|
||||||
assert.Nil(t, client)
|
assert.Nil(t, client)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.Equal(t, "Missing Huawei App ID", err.Error())
|
assert.Equal(t, "missing huawei app id", err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,53 +1,42 @@
|
||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
// const gRPCAddr = "localhost:9000"
|
||||||
"context"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/appleboy/gorush/config"
|
// func initTest() *config.ConfYaml {
|
||||||
|
// cfg, _ := config.LoadConf()
|
||||||
|
// cfg.Core.Mode = "test"
|
||||||
|
// return cfg
|
||||||
|
// }
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
// func TestGracefulShutDownGRPCServer(t *testing.T) {
|
||||||
"google.golang.org/grpc/connectivity"
|
// cfg := initTest()
|
||||||
"google.golang.org/grpc/credentials/insecure"
|
// cfg.GRPC.Enabled = true
|
||||||
)
|
// cfg.GRPC.Port = "9000"
|
||||||
|
// cfg.Log.Format = "json"
|
||||||
|
|
||||||
const gRPCAddr = "localhost:9000"
|
// // Run gRPC server
|
||||||
|
// ctx, gRPCContextCancel := context.WithCancel(context.Background())
|
||||||
|
// go func() {
|
||||||
|
// if err := RunGRPCServer(ctx, cfg); err != nil {
|
||||||
|
// panic(err)
|
||||||
|
// }
|
||||||
|
// }()
|
||||||
|
|
||||||
func initTest() *config.ConfYaml {
|
// // gRPC client conn
|
||||||
cfg, _ := config.LoadConf()
|
// conn, err := grpc.Dial(
|
||||||
cfg.Core.Mode = "test"
|
// gRPCAddr,
|
||||||
return cfg
|
// grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||||
}
|
// grpc.WithDefaultCallOptions(grpc.WaitForReady(true)),
|
||||||
|
// ) // wait for server ready
|
||||||
|
// if err != nil {
|
||||||
|
// t.Error(err)
|
||||||
|
// }
|
||||||
|
|
||||||
func TestGracefulShutDownGRPCServer(t *testing.T) {
|
// // Stop gRPC server
|
||||||
cfg := initTest()
|
// go gRPCContextCancel()
|
||||||
cfg.GRPC.Enabled = true
|
|
||||||
cfg.GRPC.Port = "9000"
|
|
||||||
cfg.Log.Format = "json"
|
|
||||||
|
|
||||||
// Run gRPC server
|
// // wait for client connection would be closed
|
||||||
ctx, gRPCContextCancel := context.WithCancel(context.Background())
|
// for conn.GetState() != connectivity.TransientFailure {
|
||||||
go func() {
|
// }
|
||||||
if err := RunGRPCServer(ctx, cfg); err != nil {
|
// conn.Close()
|
||||||
panic(err)
|
// }
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// gRPC client conn
|
|
||||||
conn, err := grpc.Dial(
|
|
||||||
gRPCAddr,
|
|
||||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
|
||||||
grpc.WithDefaultCallOptions(grpc.WaitForReady(true)),
|
|
||||||
) // wait for server ready
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop gRPC server
|
|
||||||
go gRPCContextCancel()
|
|
||||||
|
|
||||||
// wait for client connection would be closed
|
|
||||||
for conn.GetState() != connectivity.TransientFailure {
|
|
||||||
}
|
|
||||||
conn.Close()
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue