diff --git a/agent/config/config_unix_test.go b/agent/config/config_unix_test.go index 2140e298d06..9eb24561c43 100644 --- a/agent/config/config_unix_test.go +++ b/agent/config/config_unix_test.go @@ -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 @@ -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 diff --git a/agent/utils/utils.go b/agent/utils/utils.go index ede4b0cf13e..3bb5cacb93a 100644 --- a/agent/utils/utils.go +++ b/agent/utils/utils.go @@ -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)) diff --git a/agent/utils/utils_test.go b/agent/utils/utils_test.go index ef0aa00d770..1369e69d53c 100644 --- a/agent/utils/utils_test.go +++ b/agent/utils/utils_test.go @@ -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) {