Skip to content

Commit 1434e16

Browse files
authored
tests: Add integration tests (#17)
* tests: Add integration tests Signed-off-by: Xuanwo <github@xuanwo.io> * Add envs from secrets Signed-off-by: Xuanwo <github@xuanwo.io>
1 parent da50240 commit 1434e16

File tree

8 files changed

+110
-2
lines changed

8 files changed

+110
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: "Integration Test"
2+
3+
on: [push,pull_request]
4+
5+
jobs:
6+
integration_test:
7+
name: "Integration Test"
8+
runs-on: [Linux]
9+
10+
strategy:
11+
matrix:
12+
go: [ "1.14", "1.15" ]
13+
14+
steps:
15+
- name: Set up Go 1.x
16+
uses: actions/setup-go@v2
17+
with:
18+
go-version: ${{ matrix.go }}
19+
20+
- name: Checkout repository
21+
uses: actions/checkout@v2
22+
23+
- name: Test
24+
env:
25+
STORAGE_QINGSTOR_CREDENTIAL: ${{ secrets.STORAGE_QINGSTOR_CREDENTIAL }}
26+
STORAGE_QINGSTOR_ENDPOINT: ${{ secrets.STORAGE_QINGSTOR_ENDPOINT }}
27+
STORAGE_QINGSTOR_NAME: ${{ secrets.STORAGE_QINGSTOR_NAME }}
28+
run: make integration_test

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
coverage.*
2-
bin/
2+
bin/
3+
Makefile.env

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
SHELL := /bin/bash
22

3+
-include Makefile.env
4+
35
.PHONY: all check format vet lint build test generate tidy
46

57
help:
@@ -26,9 +28,12 @@ build: generate tidy check
2628
go build ./...
2729

2830
test:
29-
go test -race -coverprofile=coverage.txt -covermode=atomic -v ./...
31+
go test -race -coverprofile=coverage.txt -covermode=atomic -v .
3032
go tool cover -html="coverage.txt" -o "coverage.html"
3133

34+
integration_test:
35+
go test -tags integration_test -race -covermode=atomic -v ./tests
36+
3237
tidy:
3338
go mod tidy
3439
go mod verify

Makefile.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export STORAGE_QINGSTOR_CREDENTIAL=hamc:access_key:secret_key
2+
export STORAGE_QINGSTOR_ENDPOINT=https:qingstor.com:443
3+
export STORAGE_QINGSTOR_NAME=bucketname

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.14
44

55
require (
66
bou.ke/monkey v1.0.2
7+
github.com/aos-dev/go-integration-test/v2 v2.0.0-20201030072349-1418884fad78
78
github.com/aos-dev/go-storage/v2 v2.0.0
89
github.com/golang/mock v1.4.4
910
github.com/google/uuid v1.1.2

go.sum

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ github.com/Xuanwo/templateutils v0.0.0-20201019101431-c73b871118f2 h1:ydpBZm38sX
66
github.com/Xuanwo/templateutils v0.0.0-20201019101431-c73b871118f2/go.mod h1:x0qS7gfgEm24b8V9U+0zBEBAu/VpxZhO/+EWtpgEgDw=
77
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
88
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
9+
github.com/aos-dev/go-integration-test/v2 v2.0.0-20201030072349-1418884fad78 h1:s/rzb/Zsilm/DOUjlgHNwBo9fByRsTGNCEh/T/uhI0c=
10+
github.com/aos-dev/go-integration-test/v2 v2.0.0-20201030072349-1418884fad78/go.mod h1:NfmZvOzPY/WaTXz7t7+/LaBecD/rvZWZKaQWR5oTQBg=
11+
github.com/aos-dev/go-storage/v2 v2.0.0-20201030030412-57f6d503c7c7/go.mod h1:eHpnrdrHP8mMoT1XdPcd7WRYtJKAYIcHmd2MhMO6l9E=
912
github.com/aos-dev/go-storage/v2 v2.0.0 h1:7o2f1hz8vWSTAV1dH1l/qo8e75wzeP1ZiRPr3TP5DD0=
1013
github.com/aos-dev/go-storage/v2 v2.0.0/go.mod h1:a9oqOqLBsKkgep91ZF1bicbpAodOWtbPs3sAtaScbk8=
1114
github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM=
@@ -18,15 +21,20 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
1821
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1922
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2023
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
24+
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
2125
github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc=
2226
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
2327
github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
2428
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
2529
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
30+
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
2631
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
2732
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
33+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
2834
github.com/hashicorp/hcl/v2 v2.7.0 h1:IU8qz5UzZ1po3M1D9/Kq6S5zbDGVfI9bnzmC1ogKKmI=
2935
github.com/hashicorp/hcl/v2 v2.7.0/go.mod h1:bQTN5mpo+jewjJgh8jr0JUguIi7qPHUF6yIfAEN3jqY=
36+
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
37+
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
3038
github.com/kevinburke/go-bindata v3.22.0+incompatible h1:/JmqEhIWQ7GRScV0WjX/0tqBrC5D21ALg0H0U/KZ/ts=
3139
github.com/kevinburke/go-bindata v3.22.0+incompatible/go.mod h1:/pEEZ72flUW2p0yi30bslSp9YqD9pysLxunQDdb2CPM=
3240
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
@@ -46,6 +54,10 @@ github.com/qingstor/log v0.0.0-20200804082313-615256cccabc/go.mod h1:XfNhERXtkg/
4654
github.com/qingstor/qingstor-sdk-go/v4 v4.2.0 h1:NEMvd0fxdYxhtWzFFtxGeQaDwdgXCDarpa6kKnIuxKs=
4755
github.com/qingstor/qingstor-sdk-go/v4 v4.2.0/go.mod h1:Uu3Bs4hnGW4dEWD+S3j1onwmS18jEcLVIZHknlo1q6o=
4856
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
57+
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
58+
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
59+
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
60+
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
4961
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
5062
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
5163
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
@@ -66,10 +78,12 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
6678
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
6779
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
6880
golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
81+
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
6982
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
7083
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
7184
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
7285
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
86+
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
7387
golang.org/x/tools v0.0.0-20190425150028-36563e24a262 h1:qsl9y/CJx34tuA7QCPNp86JNJe4spst6Ff8MjvPUdPg=
7488
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
7589
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
@@ -81,3 +95,5 @@ gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
8195
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
8296
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
8397
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
98+
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
99+
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

tests/storage_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// +build integration_test
2+
3+
package tests
4+
5+
import (
6+
"testing"
7+
8+
tests "github.com/aos-dev/go-integration-test/v2"
9+
)
10+
11+
func TestStorage(t *testing.T) {
12+
tests.TestStorager(t, setupTest(t))
13+
}

tests/utils_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// +build integration_test
2+
3+
package tests
4+
5+
import (
6+
"os"
7+
"testing"
8+
9+
"github.com/aos-dev/go-service-qingstor"
10+
ps "github.com/aos-dev/go-storage/v2/pairs"
11+
"github.com/aos-dev/go-storage/v2/pkg/credential"
12+
"github.com/aos-dev/go-storage/v2/pkg/endpoint"
13+
"github.com/aos-dev/go-storage/v2/types"
14+
"github.com/google/uuid"
15+
)
16+
17+
func setupTest(t *testing.T) types.Storager {
18+
t.Log("Setup test for qingstor")
19+
20+
cred, err := credential.Parse(os.Getenv("STORAGE_QINGSTOR_CREDENTIAL"))
21+
if err != nil {
22+
t.Errorf("credential parse: %v", err)
23+
}
24+
25+
ep, err := endpoint.Parse(os.Getenv("STORAGE_QINGSTOR_ENDPOINT"))
26+
if err != nil {
27+
t.Errorf("endpoint parse: %v", err)
28+
}
29+
30+
31+
store, err := qingstor.NewStorager(
32+
ps.WithCredential(cred),
33+
ps.WithEndpoint(ep),
34+
ps.WithName(os.Getenv("STORAGE_QINGSTOR_NAME")),
35+
ps.WithWorkDir("/"+uuid.New().String()+"/"),
36+
)
37+
if err != nil {
38+
t.Errorf("new storager: %v", err)
39+
}
40+
return store
41+
}

0 commit comments

Comments
 (0)