-
Notifications
You must be signed in to change notification settings - Fork 12
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 #29 from antavelos/manage-rel-url
Write fix to handle relative URL
- Loading branch information
Showing
2 changed files
with
62 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,44 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/antavelos/terminews/db" | ||
"testing" | ||
) | ||
|
||
func TestGetContentURL(t *testing.T) { | ||
type test struct { | ||
site db.Site | ||
url string | ||
expected string | ||
} | ||
|
||
tests := []test{ | ||
{ | ||
site: db.Site{Url: "https://blog.example.org/index.xml"}, | ||
url: "/2021/02/a-blog-post", | ||
expected: "https://blog.example.org/2021/02/a-blog-post", | ||
}, | ||
{ | ||
site: db.Site{Url: "http://blog.example.org/index.xml"}, | ||
url: "2021/02/a-blog-post", | ||
expected: "http://blog.example.org/2021/02/a-blog-post", | ||
}, | ||
{ | ||
site: db.Site{Url: "https://blog.example.org/feed.rss"}, | ||
url: "https://blog.example.org/super-blog-post", | ||
expected: "https://blog.example.org/super-blog-post", | ||
}, | ||
{ | ||
site: db.Site{Url: "http://blog.example.org/feed.rss"}, | ||
url: "http://blog.example.org/super-blog-post", | ||
expected: "http://blog.example.org/super-blog-post", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
value := getContentURL(test.site, test.url) | ||
if value != test.expected { | ||
t.Errorf("got: %s want: %s", value, test.expected) | ||
} | ||
} | ||
} |