Skip to content

Commit

Permalink
refactor: replace test init function
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommi2Day committed Jun 24, 2024
1 parent c9b0483 commit 2923462
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog hmcli

## [v1.2.2 - 2024-06-24]
### Changed
- update dependencies
- replace test init function

## [v1.2.1 - 2024-06-23]
- renamed from check_hm to hmcli
- use common.IsNumeric
Expand Down
2 changes: 1 addition & 1 deletion cmd/datapoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func TestDatapoint(t *testing.T) {
var httpClient = resty.New()
test.Testinit(t)
test.InitTestDirs()
httpmock.Reset()
httpmock.ActivateNonDefault(httpClient.GetClient())
hmlib.SetHTTPClient(httpClient)
Expand Down
2 changes: 1 addition & 1 deletion cmd/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func TestDevices(t *testing.T) {
var httpClient = resty.New()
test.Testinit(t)
test.InitTestDirs()
httpmock.Reset()
httpmock.ActivateNonDefault(httpClient.GetClient())
hmlib.SetHTTPClient(httpClient)
Expand Down
2 changes: 1 addition & 1 deletion cmd/mastervalues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func TestMasterValues(t *testing.T) {
var httpClient = resty.New()
test.Testinit(t)
test.InitTestDirs()
httpmock.ActivateNonDefault(httpClient.GetClient())
defer httpmock.DeactivateAndReset()
hmlib.SetHTTPClient(httpClient)
Expand Down
2 changes: 1 addition & 1 deletion cmd/notification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func TestNotifications(t *testing.T) {
var httpClient = resty.New()
test.Testinit(t)
test.InitTestDirs()
httpmock.ActivateNonDefault(httpClient.GetClient())
defer httpmock.DeactivateAndReset()
hmlib.SetHTTPClient(httpClient)
Expand Down
2 changes: 1 addition & 1 deletion cmd/rssi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func TestRssi(t *testing.T) {
var httpClient = resty.New()
test.Testinit(t)
test.InitTestDirs()
httpmock.ActivateNonDefault(httpClient.GetClient())
defer httpmock.DeactivateAndReset()
hmlib.SetHTTPClient(httpClient)
Expand Down
2 changes: 1 addition & 1 deletion cmd/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func TestSysvar(t *testing.T) {
var httpClient = resty.New()
test.Testinit(t)
test.InitTestDirs()
httpmock.Reset()
httpmock.ActivateNonDefault(httpClient.GetClient())
hmlib.SetHTTPClient(httpClient)
Expand Down
2 changes: 1 addition & 1 deletion cmd/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func TestVersion(t *testing.T) {
var err error
var out = ""
test.Testinit(t)
test.InitTestDirs()
t.Run("Version func", func(t *testing.T) {
actual := GetVersion(false)
assert.NotEmpty(t, actual, "GetVersion should not be empty")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
github.com/tommi2day/gomodules v1.14.1
github.com/tommi2day/gomodules v1.14.2
github.com/x-cray/logrus-prefixed-formatter v0.5.2
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/tommi2day/gomodules v1.14.1 h1:65gZ830hX8cVuT/AhZwCUL7+zyFZWtoWOku/Nau6Dg8=
github.com/tommi2day/gomodules v1.14.1/go.mod h1:wz0a8Ip7t1Nqhht/jXPCRAEhA2xiDLsXfFHpTW2xWEI=
github.com/tommi2day/gomodules v1.14.2 h1:gIM4raI0t7xSINqoEk9uRJZTSfkiLKycZmIAcXr7O+8=
github.com/tommi2day/gomodules v1.14.2/go.mod h1:wz0a8Ip7t1Nqhht/jXPCRAEhA2xiDLsXfFHpTW2xWEI=
github.com/x-cray/logrus-prefixed-formatter v0.5.2 h1:00txxvfBM9muc0jiLIEAkAcIMJzfthRT6usrui8uGmg=
github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
Expand Down
12 changes: 6 additions & 6 deletions test/testfunc.go → test/testinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
"os"
"path"
"runtime"
"testing"

log "github.com/sirupsen/logrus"
)

// TestDir working dir for test
Expand All @@ -15,8 +16,8 @@ var TestDir string
// TestData directory for working Attachments
var TestData string

// Testinit set test directory
func Testinit(t *testing.T) {
// InitTestDirs set test directory
func InitTestDirs() {
_, filename, _, _ := runtime.Caller(0)
dir := path.Dir(filename)
err := os.Chdir(dir)
Expand All @@ -26,10 +27,9 @@ func Testinit(t *testing.T) {
// create data directory and ignore errors
err = os.Mkdir(TestData, 0750)
if err != nil && !os.IsExist(err) {
t.Fatalf("Init error:%s", err)
log.Fatalf("Init error:%s", err)
}
t.Logf("Test in %s", dir)
} else {
t.Fatalf("Init error:%s", err)
log.Fatalf("Init error:%s", err)
}
}

0 comments on commit 2923462

Please sign in to comment.