Skip to content

Commit

Permalink
Merge pull request #79 from RTradeLtd/testutils
Browse files Browse the repository at this point in the history
Add Test Utils For Golang
  • Loading branch information
bonedaddy authored Apr 20, 2020
2 parents 27d92ba + 5f7f06f commit d18a462
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 2 additions & 0 deletions go/xtestutils/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package xtestutils provides golang testutils for developing with TemporalX
package xtestutils
19 changes: 19 additions & 0 deletions go/xtestutils/testutils.go
Original file line number Diff line number Diff line change
@@ -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"
}
30 changes: 30 additions & 0 deletions go/xtestutils/testutils_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
}

0 comments on commit d18a462

Please sign in to comment.