Files
threshold/api/client_test.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

90 lines
2.4 KiB
Go
Raw Normal View History

2023-02-02 17:15:17 -08:00
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
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 {
2023-06-11 20:40:47 -04:00
name string
input string
address string
socketAddr string
2020-05-04 10:58:03 -04:00
}
tests := []test{
{
2023-06-11 20:40:47 -04:00
name: "bare",
input: "http://127.0.0.1:9200",
address: "http://127.0.0.1:9200",
2020-05-04 10:58:03 -04:00
},
{
2023-06-11 20:40:47 -04:00
name: "bare with version",
input: "http://127.0.0.1:9200/v1",
address: "http://127.0.0.1:9200",
2020-05-04 10:58:03 -04:00
},
{
2023-06-11 20:40:47 -04:00
name: "bare with version and trailing slash",
input: "http://127.0.0.1:9200/v1/",
address: "http://127.0.0.1:9200",
2020-05-04 10:58:03 -04:00
},
{
2023-06-11 20:40:47 -04:00
name: "valid top level scope",
input: "http://127.0.0.1:9200/v1/scopes",
address: "http://127.0.0.1:9200",
2020-05-04 10:58:03 -04:00
},
{
2023-06-11 20:40:47 -04:00
name: "valid scope",
input: "http://127.0.0.1:9200/v1/scopes/scopeid",
address: "http://127.0.0.1:9200",
2020-05-04 10:58:03 -04:00
},
{
2023-06-11 20:40:47 -04:00
name: "longer path project",
input: "http://127.0.0.1:9200/v1/auth-methods",
address: "http://127.0.0.1:9200",
2020-05-04 10:58:03 -04:00
},
{
2023-06-11 20:40:47 -04:00
name: "valid project",
input: "http://127.0.0.1:9200/my-install",
address: "http://127.0.0.1:9200/my-install",
2020-05-04 10:58:03 -04:00
},
{
2023-06-11 20:40:47 -04:00
name: "valid project path containing v1",
input: "http://127.0.0.1:9200/randomPathHasv1InIt",
address: "http://127.0.0.1:9200/randomPathHasv1InIt",
},
{
name: "unix socket with linux pathing",
input: "unix:///home/username/.boundary/socketdir/boundary.sock",
address: "unix:///home/username/.boundary/socketdir/boundary.sock",
socketAddr: "/home/username/.boundary/socketdir/boundary.sock",
},
{
name: "unix socket with weird linux pathing",
input: "unix:///home/username/.boundary/something/../socketdir/boundary.sock",
address: "unix:///home/username/.boundary/socketdir/boundary.sock",
socketAddr: "/home/username/.boundary/socketdir/boundary.sock",
},
{
name: "unix socket with windows pathing",
input: "unix://C:\\Users\\Admin\\AppData\\boundary.sock",
address: "unix://C:\\Users\\Admin\\AppData\\boundary.sock",
socketAddr: "C:\\Users\\Admin\\AppData\\boundary.sock",
},
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)
2023-06-11 20:40:47 -04:00
assert.NoError(t, err)
2020-05-08 12:03:56 -04:00
assert.Equal(t, v.address, c.Addr)
2023-06-11 20:40:47 -04:00
assert.Equal(t, v.socketAddr, c.socketAddr)
2020-05-04 10:58:03 -04:00
})
}
}