-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refine error message when validating extension name (#845)
Signed-off-by: jack.wong <jack.wong@bytedance.com> Co-authored-by: jack.wong <jack.wong@bytedance.com>
- Loading branch information
1 parent
4cbabea
commit 79ffd85
Showing
2 changed files
with
41 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Copyright 2021 The CloudEvents Authors | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package event | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
) | ||
|
||
func TestEvent_validateExtensionName(t *testing.T) { | ||
testCases := map[string]struct { | ||
key string | ||
want error | ||
}{ | ||
"empty key": { | ||
key: "", | ||
want: errors.New("bad key, CloudEvents attribute names MUST NOT be empty"), | ||
}, | ||
"invalid character": { | ||
key: "invalid_key", | ||
want: errors.New("bad key, CloudEvents attribute names MUST consist of lower-case letters ('a' to 'z'), upper-case letters ('A' to 'Z') or digits ('0' to '9') from the ASCII character set"), | ||
}, | ||
"valid key": { | ||
key: "validkey123", | ||
want: nil, | ||
}, | ||
} | ||
|
||
for name, tc := range testCases { | ||
t.Run(name, func(t *testing.T) { | ||
err := validateExtensionName(tc.key) | ||
if err != nil && err.Error() != tc.want.Error() || err == nil && tc.want != nil { | ||
t.Errorf("unexpected error, expected: %v, actual: %v", tc.want, err) | ||
} | ||
}) | ||
} | ||
} |