-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6421 from hashicorp/b-acl-bootstrap-codes
api: acl bootstrap errors aren't 500
- Loading branch information
Showing
6 changed files
with
110 additions
and
19 deletions.
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
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,49 @@ | ||
package structs | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRPCCodedErrors(t *testing.T) { | ||
cases := []struct { | ||
err error | ||
code int | ||
message string | ||
}{ | ||
{ | ||
NewErrRPCCoded(400, "a test message,here"), | ||
400, | ||
"a test message,here", | ||
}, | ||
{ | ||
NewErrRPCCodedf(500, "a test message,here %s %s", "and,here%s", "second"), | ||
500, | ||
"a test message,here and,here%s second", | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.err.Error(), func(t *testing.T) { | ||
code, msg, ok := CodeFromRPCCodedErr(c.err) | ||
assert.True(t, ok) | ||
assert.Equal(t, c.code, code) | ||
assert.Equal(t, c.message, msg) | ||
}) | ||
} | ||
|
||
negativeCases := []string{ | ||
"random error", | ||
errRPCCodedErrorPrefix, | ||
errRPCCodedErrorPrefix + "123", | ||
errRPCCodedErrorPrefix + "qwer,asdf", | ||
} | ||
for _, c := range negativeCases { | ||
t.Run(c, func(t *testing.T) { | ||
_, _, ok := CodeFromRPCCodedErr(errors.New(c)) | ||
assert.False(t, ok) | ||
}) | ||
} | ||
} |