-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update for new home az contract from nma (#3151)
* update for new home az contract * fix lint * address comment * fix lint * address comment * Add "AppliedFixes" to HomeAzResponse The NMAgent team has added an API version field to the HomeAZ response as a means to indicate whether or not certain bugfixes have been applied. Since this API Version field conveys no meaningful information, this adds an "AppliedFixes" field to the response to make it meaningful to users. * Implement fmt.Stringer for HomeAZFix This is to ensure that these are prett-printed properly for clients that log them. * Use nmagent.(HomeAZResponse).ContainsFixes in CNS This alters the response to use the ContainsFixes method added to the HomeAzResponse. Rather than using API Version directly, the more semantically-meaningful constants from the nmagent package are used instead to indicate whether or not some bugfixes have been applied. * add nma client test * fix lint * fix UTs --------- Co-authored-by: Timothy J. Raymond <traymond@microsoft.com>
- Loading branch information
1 parent
7e6e30d
commit 1dc442f
Showing
7 changed files
with
257 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package nmagent_test | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/Azure/azure-container-networking/nmagent" | ||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestContainsFixes(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
resp nmagent.AzResponse | ||
fixes []nmagent.HomeAZFix | ||
exp bool | ||
}{ | ||
{ | ||
"empty", | ||
nmagent.AzResponse{}, | ||
[]nmagent.HomeAZFix{}, | ||
true, | ||
}, | ||
{ | ||
"one present", | ||
nmagent.AzResponse{ | ||
AppliedFixes: []nmagent.HomeAZFix{ | ||
nmagent.HomeAZFixIPv6, | ||
}, | ||
}, | ||
[]nmagent.HomeAZFix{nmagent.HomeAZFixIPv6}, | ||
true, | ||
}, | ||
{ | ||
"one absent", | ||
nmagent.AzResponse{ | ||
AppliedFixes: []nmagent.HomeAZFix{}, | ||
}, | ||
[]nmagent.HomeAZFix{nmagent.HomeAZFixIPv6}, | ||
false, | ||
}, | ||
{ | ||
"one with empty request", | ||
nmagent.AzResponse{ | ||
AppliedFixes: []nmagent.HomeAZFix{ | ||
nmagent.HomeAZFixIPv6, | ||
}, | ||
}, | ||
[]nmagent.HomeAZFix{}, | ||
true, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
test := test | ||
t.Run(test.name, func(t *testing.T) { | ||
t.Parallel() | ||
got := test.resp.ContainsFixes(test.fixes...) | ||
|
||
exp := test.exp | ||
if got != exp { | ||
t.Error("unexpected response from ContainsFixes: exp:", exp, "got:", got) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestUnmarshalAzResponse(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
in string | ||
exp nmagent.AzResponse | ||
shouldErr bool | ||
}{ | ||
{ | ||
"empty", | ||
"{}", | ||
nmagent.AzResponse{}, | ||
false, | ||
}, | ||
{ | ||
"only homeaz", | ||
`{"homeAz": 42}`, | ||
nmagent.AzResponse{ | ||
HomeAz: 42, | ||
}, | ||
false, | ||
}, | ||
{ | ||
"valid apiversion", | ||
`{"homeAz": 42, "apiVersion": 0}`, | ||
nmagent.AzResponse{ | ||
HomeAz: 42, | ||
}, | ||
false, | ||
}, | ||
{ | ||
"valid apiversion ipv6", | ||
`{"homeAz": 42, "apiVersion": 2}`, | ||
nmagent.AzResponse{ | ||
HomeAz: 42, | ||
AppliedFixes: []nmagent.HomeAZFix{ | ||
nmagent.HomeAZFixIPv6, | ||
}, | ||
}, | ||
false, | ||
}, | ||
{ | ||
"invalid apiversion", | ||
`{"homeAz": 42, "apiVersion": 42}`, | ||
nmagent.AzResponse{}, | ||
true, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
test := test | ||
t.Run(test.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
var got nmagent.AzResponse | ||
err := json.Unmarshal([]byte(test.in), &got) | ||
if err != nil && !test.shouldErr { | ||
t.Fatal("unexpected error unmarshaling JSON: err:", err) | ||
} | ||
|
||
if err == nil && test.shouldErr { | ||
t.Fatal("expected error but received none") | ||
} | ||
|
||
exp := test.exp | ||
if !cmp.Equal(got, exp) { | ||
t.Error("received response differs from expected: diff:", cmp.Diff(got, exp)) | ||
} | ||
}) | ||
} | ||
} |