From 540269880ffa34f64a2eca8c70b61da120b59a1c Mon Sep 17 00:00:00 2001 From: Nikola Jokic Date: Thu, 27 Nov 2025 15:31:57 +0100 Subject: [PATCH] Typo in test name caused test to not execute (#4330) --- github/actions/config_test.go | 14 ++++++- github/actions/errors_test.go | 72 +++++++++++++++++------------------ 2 files changed, 47 insertions(+), 39 deletions(-) diff --git a/github/actions/config_test.go b/github/actions/config_test.go index 99b6459b..dc3aacbd 100644 --- a/github/actions/config_test.go +++ b/github/actions/config_test.go @@ -15,10 +15,12 @@ import ( func TestGitHubConfig(t *testing.T) { t.Run("when given a valid URL", func(t *testing.T) { tests := []struct { + name string configURL string expected *actions.GitHubConfig }{ { + name: "repository URL", configURL: "https://github.com/org/repo", expected: &actions.GitHubConfig{ Scope: actions.GitHubScopeRepository, @@ -29,6 +31,7 @@ func TestGitHubConfig(t *testing.T) { }, }, { + name: "repository URL with trailing slash", configURL: "https://github.com/org/repo/", expected: &actions.GitHubConfig{ Scope: actions.GitHubScopeRepository, @@ -39,6 +42,7 @@ func TestGitHubConfig(t *testing.T) { }, }, { + name: "organization URL", configURL: "https://github.com/org", expected: &actions.GitHubConfig{ Scope: actions.GitHubScopeOrganization, @@ -49,6 +53,7 @@ func TestGitHubConfig(t *testing.T) { }, }, { + name: "enterprise URL", configURL: "https://github.com/enterprises/my-enterprise", expected: &actions.GitHubConfig{ Scope: actions.GitHubScopeEnterprise, @@ -59,6 +64,7 @@ func TestGitHubConfig(t *testing.T) { }, }, { + name: "enterprise URL with trailing slash", configURL: "https://github.com/enterprises/my-enterprise/", expected: &actions.GitHubConfig{ Scope: actions.GitHubScopeEnterprise, @@ -69,6 +75,7 @@ func TestGitHubConfig(t *testing.T) { }, }, { + name: "organization URL with www", configURL: "https://www.github.com/org", expected: &actions.GitHubConfig{ Scope: actions.GitHubScopeOrganization, @@ -79,6 +86,7 @@ func TestGitHubConfig(t *testing.T) { }, }, { + name: "organization URL with www and trailing slash", configURL: "https://www.github.com/org/", expected: &actions.GitHubConfig{ Scope: actions.GitHubScopeOrganization, @@ -89,6 +97,7 @@ func TestGitHubConfig(t *testing.T) { }, }, { + name: "github local URL", configURL: "https://github.localhost/org", expected: &actions.GitHubConfig{ Scope: actions.GitHubScopeOrganization, @@ -99,6 +108,7 @@ func TestGitHubConfig(t *testing.T) { }, }, { + name: "github local org URL", configURL: "https://my-ghes.com/org", expected: &actions.GitHubConfig{ Scope: actions.GitHubScopeOrganization, @@ -109,6 +119,7 @@ func TestGitHubConfig(t *testing.T) { }, }, { + name: "github local URL with trailing slash", configURL: "https://my-ghes.com/org/", expected: &actions.GitHubConfig{ Scope: actions.GitHubScopeOrganization, @@ -119,6 +130,7 @@ func TestGitHubConfig(t *testing.T) { }, }, { + name: "github local URL with ghe.com", configURL: "https://my-ghes.ghe.com/org/", expected: &actions.GitHubConfig{ Scope: actions.GitHubScopeOrganization, @@ -131,7 +143,7 @@ func TestGitHubConfig(t *testing.T) { } for _, test := range tests { - t.Run(test.configURL, func(t *testing.T) { + t.Run(test.name, func(t *testing.T) { parsedURL, err := url.Parse(strings.Trim(test.configURL, "/")) require.NoError(t, err) test.expected.ConfigURL = parsedURL diff --git a/github/actions/errors_test.go b/github/actions/errors_test.go index 46310ba1..034ff2a0 100644 --- a/github/actions/errors_test.go +++ b/github/actions/errors_test.go @@ -119,88 +119,84 @@ func TestGitHubAPIError(t *testing.T) { }) } -func ParseActionsErrorFromResponse(t *testing.T) { +func TestParseActionsErrorFromResponse(t *testing.T) { t.Run("empty content length", func(t *testing.T) { response := &http.Response{ ContentLength: 0, - Header: http.Header{ - actions.HeaderActionsActivityID: []string{"activity-id"}, - }, - StatusCode: 404, + Header: http.Header{}, + StatusCode: 404, } + response.Header.Add(actions.HeaderActionsActivityID, "activity-id") err := actions.ParseActionsErrorFromResponse(response) require.Error(t, err) - assert.Equal(t, err.(*actions.ActionsError).ActivityID, "activity-id") - assert.Equal(t, err.(*actions.ActionsError).StatusCode, 404) - assert.Equal(t, err.(*actions.ActionsError).Err.Error(), "unknown exception") + assert.Equal(t, "activity-id", err.(*actions.ActionsError).ActivityID) + assert.Equal(t, 404, err.(*actions.ActionsError).StatusCode) + assert.Equal(t, "unknown exception", err.(*actions.ActionsError).Err.Error()) }) t.Run("contains text plain error", func(t *testing.T) { errorMessage := "example error message" response := &http.Response{ ContentLength: int64(len(errorMessage)), - Header: http.Header{ - actions.HeaderActionsActivityID: []string{"activity-id"}, - "Content-Type": []string{"text/plain"}, - }, - StatusCode: 404, - Body: io.NopCloser(strings.NewReader(errorMessage)), + StatusCode: 404, + Header: http.Header{}, + Body: io.NopCloser(strings.NewReader(errorMessage)), } + response.Header.Add(actions.HeaderActionsActivityID, "activity-id") + response.Header.Add("Content-Type", "text/plain") err := actions.ParseActionsErrorFromResponse(response) require.Error(t, err) var actionsError *actions.ActionsError - assert.ErrorAs(t, err, &actionsError) - assert.Equal(t, actionsError.ActivityID, "activity-id") - assert.Equal(t, actionsError.StatusCode, 404) - assert.Equal(t, actionsError.Err.Error(), errorMessage) + require.ErrorAs(t, err, &actionsError) + assert.Equal(t, "activity-id", actionsError.ActivityID) + assert.Equal(t, 404, actionsError.StatusCode) + assert.Equal(t, errorMessage, actionsError.Err.Error()) }) t.Run("contains json error", func(t *testing.T) { errorMessage := `{"typeName":"exception-name","message":"example error message"}` response := &http.Response{ ContentLength: int64(len(errorMessage)), - Header: http.Header{ - actions.HeaderActionsActivityID: []string{"activity-id"}, - "Content-Type": []string{"application/json"}, - }, - StatusCode: 404, - Body: io.NopCloser(strings.NewReader(errorMessage)), + Header: http.Header{}, + StatusCode: 404, + Body: io.NopCloser(strings.NewReader(errorMessage)), } + response.Header.Add(actions.HeaderActionsActivityID, "activity-id") + response.Header.Add("Content-Type", "application/json") err := actions.ParseActionsErrorFromResponse(response) require.Error(t, err) var actionsError *actions.ActionsError - assert.ErrorAs(t, err, &actionsError) - assert.Equal(t, actionsError.ActivityID, "activity-id") - assert.Equal(t, actionsError.StatusCode, 404) + require.ErrorAs(t, err, &actionsError) + assert.Equal(t, "activity-id", actionsError.ActivityID) + assert.Equal(t, 404, actionsError.StatusCode) inner, ok := actionsError.Err.(*actions.ActionsExceptionError) require.True(t, ok) - assert.Equal(t, inner.ExceptionName, "exception-name") - assert.Equal(t, inner.Message, "example error message") + assert.Equal(t, "exception-name", inner.ExceptionName) + assert.Equal(t, "example error message", inner.Message) }) t.Run("wrapped exception error", func(t *testing.T) { errorMessage := `{"typeName":"exception-name","message":"example error message"}` response := &http.Response{ ContentLength: int64(len(errorMessage)), - Header: http.Header{ - actions.HeaderActionsActivityID: []string{"activity-id"}, - "Content-Type": []string{"application/json"}, - }, - StatusCode: 404, - Body: io.NopCloser(strings.NewReader(errorMessage)), + Header: http.Header{}, + StatusCode: 404, + Body: io.NopCloser(strings.NewReader(errorMessage)), } + response.Header.Add(actions.HeaderActionsActivityID, "activity-id") + response.Header.Add("Content-Type", "application/json") err := actions.ParseActionsErrorFromResponse(response) require.Error(t, err) var actionsExceptionError *actions.ActionsExceptionError - assert.ErrorAs(t, err, &actionsExceptionError) + require.ErrorAs(t, err, &actionsExceptionError) - assert.Equal(t, actionsExceptionError.ExceptionName, "exception-name") - assert.Equal(t, actionsExceptionError.Message, "example error message") + assert.Equal(t, "exception-name", actionsExceptionError.ExceptionName) + assert.Equal(t, "example error message", actionsExceptionError.Message) }) }