Skip to content

Commit

Permalink
feat: go testing (OpenAtomFoundation#118)
Browse files Browse the repository at this point in the history
* go test

* add go.sum

* String
  • Loading branch information
dingxiaoshuai123 authored Jan 11, 2024
1 parent f1d7c47 commit 0508af5
Show file tree
Hide file tree
Showing 11 changed files with 840 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/pikiwidb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ jobs:
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest

- name: Run Go E2E Tests
working-directory: ${{ github.workspace }}/build
run: |
cd ../tests
go mod tidy
go test
build_on_ubuntu:
runs-on: ubuntu-latest
needs: check_format
Expand All @@ -52,3 +59,10 @@ jobs:
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest

- name: Run Go E2E Tests
working-directory: ${{ github.workspace }}/build
run: |
cd ../tests
go mod tidy
go test
70 changes: 70 additions & 0 deletions tests/admin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2023-present, Qihoo, Inc. All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

package pikiwidb_test

import (
"context"
"log"
"strconv"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/redis/go-redis/v9"

"github.com/OpenAtomFoundation/pikiwidb/tests/util"
)

var _ = Describe("Admin", Ordered, func() {
var (
ctx = context.TODO()
s *util.Server
client *redis.Client
)

// BeforeAll closures will run exactly once before any of the specs
// within the Ordered container.
BeforeAll(func() {
config := util.GetConfPath(false, 0)

s = util.StartServer(config, map[string]string{"port": strconv.Itoa(7777)}, true)
Expect(s).NotTo(Equal(nil))
})

// AfterAll closures will run exactly once after the last spec has
// finished running.
AfterAll(func() {
err := s.Close()
if err != nil {
log.Println("Close Server fail.", err.Error())
return
}
})

// When running each spec Ginkgo will first run the BeforeEach
// closure and then the subject closure.Doing so ensures that
// each spec has a pristine, correctly initialized, copy of the
// shared variable.
BeforeEach(func() {
client = s.NewClient()
})

// nodes that run after the spec's subject(It).
AfterEach(func() {
err := client.Close()
if err != nil {
log.Println("Close client conn fail.", err.Error())
return
}
})

//TODO(dingxiaoshuai) Add more test cases.
It("Cmd INFO", func() {
log.Println("Cmd INFO Begin")
Expect(client.Info(ctx).Val()).NotTo(Equal("FooBar"))
})
})
23 changes: 23 additions & 0 deletions tests/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module github.com/OpenAtomFoundation/pikiwidb/tests

go 1.20

require (
github.com/onsi/ginkgo/v2 v2.13.2
github.com/onsi/gomega v1.30.0
github.com/redis/go-redis/v9 v9.0.4
)

require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
49 changes: 49 additions & 0 deletions tests/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
github.com/bsm/ginkgo/v2 v2.7.0 h1:ItPMPH90RbmZJt5GtkcNvIRuGEdwlBItdNVoyzaNQao=
github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs=
github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM=
github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8=
github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redis/go-redis/v9 v9.0.4 h1:FC82T+CHJ/Q/PdyLW++GeCO+Ol59Y4T7R4jbgjvktgc=
github.com/redis/go-redis/v9 v9.0.4/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc=
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
70 changes: 70 additions & 0 deletions tests/hash_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2023-present, Qihoo, Inc. All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

package pikiwidb_test

import (
"context"
"log"
"strconv"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/redis/go-redis/v9"

"github.com/OpenAtomFoundation/pikiwidb/tests/util"
)

var _ = Describe("Hash", Ordered, func() {
var (
ctx = context.TODO()
s *util.Server
client *redis.Client
)

// BeforeAll closures will run exactly once before any of the specs
// within the Ordered container.
BeforeAll(func() {
config := util.GetConfPath(false, 0)

s = util.StartServer(config, map[string]string{"port": strconv.Itoa(7777)}, true)
Expect(s).NotTo(Equal(nil))
})

// AfterAll closures will run exactly once after the last spec has
// finished running.
AfterAll(func() {
err := s.Close()
if err != nil {
log.Println("Close Server fail.", err.Error())
return
}
})

// When running each spec Ginkgo will first run the BeforeEach
// closure and then the subject closure.Doing so ensures that
// each spec has a pristine, correctly initialized, copy of the
// shared variable.
BeforeEach(func() {
client = s.NewClient()
})

// nodes that run after the spec's subject(It).
AfterEach(func() {
err := client.Close()
if err != nil {
log.Println("Close client conn fail.", err.Error())
return
}
})

//TODO(dingxiaoshuai) Add more test cases.
It("Cmd HSET", func() {
log.Println("Cmd HSET Begin")
Expect(client.HSet(ctx, "myhash", "one").Val()).NotTo(Equal("FooBar"))
})
})
69 changes: 69 additions & 0 deletions tests/list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2023-present, Qihoo, Inc. All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

package pikiwidb_test

import (
"context"
"log"
"strconv"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/redis/go-redis/v9"

"github.com/OpenAtomFoundation/pikiwidb/tests/util"
)

var _ = Describe("List", Ordered, func() {
var (
ctx = context.TODO()
s *util.Server
client *redis.Client
)

// BeforeAll closures will run exactly once before any of the specs
// within the Ordered container.
BeforeAll(func() {
config := util.GetConfPath(false, 0)

s = util.StartServer(config, map[string]string{"port": strconv.Itoa(7777)}, true)
Expect(s).NotTo(Equal(nil))
})

// AfterAll closures will run exactly once after the last spec has
// finished running.
AfterAll(func() {
err := s.Close()
if err != nil {
log.Println("Close Server fail.", err.Error())
return
}
})

// When running each spec Ginkgo will first run the BeforeEach
// closure and then the subject closure.Doing so ensures that
// each spec has a pristine, correctly initialized, copy of the
// shared variable.
BeforeEach(func() {
client = s.NewClient()
})

// nodes that run after the spec's subject(It).
AfterEach(func() {
err := client.Close()
if err != nil {
log.Println("Close client conn fail.", err.Error())
return
}
})
//TODO(dingxiaoshuai) Add more test cases.
It("Cmd LPUSH", func() {
log.Println("Cmd LPUSH Begin")
Expect(client.LPush(ctx, "mylist", "one", "two").Val()).NotTo(Equal("FooBar"))
})
})
30 changes: 30 additions & 0 deletions tests/pikiwidb_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2023-present, Qihoo, Inc. All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

package pikiwidb_test

import (
"math"
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

const (
DefaultKey = "key"
DefaultValue = "value"
Max64 = math.MaxUint64
Min64 = math.MinInt64
OK = "OK"
Nil = ""
)

func TestPikiwidb(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Tests Suite")
}
Loading

0 comments on commit 0508af5

Please sign in to comment.