Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: webhook URL parse Signed-off-by: jolheiser <john.olheiser@gmail.com> * review: update func name Co-authored-by: ToπSenpai <15636011+TopiSenpai@users.noreply.github.com> * review: fix tests Co-authored-by: ToπSenpai <15636011+TopiSenpai@users.noreply.github.com> Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: ToπSenpai <15636011+TopiSenpai@users.noreply.github.com>
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package webhook | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/disgoorg/snowflake/v2" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestParseURL(t *testing.T) { | ||
tt := []struct { | ||
URL string | ||
ID snowflake.ID | ||
Token string | ||
Err bool | ||
}{ | ||
{ | ||
URL: "https://discord.com/api/webhooks/123456789123456789/foo", | ||
ID: snowflake.ID(123456789123456789), | ||
Token: "foo", | ||
}, | ||
{ | ||
URL: "https://discord.com/api/webhooks/123456789123456789/foo/", | ||
ID: snowflake.ID(123456789123456789), | ||
Token: "foo", | ||
}, | ||
{ | ||
URL: "https://canary.discord.com/api/webhooks/123456789123456789/foo", | ||
ID: snowflake.ID(123456789123456789), | ||
Token: "foo", | ||
}, | ||
{ | ||
URL: "foobarbaz", | ||
Err: true, | ||
}, | ||
{ | ||
URL: "https://discord.com/api/webhooks/123456789123456789/foo?wait=10", | ||
ID: snowflake.ID(123456789123456789), | ||
Token: "foo", | ||
}, | ||
} | ||
|
||
for _, tc := range tt { | ||
t.Run(tc.URL, func(t *testing.T) { | ||
assert := require.New(t) | ||
|
||
c, err := NewWithURL(tc.URL) | ||
if tc.Err { | ||
assert.Error(err, "URL parsing should have resulted in an error") | ||
return | ||
} | ||
assert.Equal(tc.ID, c.ID(), "URL ID should match") | ||
assert.Equal(tc.Token, c.Token(), "URL token should match") | ||
}) | ||
} | ||
} |