37 lines
1.4 KiB
Go
37 lines
1.4 KiB
Go
package client
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
var urlTests = []struct {
|
|
base string
|
|
section string
|
|
command string
|
|
out string
|
|
}{
|
|
{"supervisor", "section", "command", "http://supervisor/section/command"},
|
|
{"supervisor:80", "section", "command", "http://supervisor:80/section/command"},
|
|
{"supervisor.example.org:8080", "section", "command", "http://supervisor.example.org:8080/section/command"},
|
|
{"https://supervisor", "section", "command", "https://supervisor/section/command"},
|
|
{"https://supervisor:8080", "section", "command", "https://supervisor:8080/section/command"},
|
|
{"https://supervisor", "section", "command", "https://supervisor/section/command"},
|
|
{"https://supervisor:8080", "section", "command", "https://supervisor:8080/section/command"},
|
|
{"supervisor", "section", "", "http://supervisor/section"},
|
|
{"supervisor", "section/../othersection", "", "http://supervisor/othersection"},
|
|
{"supervisor/api/", "section", "command", "http://supervisor/api/section/command"},
|
|
{"supervisor/api/", "section", "{slug}/command", "http://supervisor/api/section/{slug}/command"},
|
|
}
|
|
|
|
func TestURLHelper(t *testing.T) {
|
|
for _, tt := range urlTests {
|
|
t.Run(fmt.Sprintf("[%s][%s][%s]", tt.base, tt.section, tt.command), func(t *testing.T) {
|
|
s, _ := URLHelper(tt.base, tt.section, tt.command)
|
|
if s != tt.out {
|
|
t.Errorf("got %q, want %q", s, tt.out)
|
|
}
|
|
})
|
|
}
|
|
}
|