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

Fix Type Issue In Ethtool Test #583

Merged
merged 1 commit into from
Aug 30, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
func TestDefaultConfig(t *testing.T) {
d := new(Ethtool)
var input interface{}
e := json.Unmarshal([]byte(`{"ethtool": {
err := json.Unmarshal([]byte(`{"ethtool": {
}}`), &input)
if e == nil {
if err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err == nil {
assert.NoError(t, err)

_, actual := d.ApplyRule(input)

d := []interface{}{map[string]interface{}{
Expand All @@ -24,33 +24,50 @@ func TestDefaultConfig(t *testing.T) {
},
}
assert.Equal(t, d, actual, "Expected to be equal")
} else {
panic(err)
}
}

func TestFullConfig(t *testing.T) {
d := new(Ethtool)
var input interface{}
e := json.Unmarshal([]byte(`{"ethtool": {
err := json.Unmarshal([]byte(`{"ethtool": {
"interface_include": [
"eth0"
],
"interface_exclude": [
"eth1"
],
"metrics_include": [
"bw_in_allowance_exceeded",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is invalid json.

],
"bw_in_allowance_exceeded"
]
}}`), &input)
if e == nil {
if err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err == nil {
assert.NoError(t, err)

_, actual := d.ApplyRule(input)

d := []interface{}{map[string]interface{}{
expected := []interface{}{map[string]interface{}{
"interface_include": []string{"eth0"},
"interface_exclude": []string{"eth1"},
"fieldpass": []string{"bw_in_allowance_exceeded"},
},
}

assert.Equal(t, d, actual, "Expected to be equal")
// compare marshalled values since unmarshalled values have type conflicts
// the actual uses interface instead of expected string type
// interface will be converted to string on marshall
// this is going to be marshalled into toml not pogo
marshalActual, err := json.Marshal(actual)
if err != nil {
return
}
marshalExpected, err := json.Marshal(expected)
if err != nil {
return
}

assert.Equal(t, string(marshalExpected), string(marshalActual), "Expected to be equal")
} else {
panic(err)
}
}