From 924473090e165c7bc0d9d295442f6502f243076e Mon Sep 17 00:00:00 2001 From: Mike Shoup Date: Sat, 27 Oct 2018 19:27:23 -0600 Subject: [PATCH] Allow configuration of InfluxDB address for tests --- .gitlab-ci.yml | 1 + influx_test.go | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6986b36..bf621db 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,6 +21,7 @@ test: variables: GIN_MODE: debug INFLUXDB_DB: db + INFLUXDB_ADDR: http://influxdb:8086 services: - influxdb script: diff --git a/influx_test.go b/influx_test.go index dcce4f7..6d2fa5c 100644 --- a/influx_test.go +++ b/influx_test.go @@ -1,12 +1,14 @@ package main import ( + "os" "testing" "github.com/stretchr/testify/assert" ) func Test_WriteStateToInflux(t *testing.T) { + influxAddr := os.Getenv("INFLUXDB_ADDR") state := State{Temp: 32} // Test failure with empty config @@ -14,11 +16,11 @@ func Test_WriteStateToInflux(t *testing.T) { assert.NotEqual(t, nil, err) // Test failure with missing database - err = WriteStateToInflux(state, Influx{Addr: "http://127.0.0.1:8086"}) + err = WriteStateToInflux(state, Influx{Addr: influxAddr}) assert.NotEqual(t, nil, err) // Test success with writing to database - config := Influx{Addr: "http://127.0.0.1:8086", Database: "db"} + config := Influx{Addr: influxAddr, Database: "db"} err = WriteStateToInflux(state, config) assert.Equal(t, nil, err) }