Allow the TestController to be referenced externally (#65)
* Allow the TestController to be used outside of our go module. * Adding package comment explaining this testing package is for internal use only.
This commit is contained in:
1 parent
3157fd0e5f
commit
95d29c3e95
3 files changed
+114
-3
No files matched your search
@@ -19,6 +19,7 @@ type TestController struct {
|
||||
b *base.Server
|
||||
c *Controller
|
||||
t *testing.T
|
||||
addr string // The address the Controller API is listening on
|
||||
client *api.Client
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
@@ -41,7 +42,10 @@ func (tc *TestController) Cancel() {
|
||||
tc.cancel()
|
||||
}
|
||||
|
||||
func (tc *TestController) buildClient() {
|
||||
func (tc *TestController) ApiAddress() string {
|
||||
if tc.addr != "" {
|
||||
return tc.addr
|
||||
}
|
||||
var apiLn *base.ServerListener
|
||||
for _, listener := range tc.b.Listeners {
|
||||
if listener.Config.Purpose[0] == "api" {
|
||||
@@ -57,12 +61,16 @@ func (tc *TestController) buildClient() {
|
||||
if !ok {
|
||||
tc.t.Fatal("could not parse address as a TCP addr")
|
||||
}
|
||||
addr := fmt.Sprintf("http://%s:%d", tcpAddr.IP.String(), tcpAddr.Port)
|
||||
tc.addr = fmt.Sprintf("http://%s:%d", tcpAddr.IP.String(), tcpAddr.Port)
|
||||
return tc.addr
|
||||
}
|
||||
|
||||
func (tc *TestController) buildClient() {
|
||||
client, err := api.NewClient(nil)
|
||||
if err != nil {
|
||||
tc.t.Fatal(fmt.Errorf("error creating client: %w", err))
|
||||
}
|
||||
if err := client.SetAddr(addr); err != nil {
|
||||
if err := client.SetAddr(tc.ApiAddress()); err != nil {
|
||||
tc.t.Fatal(fmt.Errorf("error setting client address: %w", err))
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user