Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow instance attributes to be provided from config file. #893

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 2 additions & 1 deletion agent/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func ZeroOrNil(obj interface{}) bool {
if obj == nil {
return true
}
if value.Kind() == reflect.Slice || value.Kind() == reflect.Array {
switch value.Kind() {
case reflect.Slice, reflect.Array, 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