1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-06 17:41:00 +00:00

Consider base path when generating third-party services API endpoint

This commit is contained in:
Frédéric Guillot 2023-08-12 19:01:22 -07:00
parent fb8737e330
commit 13d9d86acd
9 changed files with 87 additions and 60 deletions

View file

@ -89,3 +89,34 @@ func TestDomain(t *testing.T) {
}
}
}
func TestJoinBaseURLAndPath(t *testing.T) {
type args struct {
baseURL string
path string
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{"empty base url", args{"", "/api/bookmarks/"}, "", true},
{"empty path", args{"https://example.com", ""}, "", true},
{"invalid base url", args{"incorrect url", ""}, "", true},
{"valid", args{"https://example.com", "/api/bookmarks/"}, "https://example.com/api/bookmarks/", false},
{"valid", args{"https://example.com/subfolder", "/api/bookmarks/"}, "https://example.com/subfolder/api/bookmarks/", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := JoinBaseURLAndPath(tt.args.baseURL, tt.args.path)
if (err != nil) != tt.wantErr {
t.Errorf("JoinBaseURLAndPath error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("JoinBaseURLAndPath = %v, want %v", got, tt.want)
}
})
}
}