mirror of
https://github.com/shouptech/tempgopher.git
synced 2026-02-03 08:39:43 +00:00
Add tests for influx
This commit is contained in:
parent
1b946b9ce8
commit
927f5b9043
3 changed files with 59 additions and 0 deletions
|
|
@ -20,6 +20,9 @@ test:
|
||||||
stage: test
|
stage: test
|
||||||
variables:
|
variables:
|
||||||
GIN_MODE: debug
|
GIN_MODE: debug
|
||||||
|
INFLUXDB_DB: db
|
||||||
|
services:
|
||||||
|
- influxdb
|
||||||
script:
|
script:
|
||||||
- go get -v -t ./...
|
- go get -v -t ./...
|
||||||
- go test -v -coverprofile=$CI_PROJECT_DIR/coverage.out
|
- go test -v -coverprofile=$CI_PROJECT_DIR/coverage.out
|
||||||
|
|
|
||||||
24
influx_test.go
Normal file
24
influx_test.go
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_WriteStateToInflux(t *testing.T) {
|
||||||
|
state := State{Temp: 32}
|
||||||
|
|
||||||
|
// Test failure with empty config
|
||||||
|
err := WriteStateToInflux(state, Influx{})
|
||||||
|
assert.NotEqual(t, nil, err)
|
||||||
|
|
||||||
|
// Test failure with missing database
|
||||||
|
err = WriteStateToInflux(state, Influx{Addr: "http://127.0.0.1:8086"})
|
||||||
|
assert.NotEqual(t, nil, err)
|
||||||
|
|
||||||
|
// Test success with writing to database
|
||||||
|
config := Influx{Addr: "http://127.0.0.1:8086", Database: "db"}
|
||||||
|
err = WriteStateToInflux(state, config)
|
||||||
|
assert.Equal(t, nil, err)
|
||||||
|
}
|
||||||
32
web_test.go
32
web_test.go
|
|
@ -256,3 +256,35 @@ func Test_GetGinAccounts(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, testUsers, actualUsers)
|
assert.Equal(t, testUsers, actualUsers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_reloadWebConfig(t *testing.T) {
|
||||||
|
// Save zero-valued config
|
||||||
|
testConfig := Config{
|
||||||
|
Sensors: []Sensor{},
|
||||||
|
Users: []User{},
|
||||||
|
ListenAddr: ":8080",
|
||||||
|
}
|
||||||
|
|
||||||
|
newConfig := Config{
|
||||||
|
Sensors: []Sensor{},
|
||||||
|
Users: []User{},
|
||||||
|
BaseURL: "http://localhost:8080",
|
||||||
|
ListenAddr: ":8080",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a temp file to store newConfig
|
||||||
|
tmpfile, err := ioutil.TempFile("", "tempgopher")
|
||||||
|
assert.Equal(t, nil, err)
|
||||||
|
defer os.Remove(tmpfile.Name()) // Remove the tempfile when done
|
||||||
|
SaveConfig(tmpfile.Name(), newConfig)
|
||||||
|
|
||||||
|
// Test that newConfig is copied to testConfig
|
||||||
|
err = reloadWebConfig(&testConfig, tmpfile.Name())
|
||||||
|
assert.Equal(t, nil, err)
|
||||||
|
assert.Equal(t, testConfig, newConfig)
|
||||||
|
|
||||||
|
// Test the error case
|
||||||
|
err = reloadWebConfig(&testConfig, "/does/not/exist")
|
||||||
|
assert.NotEqual(t, nil, err)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue