Skip to content

Commit

Permalink
enhance test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Clivern committed Nov 20, 2018
1 parent d1dc272 commit 656a15d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 53,7 @@ test_short:
## test: Run test cases.
test:
@echo ">> running all tests"
$(GO) test -race -cover -coverprofile=cover.out $(pkgs)
$(GO) test -race -cover $(pkgs)


## lint: Lint the code.
Expand Down Expand Up @@ -98,7 98,7 @@ build:


## ci: Run all CI tests.
ci: style check_license test vet lint coverage
ci: style check_license test vet lint
@echo "\n==> All quality checks passed"


Expand Down
5 changes: 4 additions & 1 deletion internal/app/api/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 9,7 @@ import (
"github.com/clivern/beaver/internal/pkg/utils"
"github.com/nbio/st"
"os"
"strings"
"testing"
)

Expand All @@ -26,7 27,9 @@ func TestChannelAPI(t *testing.T) {
}
config.Cache()
config.GinEnv()
os.Setenv("LogPath", fmt.Sprintf("%s/%s", basePath, os.Getenv("LogPath")))
if !strings.Contains(os.Getenv("LogPath"), basePath) {
os.Setenv("LogPath", fmt.Sprintf("%s/%s", basePath, os.Getenv("LogPath")))
}

channelAPI := &Channel{}
st.Expect(t, channelAPI.Init(), true)
Expand Down
6 changes: 4 additions & 2 deletions internal/app/api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 9,7 @@ import (
"github.com/clivern/beaver/internal/pkg/utils"
"github.com/nbio/st"
"os"
"strings"
"testing"
)

Expand All @@ -26,8 27,9 @@ func TestClientAPI(t *testing.T) {
}
config.Cache()
config.GinEnv()
os.Setenv("LogPath", fmt.Sprintf("%s/%s", basePath, os.Getenv("LogPath")))

if !strings.Contains(os.Getenv("LogPath"), basePath) {
os.Setenv("LogPath", fmt.Sprintf("%s/%s", basePath, os.Getenv("LogPath")))
}
clientAPI := &Client{}
st.Expect(t, clientAPI.Init(), true)
}
28 changes: 27 additions & 1 deletion internal/app/api/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 9,7 @@ import (
"github.com/clivern/beaver/internal/pkg/utils"
"github.com/nbio/st"
"os"
"strings"
"testing"
)

Expand All @@ -26,7 27,20 @@ func TestConfigsAPI(t *testing.T) {
}
config.Cache()
config.GinEnv()
os.Setenv("LogPath", fmt.Sprintf("%s/%s", basePath, os.Getenv("LogPath")))
if !strings.Contains(os.Getenv("LogPath"), basePath) {
os.Setenv("LogPath", fmt.Sprintf("%s/%s", basePath, os.Getenv("LogPath")))
}

configResult := &ConfigResult{Key: "key", Value: "value"}
jsonValue, err := configResult.ConvertToJSON()
st.Expect(t, jsonValue, `{"key":"key","value":"value"}`)
st.Expect(t, err, nil)

ok, err = configResult.LoadFromJSON([]byte(jsonValue))
st.Expect(t, ok, true)
st.Expect(t, err, nil)
st.Expect(t, configResult.Key, "key")
st.Expect(t, configResult.Value, "value")

configAPI := &Config{}
st.Expect(t, configAPI.Init(), true)
Expand All @@ -35,19 49,31 @@ func TestConfigsAPI(t *testing.T) {
st.Expect(t, ok, true)
st.Expect(t, err, nil)

ok, err = configAPI.CreateConfig("key", "value")
st.Expect(t, ok, false)

value, err := configAPI.GetConfigByKey("key")
st.Expect(t, value, "value")
st.Expect(t, err, nil)

value, err = configAPI.GetConfigByKey("not_exist")
st.Expect(t, value, "")

ok, err = configAPI.UpdateConfigByKey("key", "new_value")
st.Expect(t, ok, true)
st.Expect(t, err, nil)

ok, err = configAPI.UpdateConfigByKey("not_exist", "new_value")
st.Expect(t, ok, false)

value, err = configAPI.GetConfigByKey("key")
st.Expect(t, value, "new_value")
st.Expect(t, err, nil)

ok, err = configAPI.DeleteConfigByKey("key")
st.Expect(t, ok, true)
st.Expect(t, err, nil)

ok, err = configAPI.DeleteConfigByKey("not_exist")
st.Expect(t, ok, false)
}
4 changes: 3 additions & 1 deletion internal/pkg/logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 29,9 @@ func TestLogging(t *testing.T) {
}
config.Cache()
config.GinEnv()
os.Setenv("LogPath", fmt.Sprintf("%s/%s", basePath, os.Getenv("LogPath")))
if !strings.Contains(os.Getenv("LogPath"), basePath) {
os.Setenv("LogPath", fmt.Sprintf("%s/%s", basePath, os.Getenv("LogPath")))
}

// Start Test Cases
Info("Info")
Expand Down

0 comments on commit 656a15d

Please sign in to comment.