Added tests for LookupOperatorTeam

This commit is contained in:
Tristan Weir 2018-12-26 15:56:46 -08:00
Родитель bb6cf19a19
Коммит 5101d96524
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 1C5E6CBF4E06FB04
2 изменённых файлов: 41 добавлений и 8 удалений

Просмотреть файл

@ -60,14 +60,6 @@ type ServiceApiAsset struct {
Score int `json:"score"`
}
type ServiceApi struct {
URL string
AuthEndpoint string
ClientID string
ClientSecret string
Token string // ephemeral token we generate to connect to ServiceAPI
}
type Auth0Token struct {
AccessToken string `json:"access_token"`
Scope string `json:"scope"`

Просмотреть файл

@ -104,3 +104,44 @@ func TestConfigParsing(t *testing.T) {
}
}
}
func TestLookupOperatorTeam(t *testing.T) {
var serviceApiAssets = make(map[string]ServiceApiAsset)
testCases := [][]string{
{ "hostname1", "team1", "operator1" },
{ "hostname2", "", "operator2" },
{ "hostname3", "team3", "" },
{ "hostname4", "", ""},
}
// fill the map with test cases
for _, test := range testCases {
serviceApiAssets[test[0]] = ServiceApiAsset{AssetIdentifier: test[0], Team: test[1], Operator: test[2]}
}
// run the test cases
for _, test := range testCases {
testOperator, testTeam := LookupOperatorTeam(test[0], serviceApiAssets)
if testOperator != test[2] || testTeam != test[1] {
t.Errorf(
"Expected operator to be %v but it is %v. Expected team to be %v but it is %v",
test[2],
testOperator,
test[1],
testTeam)
}
}
// test lookup on a nonexistent hostname
testOperator, testTeam := LookupOperatorTeam("hostnameDoesNotExist", serviceApiAssets)
if testOperator != "" || testTeam != "" {
t.Errorf(
"Expected operator to be %v but it is %v. Expected team to be %v but it is %v",
"",
testOperator,
"",
testTeam)
}
}