Skip to content

Commit

Permalink
Fix Type Issue In Ethtool Test (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethAmazon authored Aug 30, 2022
1 parent 1e5dbf0 commit 0cc4df3
Showing 1 changed file with 25 additions and 8 deletions.
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 {
_, 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",
],
"bw_in_allowance_exceeded"
]
}}`), &input)
if e == nil {
if err == nil {
_, 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)
}
}

0 comments on commit 0cc4df3

Please sign in to comment.