Skip to content

Commit

Permalink
Allow instance attributes to be provided from config file.
Browse files Browse the repository at this point in the history
Another case of #732,
instance attributes from the config file get overriden by the nil
instance attributes from the environment.
  • Loading branch information
ejholmes committed Jul 19, 2017
1 parent 15de319 commit 8fbe440
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions agent/config/config_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func TestConfigFromFile(t *testing.T) {
assert.Equal(t, cluster, config.Cluster, "cluster name not as expected from file")
assert.Equal(t, dockerAuthType, config.EngineAuthType, "docker auth type not as expected from file")
assert.Equal(t, dockerAuth, string(config.EngineAuthData.Contents()), "docker auth data not as expected from file")
assert.Equal(t, map[string]string{"attribute1": "value1"}, config.InstanceAttributes)
}

// TestDockerAuthMergeFromFile tests docker auth read from file correctly after merge
Expand Down Expand Up @@ -136,6 +137,7 @@ func TestDockerAuthMergeFromFile(t *testing.T) {
assert.Equal(t, cluster, config.Cluster, "cluster name not as expected from environment variable")
assert.Equal(t, dockerAuthType, config.EngineAuthType, "docker auth type not as expected from file")
assert.Equal(t, dockerAuth, string(config.EngineAuthData.Contents()), "docker auth data not as expected from file")
assert.Equal(t, map[string]string{"attribute1": "value1"}, config.InstanceAttributes)
}

// setupDockerAuthConfiguration create a temp file store the configuration
Expand Down
2 changes: 1 addition & 1 deletion agent/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func ZeroOrNil(obj interface{}) bool {
if obj == nil {
return true
}
if value.Kind() == reflect.Slice || value.Kind() == reflect.Array {
if value.Kind() == reflect.Slice || value.Kind() == reflect.Array || value.Kind() == reflect.Map {
return value.Len() == 0
}
zero := reflect.Zero(reflect.TypeOf(obj))
Expand Down
8 changes: 8 additions & 0 deletions agent/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ func TestZeroOrNil(t *testing.T) {
t.Error("Uncomparable structs are never zero")
}

var strMap map[string]string
if !ZeroOrNil(strMap) {
t.Error("map[string]string is not zero or nil")
}

if ZeroOrNil(map[string]string{"foo": "bar"}) {
t.Error("map[string]string{foo:bar} is zero or nil")
}
}

func TestSlicesDeepEqual(t *testing.T) {
Expand Down

0 comments on commit 8fbe440

Please sign in to comment.