Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
startover committed Mar 14, 2017
1 parent ce1f98b commit a0f4a7f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -3,7 +3,7 @@ sudo: false
language: go

go:
- 1.6.3
- 1.7.5

go_import_path: github.com/cloudinsight/cloudinsight-agent

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -11,7 +11,7 @@ running on, or from other services, and sending them to [Cloudinsight](https://c

## Building from source

To build Cloudinsight Agent from the source code yourself you need to have a working Go environment with [version 1.8+](https://golang.org/doc/install).
To build Cloudinsight Agent from the source code yourself you need to have a working Go environment with [version 1.7+](https://golang.org/doc/install).

```
$ mkdir -p $GOPATH/src/github.com/cloudinsight
Expand Down
2 changes: 1 addition & 1 deletion README_zh-CN.md
Expand Up @@ -7,7 +7,7 @@ Cloudinsight 探针可以收集它所在操作系统的各种指标,然后发

## 源代码编译

为了从源代码编译 Cloudinsight 探针,你需要准备一个 Go 语言环境,版本需要 [>= 1.8](https://golang.org/doc/install)
为了从源代码编译 Cloudinsight 探针,你需要准备一个 Go 语言环境,版本需要 [>= 1.7](https://golang.org/doc/install)

```
$ mkdir -p $GOPATH/src/github.com/cloudinsight
Expand Down
1 change: 1 addition & 0 deletions agent/agent.go
Expand Up @@ -140,6 +140,7 @@ func (a *Agent) Test() error {
return err
}

// Wait a second for collecting rate metrics.
time.Sleep(time.Second)
if err := plug.Check(agg); err != nil {
return err
Expand Down
22 changes: 11 additions & 11 deletions common/config/config_test.go
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestLoadConfig(t *testing.T) {
conf, err := NewConfig("testdata/cloudinsight-agent.conf")
conf, err := NewConfig("testdata/cloudinsight-agent.conf", nil)
assert.NoError(t, err)

expectedConf := &Config{
Expand All @@ -35,56 +35,56 @@ func TestLoadConfig(t *testing.T) {
}

func TestBadConfig(t *testing.T) {
_, err := NewConfig("testdata/cloudinsight-agent-bad.conf")
_, err := NewConfig("testdata/cloudinsight-agent-bad.conf", nil)
assert.Error(t, err)
assert.Contains(t, err.Error(), "Failed to load the config file:")
}

func TestDefaultConfig(t *testing.T) {
_, err := NewConfig("testdata/cloudinsight-agent-default.conf")
_, err := NewConfig("testdata/cloudinsight-agent-default.conf", nil)
assert.Error(t, err)
assert.Equal(t, err.Error(), "LicenseKey must be specified in the config file.")
}

func TestGetForwarderAddr(t *testing.T) {
conf, _ := NewConfig("testdata/cloudinsight-agent.conf")
conf, _ := NewConfig("testdata/cloudinsight-agent.conf", nil)

expectedAddr := "localhost:9999"
assert.Equal(t, expectedAddr, conf.GetForwarderAddr())
}

func TestGetForwarderAddrWithNonLocalTraffic(t *testing.T) {
conf, _ := NewConfig("testdata/cloudinsight-agent.conf")
conf, _ := NewConfig("testdata/cloudinsight-agent.conf", nil)
conf.GlobalConfig.NonLocalTraffic = true

expectedAddr := ":9999"
assert.Equal(t, expectedAddr, conf.GetForwarderAddr())
}

func TestGetForwarderAddrWithScheme(t *testing.T) {
conf, _ := NewConfig("testdata/cloudinsight-agent.conf")
conf, _ := NewConfig("testdata/cloudinsight-agent.conf", nil)

expectedAddr := "http://localhost:9999"
assert.Equal(t, expectedAddr, conf.GetForwarderAddrWithScheme())
}

func TestGetStatsdAddr(t *testing.T) {
conf, _ := NewConfig("testdata/cloudinsight-agent.conf")
conf, _ := NewConfig("testdata/cloudinsight-agent.conf", nil)

expectedAddr := "localhost:8125"
assert.Equal(t, expectedAddr, conf.GetStatsdAddr())
}

func TestGetStatsdAddrWithNonLocalTraffic(t *testing.T) {
conf, _ := NewConfig("testdata/cloudinsight-agent.conf")
conf, _ := NewConfig("testdata/cloudinsight-agent.conf", nil)
conf.GlobalConfig.NonLocalTraffic = true

expectedAddr := ":8125"
assert.Equal(t, expectedAddr, conf.GetStatsdAddr())
}

func TestInitializeLogging(t *testing.T) {
conf, err := NewConfig("testdata/cloudinsight-agent.conf")
conf, err := NewConfig("testdata/cloudinsight-agent.conf", nil)
assert.NoError(t, err)
err = conf.InitializeLogging()
assert.NoError(t, err)
Expand All @@ -98,15 +98,15 @@ func TestInitializeLogging(t *testing.T) {
}

func TestInitializeLoggingFailed(t *testing.T) {
conf, err := NewConfig("testdata/cloudinsight-agent.conf")
conf, err := NewConfig("testdata/cloudinsight-agent.conf", nil)
assert.NoError(t, err)
conf.LoggingConfig.LogLevel = "wrong"
err = conf.InitializeLogging()
assert.Error(t, err)
}

func TestGetHostname(t *testing.T) {
conf, err := NewConfig("testdata/cloudinsight-agent.conf")
conf, err := NewConfig("testdata/cloudinsight-agent.conf", nil)
assert.NoError(t, err)
assert.Equal(t, "test", conf.GetHostname())

Expand Down

0 comments on commit a0f4a7f

Please sign in to comment.