2023-06-06 17:03:30 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
"testing"
|
|
|
|
|
2024-02-15 05:46:47 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/testing/require"
|
2023-06-06 17:03:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestValidHostname(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
name string
|
|
|
|
hostArg string
|
|
|
|
path string
|
|
|
|
joined string
|
|
|
|
err error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "hostname without port",
|
|
|
|
hostArg: "mydomain.org",
|
|
|
|
err: ErrMalformedHostname,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, c := range cases {
|
|
|
|
t.Run(c.name, func(t *testing.T) {
|
|
|
|
cl, err := NewClient(c.hostArg)
|
|
|
|
if c.err != nil {
|
|
|
|
require.ErrorIs(t, err, c.err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, c.joined, cl.BaseURL().ResolveReference(&url.URL{Path: c.path}).String())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWithAuthenticationToken(t *testing.T) {
|
|
|
|
cl, err := NewClient("https://www.offchainlabs.com:3500", WithAuthenticationToken("my token"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, cl.Token(), "my token")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBaseURL(t *testing.T) {
|
|
|
|
cl, err := NewClient("https://www.offchainlabs.com:3500")
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, "www.offchainlabs.com", cl.BaseURL().Hostname())
|
|
|
|
require.Equal(t, "3500", cl.BaseURL().Port())
|
|
|
|
}
|