From 330d66c2700bf2ebe3f699f28e13f05042cd3fd4 Mon Sep 17 00:00:00 2001 From: Rajat Kalsy Date: Fri, 31 Aug 2018 21:01:40 +0530 Subject: [PATCH] subscribe auth test fixes --- tests/e2e/subscribe_test_1.9.go | 57 +++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/e2e/subscribe_test_1.9.go diff --git a/tests/e2e/subscribe_test_1.9.go b/tests/e2e/subscribe_test_1.9.go new file mode 100644 index 00000000..87d85db8 --- /dev/null +++ b/tests/e2e/subscribe_test_1.9.go @@ -0,0 +1,57 @@ +// +build go1.9 + +package e2e + +import ( + "fmt" + "io/ioutil" + "log" + "os" + "testing" + "time" + + pubnub "github.com/pubnub/go" + "github.com/stretchr/testify/assert" +) + +func TestSubscribeParseLogsForAuthKey(t *testing.T) { + + assert := assert.New(t) + rescueStdout := os.Stdout + r, w, _ := os.Pipe() + os.Stdout = w + + pn := pubnub.NewPubNub(configCopy()) + pn.Config.AuthKey = "myAuthKey" + channel := "ch" + + pn.Config.Log = log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile) + + pn.Subscribe(). + Channels([]string{channel}). + Execute() + + tic := time.NewTicker(time.Duration(timeout) * time.Second) + select { + case <-tic.C: + tic.Stop() + } + + w.Close() + out, _ := ioutil.ReadAll(r) + os.Stdout = rescueStdout + + //fmt.Printf("Captured: %s", out) + + s := fmt.Sprintf("%s", out) + expected := fmt.Sprintf("https://%s/v2/subscribe/%s/%s/0?pnsdk=PubNub-Go/%s&uuid=%s&auth=%s", + pn.Config.Origin, + pn.Config.SubscribeKey, + channel, + pubnub.Version, + pn.Config.UUID, + pn.Config.AuthKey) + + //https://ps.pndsn.com/v2/subscribe/sub-c-e41d50d4-43ce-11e8-a433-9e6b275e7b64/ch/0?pnsdk=PubNub-Go/4.1.3&uuid=pn-ac860b0d-d078-46b1-b142-c5492101dc82&auth=myAuthKey + assert.Contains(s, expected) +}