Skip to content

Commit

Permalink
Add some pkg/utils/url.go tests (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada authored Sep 10, 2023
1 parent 1cab562 commit 438b0c7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Fix: We do some more YouTube video ID parsing to ensure broken links (such as `youtube.com/watch?v=foobar?feature=share`) still return the actual video ID, since this is how the browser operates. (#488)
- Dev: Document the `log-development` setting. (#491)
- Dev: Document the `log-level` setting. (#490)
- Dev: Add some `pkg/utils/url.go` tests. (#525)

## 2.0.2

Expand Down
47 changes: 47 additions & 0 deletions pkg/utils/url_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package utils

import (
"net/url"
"testing"

qt "github.com/frankban/quicktest"
)

func makeUrl(rawurl string) *url.URL {
u, err := url.Parse(rawurl)
if err != nil {
panic(err)
}
return u
}

func TestIsSubdomainOf(t *testing.T) {
c := qt.New(t)
type tTest struct {
u *url.URL

parent string
expected bool
}

tests := []tTest{
{
u: makeUrl("https://www.youtube.com/watch?v=aTts9CnsAv8"),
parent: "youtube.com",
expected: true,
},
{
u: makeUrl("https://www.twitter.com/forsen"),
parent: "youtube.com",
expected: false,
},
}

for _, test := range tests {
c.Run(test.u.String(), func(c *qt.C) {
actual := IsSubdomainOf(test.u, test.parent)
c.Assert(actual, qt.Equals, test.expected)
})
}

}

0 comments on commit 438b0c7

Please sign in to comment.