Skip to content

Commit 5101d96

Browse files
author
Tristan Weir
committed
Added tests for LookupOperatorTeam
1 parent bb6cf19 commit 5101d96

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

runner-plugins/runner-scribe/main.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ type ServiceApiAsset struct {
6060
Score int `json:"score"`
6161
}
6262

63-
type ServiceApi struct {
64-
URL string
65-
AuthEndpoint string
66-
ClientID string
67-
ClientSecret string
68-
Token string // ephemeral token we generate to connect to ServiceAPI
69-
}
70-
7163
type Auth0Token struct {
7264
AccessToken string `json:"access_token"`
7365
Scope string `json:"scope"`

runner-plugins/runner-scribe/main_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,44 @@ func TestConfigParsing(t *testing.T) {
104104
}
105105
}
106106
}
107+
108+
func TestLookupOperatorTeam(t *testing.T) {
109+
var serviceApiAssets = make(map[string]ServiceApiAsset)
110+
testCases := [][]string{
111+
{ "hostname1", "team1", "operator1" },
112+
{ "hostname2", "", "operator2" },
113+
{ "hostname3", "team3", "" },
114+
{ "hostname4", "", ""},
115+
}
116+
117+
// fill the map with test cases
118+
for _, test := range testCases {
119+
serviceApiAssets[test[0]] = ServiceApiAsset{AssetIdentifier: test[0], Team: test[1], Operator: test[2]}
120+
}
121+
122+
// run the test cases
123+
for _, test := range testCases {
124+
testOperator, testTeam := LookupOperatorTeam(test[0], serviceApiAssets)
125+
if testOperator != test[2] || testTeam != test[1] {
126+
t.Errorf(
127+
"Expected operator to be %v but it is %v. Expected team to be %v but it is %v",
128+
test[2],
129+
testOperator,
130+
test[1],
131+
testTeam)
132+
}
133+
}
134+
135+
// test lookup on a nonexistent hostname
136+
testOperator, testTeam := LookupOperatorTeam("hostnameDoesNotExist", serviceApiAssets)
137+
if testOperator != "" || testTeam != "" {
138+
t.Errorf(
139+
"Expected operator to be %v but it is %v. Expected team to be %v but it is %v",
140+
"",
141+
testOperator,
142+
"",
143+
testTeam)
144+
}
145+
146+
147+
}

0 commit comments

Comments
 (0)