diff --git a/go.mod b/go.mod index a4c9c3b..35b0391 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/RTradeLtd/go-libp2p-tls v0.2.3 github.com/gogo/protobuf v1.3.1 github.com/golang/protobuf v1.3.5 // indirect + github.com/google/go-cmp v0.3.1 // indirect github.com/ipfs/go-block-format v0.0.2 github.com/ipfs/go-cid v0.0.5 github.com/ipfs/go-datastore v0.4.4 // indirect diff --git a/go.sum b/go.sum index f72f818..5611d46 100644 --- a/go.sum +++ b/go.sum @@ -59,6 +59,8 @@ github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8l github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= diff --git a/go/xtestutils/doc.go b/go/xtestutils/doc.go new file mode 100644 index 0000000..55e7ebb --- /dev/null +++ b/go/xtestutils/doc.go @@ -0,0 +1,2 @@ +// Package xtestutils provides golang testutils for developing with TemporalX +package xtestutils diff --git a/go/xtestutils/testutils.go b/go/xtestutils/testutils.go new file mode 100644 index 0000000..907deb7 --- /dev/null +++ b/go/xtestutils/testutils.go @@ -0,0 +1,19 @@ +package xtestutils + +import ( + "os" + "testing" +) + +// GetXAPIAddress returns the address to used to talk to TemporalX +func GetXAPIAddress(t *testing.T) string { + if os.Getenv("TEST_XAPI") != "" { + return os.Getenv("TEST_XAPI") + } + return "xapi.temporal.cloud:9090" +} + +// GetXAPIInsecure returns whether or not to use a secure connection +func GetXAPIInsecure(t *testing.T) bool { + return os.Getenv("TEST_XAPI_SECURE") != "true" +} diff --git a/go/xtestutils/testutils_test.go b/go/xtestutils/testutils_test.go new file mode 100644 index 0000000..ee2b60b --- /dev/null +++ b/go/xtestutils/testutils_test.go @@ -0,0 +1,30 @@ +package xtestutils + +import ( + "os" + "testing" +) + +func TestGetXAPIAddress(t *testing.T) { + if addr := GetXAPIAddress(t); addr != "xapi.temporal.cloud:9090" { + t.Fatal("bad address") + } + if err := os.Setenv("TEST_XAPI", "xxapi.temporal.cloud:9090"); err != nil { + t.Fatal(err) + } + if addr := GetXAPIAddress(t); addr != "xxapi.temporal.cloud:9090" { + t.Fatal("bad address") + } +} + +func TestXAPISecure(t *testing.T) { + if !GetXAPIInsecure(t) { + t.Fatal("should be true") + } + if err := os.Setenv("TEST_XAPI_SECURE", "true"); err != nil { + t.Fatal(err) + } + if GetXAPIInsecure(t) { + t.Fatal("should be false") + } +}