35 lines
689 B
Go
35 lines
689 B
Go
package util_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/BeatGlow/beatglow/internal/util"
|
|
)
|
|
|
|
func TestMakeAddr(t *testing.T) {
|
|
var (
|
|
testDefault = "localhost:80"
|
|
testCases = []struct {
|
|
Test string
|
|
Want string
|
|
}{
|
|
{"", testDefault},
|
|
{"81", "localhost:81"},
|
|
{"1.1.1.1", "1.1.1.1:80"},
|
|
{"foo", "foo:80"},
|
|
{":https", "localhost:https"},
|
|
{"1.2.3.4:", "1.2.3.4:80"},
|
|
}
|
|
)
|
|
for _, test := range testCases {
|
|
t.Run(test.Test, func(it *testing.T) {
|
|
v := util.MakeAddr(test.Test, testDefault)
|
|
if v != test.Want {
|
|
it.Fatalf("expected %q to return %q, got %q", test.Test, test.Want, v)
|
|
} else {
|
|
it.Logf("%q resolved to %q", test.Test, v)
|
|
}
|
|
})
|
|
}
|
|
}
|