Skip to content

Commit 5402698

Browse files
authored
Typo in test name caused test to not execute (#4330)
1 parent 9ebb97f commit 5402698

File tree

2 files changed

+47
-39
lines changed

2 files changed

+47
-39
lines changed

github/actions/config_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import (
1515
func TestGitHubConfig(t *testing.T) {
1616
t.Run("when given a valid URL", func(t *testing.T) {
1717
tests := []struct {
18+
name string
1819
configURL string
1920
expected *actions.GitHubConfig
2021
}{
2122
{
23+
name: "repository URL",
2224
configURL: "https://github.com/org/repo",
2325
expected: &actions.GitHubConfig{
2426
Scope: actions.GitHubScopeRepository,
@@ -29,6 +31,7 @@ func TestGitHubConfig(t *testing.T) {
2931
},
3032
},
3133
{
34+
name: "repository URL with trailing slash",
3235
configURL: "https://github.com/org/repo/",
3336
expected: &actions.GitHubConfig{
3437
Scope: actions.GitHubScopeRepository,
@@ -39,6 +42,7 @@ func TestGitHubConfig(t *testing.T) {
3942
},
4043
},
4144
{
45+
name: "organization URL",
4246
configURL: "https://github.com/org",
4347
expected: &actions.GitHubConfig{
4448
Scope: actions.GitHubScopeOrganization,
@@ -49,6 +53,7 @@ func TestGitHubConfig(t *testing.T) {
4953
},
5054
},
5155
{
56+
name: "enterprise URL",
5257
configURL: "https://github.com/enterprises/my-enterprise",
5358
expected: &actions.GitHubConfig{
5459
Scope: actions.GitHubScopeEnterprise,
@@ -59,6 +64,7 @@ func TestGitHubConfig(t *testing.T) {
5964
},
6065
},
6166
{
67+
name: "enterprise URL with trailing slash",
6268
configURL: "https://github.com/enterprises/my-enterprise/",
6369
expected: &actions.GitHubConfig{
6470
Scope: actions.GitHubScopeEnterprise,
@@ -69,6 +75,7 @@ func TestGitHubConfig(t *testing.T) {
6975
},
7076
},
7177
{
78+
name: "organization URL with www",
7279
configURL: "https://www.github.com/org",
7380
expected: &actions.GitHubConfig{
7481
Scope: actions.GitHubScopeOrganization,
@@ -79,6 +86,7 @@ func TestGitHubConfig(t *testing.T) {
7986
},
8087
},
8188
{
89+
name: "organization URL with www and trailing slash",
8290
configURL: "https://www.github.com/org/",
8391
expected: &actions.GitHubConfig{
8492
Scope: actions.GitHubScopeOrganization,
@@ -89,6 +97,7 @@ func TestGitHubConfig(t *testing.T) {
8997
},
9098
},
9199
{
100+
name: "github local URL",
92101
configURL: "https://github.localhost/org",
93102
expected: &actions.GitHubConfig{
94103
Scope: actions.GitHubScopeOrganization,
@@ -99,6 +108,7 @@ func TestGitHubConfig(t *testing.T) {
99108
},
100109
},
101110
{
111+
name: "github local org URL",
102112
configURL: "https://my-ghes.com/org",
103113
expected: &actions.GitHubConfig{
104114
Scope: actions.GitHubScopeOrganization,
@@ -109,6 +119,7 @@ func TestGitHubConfig(t *testing.T) {
109119
},
110120
},
111121
{
122+
name: "github local URL with trailing slash",
112123
configURL: "https://my-ghes.com/org/",
113124
expected: &actions.GitHubConfig{
114125
Scope: actions.GitHubScopeOrganization,
@@ -119,6 +130,7 @@ func TestGitHubConfig(t *testing.T) {
119130
},
120131
},
121132
{
133+
name: "github local URL with ghe.com",
122134
configURL: "https://my-ghes.ghe.com/org/",
123135
expected: &actions.GitHubConfig{
124136
Scope: actions.GitHubScopeOrganization,
@@ -131,7 +143,7 @@ func TestGitHubConfig(t *testing.T) {
131143
}
132144

133145
for _, test := range tests {
134-
t.Run(test.configURL, func(t *testing.T) {
146+
t.Run(test.name, func(t *testing.T) {
135147
parsedURL, err := url.Parse(strings.Trim(test.configURL, "/"))
136148
require.NoError(t, err)
137149
test.expected.ConfigURL = parsedURL

github/actions/errors_test.go

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -119,88 +119,84 @@ func TestGitHubAPIError(t *testing.T) {
119119
})
120120
}
121121

122-
func ParseActionsErrorFromResponse(t *testing.T) {
122+
func TestParseActionsErrorFromResponse(t *testing.T) {
123123
t.Run("empty content length", func(t *testing.T) {
124124
response := &http.Response{
125125
ContentLength: 0,
126-
Header: http.Header{
127-
actions.HeaderActionsActivityID: []string{"activity-id"},
128-
},
129-
StatusCode: 404,
126+
Header: http.Header{},
127+
StatusCode: 404,
130128
}
129+
response.Header.Add(actions.HeaderActionsActivityID, "activity-id")
131130

132131
err := actions.ParseActionsErrorFromResponse(response)
133132
require.Error(t, err)
134-
assert.Equal(t, err.(*actions.ActionsError).ActivityID, "activity-id")
135-
assert.Equal(t, err.(*actions.ActionsError).StatusCode, 404)
136-
assert.Equal(t, err.(*actions.ActionsError).Err.Error(), "unknown exception")
133+
assert.Equal(t, "activity-id", err.(*actions.ActionsError).ActivityID)
134+
assert.Equal(t, 404, err.(*actions.ActionsError).StatusCode)
135+
assert.Equal(t, "unknown exception", err.(*actions.ActionsError).Err.Error())
137136
})
138137

139138
t.Run("contains text plain error", func(t *testing.T) {
140139
errorMessage := "example error message"
141140
response := &http.Response{
142141
ContentLength: int64(len(errorMessage)),
143-
Header: http.Header{
144-
actions.HeaderActionsActivityID: []string{"activity-id"},
145-
"Content-Type": []string{"text/plain"},
146-
},
147-
StatusCode: 404,
148-
Body: io.NopCloser(strings.NewReader(errorMessage)),
142+
StatusCode: 404,
143+
Header: http.Header{},
144+
Body: io.NopCloser(strings.NewReader(errorMessage)),
149145
}
146+
response.Header.Add(actions.HeaderActionsActivityID, "activity-id")
147+
response.Header.Add("Content-Type", "text/plain")
150148

151149
err := actions.ParseActionsErrorFromResponse(response)
152150
require.Error(t, err)
153151
var actionsError *actions.ActionsError
154-
assert.ErrorAs(t, err, &actionsError)
155-
assert.Equal(t, actionsError.ActivityID, "activity-id")
156-
assert.Equal(t, actionsError.StatusCode, 404)
157-
assert.Equal(t, actionsError.Err.Error(), errorMessage)
152+
require.ErrorAs(t, err, &actionsError)
153+
assert.Equal(t, "activity-id", actionsError.ActivityID)
154+
assert.Equal(t, 404, actionsError.StatusCode)
155+
assert.Equal(t, errorMessage, actionsError.Err.Error())
158156
})
159157

160158
t.Run("contains json error", func(t *testing.T) {
161159
errorMessage := `{"typeName":"exception-name","message":"example error message"}`
162160
response := &http.Response{
163161
ContentLength: int64(len(errorMessage)),
164-
Header: http.Header{
165-
actions.HeaderActionsActivityID: []string{"activity-id"},
166-
"Content-Type": []string{"application/json"},
167-
},
168-
StatusCode: 404,
169-
Body: io.NopCloser(strings.NewReader(errorMessage)),
162+
Header: http.Header{},
163+
StatusCode: 404,
164+
Body: io.NopCloser(strings.NewReader(errorMessage)),
170165
}
166+
response.Header.Add(actions.HeaderActionsActivityID, "activity-id")
167+
response.Header.Add("Content-Type", "application/json")
171168

172169
err := actions.ParseActionsErrorFromResponse(response)
173170
require.Error(t, err)
174171
var actionsError *actions.ActionsError
175-
assert.ErrorAs(t, err, &actionsError)
176-
assert.Equal(t, actionsError.ActivityID, "activity-id")
177-
assert.Equal(t, actionsError.StatusCode, 404)
172+
require.ErrorAs(t, err, &actionsError)
173+
assert.Equal(t, "activity-id", actionsError.ActivityID)
174+
assert.Equal(t, 404, actionsError.StatusCode)
178175

179176
inner, ok := actionsError.Err.(*actions.ActionsExceptionError)
180177
require.True(t, ok)
181-
assert.Equal(t, inner.ExceptionName, "exception-name")
182-
assert.Equal(t, inner.Message, "example error message")
178+
assert.Equal(t, "exception-name", inner.ExceptionName)
179+
assert.Equal(t, "example error message", inner.Message)
183180
})
184181

185182
t.Run("wrapped exception error", func(t *testing.T) {
186183
errorMessage := `{"typeName":"exception-name","message":"example error message"}`
187184
response := &http.Response{
188185
ContentLength: int64(len(errorMessage)),
189-
Header: http.Header{
190-
actions.HeaderActionsActivityID: []string{"activity-id"},
191-
"Content-Type": []string{"application/json"},
192-
},
193-
StatusCode: 404,
194-
Body: io.NopCloser(strings.NewReader(errorMessage)),
186+
Header: http.Header{},
187+
StatusCode: 404,
188+
Body: io.NopCloser(strings.NewReader(errorMessage)),
195189
}
190+
response.Header.Add(actions.HeaderActionsActivityID, "activity-id")
191+
response.Header.Add("Content-Type", "application/json")
196192

197193
err := actions.ParseActionsErrorFromResponse(response)
198194
require.Error(t, err)
199195

200196
var actionsExceptionError *actions.ActionsExceptionError
201-
assert.ErrorAs(t, err, &actionsExceptionError)
197+
require.ErrorAs(t, err, &actionsExceptionError)
202198

203-
assert.Equal(t, actionsExceptionError.ExceptionName, "exception-name")
204-
assert.Equal(t, actionsExceptionError.Message, "example error message")
199+
assert.Equal(t, "exception-name", actionsExceptionError.ExceptionName)
200+
assert.Equal(t, "example error message", actionsExceptionError.Message)
205201
})
206202
}

0 commit comments

Comments
 (0)