Skip to content

Commit

Permalink
feat. update unit test file
Browse files Browse the repository at this point in the history
  • Loading branch information
PotatoCloud committed Mar 18, 2024
1 parent ec31f21 commit db38a20
Show file tree
Hide file tree
Showing 20 changed files with 397 additions and 337 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
go-version: '1.22'

- name: Making RedQueen docker image
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
go-version: '1.22'

- name: Making RedQueen ${{ matrix.goos }}/${{ matrix.goarch }}
run: go build --tags=safety_map -ldflags "-s -w -X 'github.com/RealFax/RedQueen/internal/version.BuildTime=${{ env.build_ts }}' -X 'github.com/RealFax/RedQueen/internal/version.BuildVersion=${{ env.sha_short }}'" -o rqd.${{ matrix.goos }}.${{ matrix.goarch }} ./cmd/rqd/main.go
Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
go-version: '1.22'

- name: Making rqctl ${{ matrix.goos }}/${{ matrix.goarch }}
run: go build -ldflags "-s -w -X 'github.com/RealFax/RedQueen/internal/version.BuildTime=${{ env.build_ts }}' -X 'github.com/RealFax/RedQueen/internal/version.BuildVersion=${{ env.sha_short }}'" -o rqctl.${{ matrix.goos }}.${{ matrix.goarch }} ./cmd/rqctl
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21"
go-version: "1.22"

- name: Test
run: go test -p 1 -v ./...
Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/RealFax/RedQueen

go 1.21
go 1.22

require (
github.com/BurntSushi/toml v1.3.2
Expand All @@ -14,6 +14,7 @@ require (
github.com/julienschmidt/httprouter v1.3.0
github.com/nutsdb/nutsdb v0.14.3
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.9.0
github.com/urfave/cli/v2 v2.25.7
google.golang.org/grpc v1.61.0
google.golang.org/protobuf v1.31.0
Expand All @@ -26,6 +27,7 @@ require (
github.com/boltdb/bolt v1.3.1 // indirect
github.com/bwmarrin/snowflake v0.3.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
Expand All @@ -36,6 +38,7 @@ require (
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/tidwall/btree v1.6.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
Expand All @@ -46,4 +49,5 @@ require (
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tidwall/btree v1.6.0 h1:LDZfKfQIBHGHWSwckhXI0RPSXzlo+KYdjK7FWSqOzzg=
github.com/tidwall/btree v1.6.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
Expand Down
9 changes: 5 additions & 4 deletions internal/rqd/config/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config_test

import (
"github.com/RealFax/RedQueen/internal/rqd/config"
"github.com/stretchr/testify/assert"
"syscall"
"testing"
)
Expand Down Expand Up @@ -30,23 +31,23 @@ func (s *stringValue) String() string { return string(*s) }
func TestBindEnvVar(t *testing.T) {
var s string
config.BindEnvVar(newStringValue("default", &s), "bonjour")
t.Log("Value:", s)
assert.Equal(t, "HELLO", s)
}

func TestEnvStringVar(t *testing.T) {
var s string
config.EnvStringVar(&s, "test_string", "none")
t.Log("Value:", s)
assert.Equal(t, s, "IS_STRING")
}

func TestEnvInt64Var(t *testing.T) {
var i int64
config.EnvInt64Var(&i, "test_int64", -1)
t.Log("Value:", i)
assert.Equal(t, int64(2147483648), i)
}

func TestEnvBoolVar(t *testing.T) {
var b bool
config.EnvBoolVar(&b, "test_bool", false)
t.Log("Value:", b)
assert.Equal(t, true, b)
}
18 changes: 12 additions & 6 deletions internal/rqd/config/flag_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
package config_test

import (
config2 "github.com/RealFax/RedQueen/internal/rqd/config"
"github.com/RealFax/RedQueen/internal/rqd/config"
"github.com/stretchr/testify/assert"
"testing"
)

func TestEncodeClusterBootstraps(t *testing.T) {
t.Log(config2.EncodeClusterBootstraps([]config2.ClusterBootstrap{
var (
bootstraps = []config.ClusterBootstrap{
{"node1", "10.0.0.2:5290"},
{"node2", "10.0.0.3:5290"},
{"node3", "10.0.0.4:5290"},
}))
}
bootstrapString = "node1@10.0.0.2:5290,node2@10.0.0.3:5290,node3@10.0.0.4:5290"
)

func TestEncodeClusterBootstraps(t *testing.T) {
assert.Equal(t, bootstrapString, config.EncodeClusterBootstraps(bootstraps))
}

func TestDecodeClusterBootstraps(t *testing.T) {
clusters, err := config2.DecodeClusterBootstraps("node1@10.0.0.2:5290,node2@10.0.0.3:5290,node3@10.0.0.4:5290")
clusters, err := config.DecodeClusterBootstraps("node1@10.0.0.2:5290,node2@10.0.0.3:5290,node3@10.0.0.4:5290")
if err != nil {
t.Fatal(err)
}

t.Log(clusters)
assert.Equal(t, clusters, bootstraps)
}
21 changes: 11 additions & 10 deletions internal/rqd/raft_log_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ package rqd_test
import (
"github.com/RealFax/RedQueen/api/serverpb"
red "github.com/RealFax/RedQueen/internal/rqd"
"github.com/RealFax/RedQueen/pkg/expr"
"github.com/stretchr/testify/assert"
"testing"
)

var raftLogPayloadMessage = &serverpb.RaftLogPayload{
Command: serverpb.RaftLogCommand_TrySet,
Key: []byte("test_key"),
}

func init() {
n := "test_namespace"
raftLogPayloadMessage.Namespace = &n
}
var (
raftLogPayloadMessage = &serverpb.RaftLogPayload{
Command: serverpb.RaftLogCommand_TrySet,
Key: []byte("test_key"),
Namespace: expr.Pointer("test_namespace"),
}
expectPayloadKey = uint64(4855146586712729396)
)

func TestRaftLogPayloadKey(t *testing.T) {
t.Logf("Payload key: %d", red.RaftLogPayloadKey(raftLogPayloadMessage))
assert.Equal(t, expectPayloadKey, red.RaftLogPayloadKey(raftLogPayloadMessage))
}

func BenchmarkRaftLogPayloadKey(b *testing.B) {
Expand Down
3 changes: 0 additions & 3 deletions internal/rqd/store/nuts/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,6 @@ func (s *DB) Snapshot() (io.Reader, error) {
}

_ = db.Merge()
//if err = db.Merge(); err != nil {
// return nil, errors.Wrap(err, "fail snapshot, merge error")
//}

buf := &bytes.Buffer{}
return buf, db.View(func(tx *nutsdb.Tx) error {
Expand Down
Loading

0 comments on commit db38a20

Please sign in to comment.