Files
threshold/api/client_test.go
T

78 lines
1.3 KiB
Go
Raw Normal View History

2020-05-04 10:58:03 -04:00
package api
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestConfigSetAddress(t *testing.T) {
type test struct {
name string
input string
address string
err string
}
tests := []test{
{
"bare",
"http://127.0.0.1:9200",
"http://127.0.0.1:9200",
"",
},
{
"bare with version",
"http://127.0.0.1:9200/v1",
"http://127.0.0.1:9200",
"",
},
{
"bare with version and trailing slash",
"http://127.0.0.1:9200/v1/",
"http://127.0.0.1:9200",
"",
},
{
2020-07-22 00:14:28 -04:00
"valid top level scope",
"http://127.0.0.1:9200/v1/scopes",
2020-05-04 10:58:03 -04:00
"http://127.0.0.1:9200",
"",
},
{
2020-07-22 00:14:28 -04:00
"valid scope",
"http://127.0.0.1:9200/v1/scopes/scopeid",
2020-05-04 10:58:03 -04:00
"http://127.0.0.1:9200",
"",
},
{
2020-07-22 00:14:28 -04:00
"longer path project",
"http://127.0.0.1:9200/v1/auth-methods",
2020-05-04 10:58:03 -04:00
"http://127.0.0.1:9200",
"",
},
{
"valid project",
2020-07-22 00:14:28 -04:00
"http://127.0.0.1:9200/my-install",
"http://127.0.0.1:9200/my-install",
2020-05-04 10:58:03 -04:00
"",
},
{
"valid project path containing v1",
"http://127.0.0.1:9200/randomPathHasv1InIt",
"http://127.0.0.1:9200/randomPathHasv1InIt",
"",
},
2020-05-04 10:58:03 -04:00
}
for _, v := range tests {
t.Run(v.name, func(t *testing.T) {
var c Config
2020-05-08 12:03:56 -04:00
err := c.setAddr(v.input)
2020-05-04 10:58:03 -04:00
if err != nil {
assert.Equal(t, v.err, err.Error())
}
2020-05-08 12:03:56 -04:00
assert.Equal(t, v.address, c.Addr)
2020-05-04 10:58:03 -04:00
})
}
}