-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix jira error parsing #39204
Merged
Merged
fix jira error parsing #39204
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9789b08
fix jira error parsing
hugoShaka aa1a3ef
lint
hugoShaka 34eed06
Address zac's feedback: imprement error + rename structs
hugoShaka 9b66a30
Update integrations/access/jira/types_test.go
hugoShaka 8550d41
Apply suggestions from code review
hugoShaka 5a248e9
address feedback
hugoShaka c2a5874
Update integrations/access/jira/types.go
hugoShaka fa573f0
address feedback + fix tests
hugoShaka 4ef93de
fix unmarshal
hugoShaka 249c239
Merge branch 'master' into hugo/log-jira-error
hugoShaka 9d62d5f
Merge branch 'master' into hugo/log-jira-error
hugoShaka File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Teleport | ||
* Copyright (C) 2023 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package jira | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestErrorResultUnmarshal(t *testing.T) { | ||
t.Parallel() | ||
tests := []struct { | ||
name string | ||
input string | ||
expectedOutput ErrorResult | ||
assertErr require.ErrorAssertionFunc | ||
}{ | ||
{ | ||
name: "new error", | ||
input: `{"errorMessages":[], "errors": {"project": "project is required"}}`, | ||
expectedOutput: ErrorResult{ | ||
Details: ErrorDetails{Errors: map[string]string{"project": "project is required"}}, | ||
}, | ||
assertErr: require.NoError, | ||
}, | ||
{ | ||
name: "legacy error", | ||
input: `{"errorMessages":["foo"],"errors":["bar", "baz"]}`, | ||
expectedOutput: ErrorResult{ | ||
ErrorMessages: []string{"foo"}, | ||
Details: ErrorDetails{LegacyErrors: []string{"bar", "baz"}}, | ||
}, | ||
assertErr: require.NoError, | ||
}, | ||
{ | ||
name: "empty error", | ||
input: `{"errorMessages":["There was an error parsing JSON. Check that your request body is valid."]}`, | ||
expectedOutput: ErrorResult{ | ||
ErrorMessages: []string{"There was an error parsing JSON. Check that your request body is valid."}, | ||
}, | ||
assertErr: require.NoError, | ||
}, | ||
{ | ||
name: "malformed error", | ||
input: `{"errorMessages":["Foo"],"errors":"This is a single string"}`, | ||
expectedOutput: ErrorResult{ErrorMessages: []string{"Foo"}}, | ||
assertErr: func(t require.TestingT, err error, i ...interface{}) { | ||
require.ErrorContains(t, err, "This is a single string") | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tt := tt | ||
t.Parallel() | ||
data := []byte(tt.input) | ||
var result ErrorResult | ||
tt.assertErr(t, json.Unmarshal(data, &result)) | ||
diff := cmp.Diff(tt.expectedOutput, result, cmpopts.EquateEmpty()) | ||
require.Empty(t, diff) | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the error is >399 (
resp.IsError()==true
), does it make sense to return nil if no error is defined?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be unreachable, but I'm quite afraid of breaking something 😓 . It feels like this was added on purpose. Maybe for the "request cancelled" kind of issues.