Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for local files and Github base URLs
  • Loading branch information
muesli committed Mar 31, 2021
commit f76a1d91ac66529304b9dc4e0d1011910f1c07d6
17 changes: 17 additions & 0 deletions ansi/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ func TestUrlResolver(t *testing.T) {
assertEqual(t, resolveURL(host+"/a/b/", host2+"/c/d"), host2+"/c/d")
}

func TestUrlResolverForLocalFiles(t *testing.T) {
base := "/home/foobar/project/"
assertEqual(t,
resolveURL(base, "/assets/logo.png"),
"/home/foobar/project/assets/logo.png")
}

func TestUrlResolverForGitforgeUsage(t *testing.T) {
// in git-forges like github & gitea, URLs are often written relative,
// where the repo-url (`gitea.com/gitea/tea`) treated as reference.
Expand All @@ -206,6 +213,16 @@ func TestUrlResolverForGitforgeUsage(t *testing.T) {
assertEqual(t,
resolveURL(base, "src/branch/master/modules/print/markdown.go"),
"https://gitea.com/gitea/tea/src/branch/master/modules/print/markdown.go")

base = "https://raw.githubusercontent.com/foo/bar/master/"
assertEqual(t,
resolveURL(base, "/assets/logo.png"),
"https://raw.githubusercontent.com/foo/bar/master/assets/logo.png")

base = "https://raw.githubusercontent.com/foo/bar/master/some/dir/"
assertEqual(t,
resolveURL(base, "/assets/logo.png"),
"https://raw.githubusercontent.com/foo/bar/master/assets/logo.png")
}

func assertEqual(t *testing.T, value interface{}, expected interface{}) {
Expand Down