From 16b26adfda4c20d1b7dc3f491a32ea704abd4c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20C=C3=A1rdenas?= Date: Thu, 29 Jul 2021 12:30:36 +0200 Subject: [PATCH] Publish ablytest package. --- ably/ably_test.go | 2 +- ably/auth_test.go | 2 +- ably/event_emitter_spec_test.go | 2 +- ably/event_emitter_test.go | 2 +- ably/http_paginated_response_test.go | 2 +- ably/proto_message_test.go | 2 +- ably/readme_examples_test.go | 2 +- ably/realtime_channel_spec_test.go | 2 +- ably/realtime_channel_test.go | 2 +- ably/realtime_client_test.go | 2 +- ably/realtime_conn_spec_test.go | 2 +- ably/realtime_conn_test.go | 2 +- ably/realtime_presence_test.go | 2 +- ably/rest_channel_spec_test.go | 2 +- ably/rest_channel_test.go | 2 +- ably/rest_client_test.go | 2 +- ably/rest_presence_spec_test.go | 2 +- ably/transitioner_test.go | 2 +- .../ablytest => ablytest}/ablytest.go | 3 +- .../ablytest => ablytest}/cryptodata.go | 0 {ably/internal/ablytest => ablytest}/fmt.go | 0 .../ablytest => ablytest}/fmt_test.go | 2 +- .../internal/ablytest => ablytest}/logger.go | 0 ablytest/msgpack.go | 32 +++++++++++++++++++ .../ablytest => ablytest}/pagination.go | 0 .../internal/ablytest => ablytest}/proxies.go | 0 .../ablytest => ablytest}/recorders.go | 0 .../ablytest => ablytest}/resultgroup.go | 0 .../internal/ablytest => ablytest}/sandbox.go | 0 .../ablytest => ablytest}/test_utils.go | 0 .../internal/ablytest => ablytest}/timeout.go | 0 scripts/test_readme_examples/main.go | 2 +- 32 files changed, 53 insertions(+), 22 deletions(-) rename {ably/internal/ablytest => ablytest}/ablytest.go (98%) rename {ably/internal/ablytest => ablytest}/cryptodata.go (100%) rename {ably/internal/ablytest => ablytest}/fmt.go (100%) rename {ably/internal/ablytest => ablytest}/fmt_test.go (90%) rename {ably/internal/ablytest => ablytest}/logger.go (100%) create mode 100644 ablytest/msgpack.go rename {ably/internal/ablytest => ablytest}/pagination.go (100%) rename {ably/internal/ablytest => ablytest}/proxies.go (100%) rename {ably/internal/ablytest => ablytest}/recorders.go (100%) rename {ably/internal/ablytest => ablytest}/resultgroup.go (100%) rename {ably/internal/ablytest => ablytest}/sandbox.go (100%) rename {ably/internal/ablytest => ablytest}/test_utils.go (100%) rename {ably/internal/ablytest => ablytest}/timeout.go (100%) diff --git a/ably/ably_test.go b/ably/ably_test.go index 1590e2f6..0a06379f 100644 --- a/ably/ably_test.go +++ b/ably/ably_test.go @@ -14,8 +14,8 @@ import ( "time" "github.com/ably/ably-go/ably" - "github.com/ably/ably-go/ably/internal/ablytest" "github.com/ably/ably-go/ably/internal/ablyutil" + "github.com/ably/ably-go/ablytest" ) type Result interface { diff --git a/ably/auth_test.go b/ably/auth_test.go index 58ac27aa..bd36d648 100644 --- a/ably/auth_test.go +++ b/ably/auth_test.go @@ -13,7 +13,7 @@ import ( "time" "github.com/ably/ably-go/ably" - "github.com/ably/ably-go/ably/internal/ablytest" + "github.com/ably/ably-go/ablytest" ) func single() *ably.PaginateParams { diff --git a/ably/event_emitter_spec_test.go b/ably/event_emitter_spec_test.go index 5e553184..5e2e6b5b 100644 --- a/ably/event_emitter_spec_test.go +++ b/ably/event_emitter_spec_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/ably/ably-go/ably" - "github.com/ably/ably-go/ably/internal/ablytest" + "github.com/ably/ably-go/ablytest" ) func Test_RTE3_EventEmitter_On(t *testing.T) { diff --git a/ably/event_emitter_test.go b/ably/event_emitter_test.go index d130985b..3f3189ed 100644 --- a/ably/event_emitter_test.go +++ b/ably/event_emitter_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/ably/ably-go/ably" - "github.com/ably/ably-go/ably/internal/ablytest" + "github.com/ably/ably-go/ablytest" ) func TestEventEmitterConcurrency(t *testing.T) { diff --git a/ably/http_paginated_response_test.go b/ably/http_paginated_response_test.go index 554ad98b..5ae1502d 100644 --- a/ably/http_paginated_response_test.go +++ b/ably/http_paginated_response_test.go @@ -10,7 +10,7 @@ import ( "github.com/ably/ably-go/ably" - "github.com/ably/ably-go/ably/internal/ablytest" + "github.com/ably/ably-go/ablytest" ) func TestHTTPPaginatedResponse(t *testing.T) { diff --git a/ably/proto_message_test.go b/ably/proto_message_test.go index 3ea1f5d8..e5ffef3f 100644 --- a/ably/proto_message_test.go +++ b/ably/proto_message_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/ably/ably-go/ably" - "github.com/ably/ably-go/ably/internal/ablytest" + "github.com/ably/ably-go/ablytest" ) type custom struct{} diff --git a/ably/readme_examples_test.go b/ably/readme_examples_test.go index 3903f955..6da10572 100644 --- a/ably/readme_examples_test.go +++ b/ably/readme_examples_test.go @@ -3,7 +3,7 @@ package ably_test import "testing" import "github.com/ably/ably-go/ably" -import "github.com/ably/ably-go/ably/internal/ablytest" +import "github.com/ably/ably-go/ablytest" /* README.md:22 */ import "context" diff --git a/ably/realtime_channel_spec_test.go b/ably/realtime_channel_spec_test.go index 82ebe938..8bf132d6 100644 --- a/ably/realtime_channel_spec_test.go +++ b/ably/realtime_channel_spec_test.go @@ -13,7 +13,7 @@ import ( "time" "github.com/ably/ably-go/ably" - "github.com/ably/ably-go/ably/internal/ablytest" + "github.com/ably/ably-go/ablytest" ) func TestRealtimeChannel_RTL2_ChannelEventForStateChange(t *testing.T) { diff --git a/ably/realtime_channel_test.go b/ably/realtime_channel_test.go index 299c8d9e..d7c16491 100644 --- a/ably/realtime_channel_test.go +++ b/ably/realtime_channel_test.go @@ -9,7 +9,7 @@ import ( "time" "github.com/ably/ably-go/ably" - "github.com/ably/ably-go/ably/internal/ablytest" + "github.com/ably/ably-go/ablytest" ) func expectMsg(ch <-chan *ably.Message, name string, data interface{}, t time.Duration, received bool) error { diff --git a/ably/realtime_client_test.go b/ably/realtime_client_test.go index a0bae0c9..6b45397d 100644 --- a/ably/realtime_client_test.go +++ b/ably/realtime_client_test.go @@ -10,7 +10,7 @@ import ( "time" "github.com/ably/ably-go/ably" - "github.com/ably/ably-go/ably/internal/ablytest" + "github.com/ably/ably-go/ablytest" ) func TestRealtime_RealtimeHost(t *testing.T) { diff --git a/ably/realtime_conn_spec_test.go b/ably/realtime_conn_spec_test.go index 31173787..6e5bc507 100644 --- a/ably/realtime_conn_spec_test.go +++ b/ably/realtime_conn_spec_test.go @@ -14,7 +14,7 @@ import ( "time" "github.com/ably/ably-go/ably" - "github.com/ably/ably-go/ably/internal/ablytest" + "github.com/ably/ably-go/ablytest" ) func Test_RTN2_WebsocketQueryParams(t *testing.T) { diff --git a/ably/realtime_conn_test.go b/ably/realtime_conn_test.go index d6101945..79dfa2fd 100644 --- a/ably/realtime_conn_test.go +++ b/ably/realtime_conn_test.go @@ -8,7 +8,7 @@ import ( "time" "github.com/ably/ably-go/ably" - "github.com/ably/ably-go/ably/internal/ablytest" + "github.com/ably/ably-go/ablytest" ) var connTransitions = []ably.ConnectionState{ diff --git a/ably/realtime_presence_test.go b/ably/realtime_presence_test.go index 79ab3a45..f1c9bacc 100644 --- a/ably/realtime_presence_test.go +++ b/ably/realtime_presence_test.go @@ -9,7 +9,7 @@ import ( "time" "github.com/ably/ably-go/ably" - "github.com/ably/ably-go/ably/internal/ablytest" + "github.com/ably/ably-go/ablytest" ) func contains(members []*ably.PresenceMessage, clients ...string) error { diff --git a/ably/rest_channel_spec_test.go b/ably/rest_channel_spec_test.go index 0199d83c..36358665 100644 --- a/ably/rest_channel_spec_test.go +++ b/ably/rest_channel_spec_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/ably/ably-go/ably" - "github.com/ably/ably-go/ably/internal/ablytest" + "github.com/ably/ably-go/ablytest" ) func TestRSL1f1(t *testing.T) { diff --git a/ably/rest_channel_test.go b/ably/rest_channel_test.go index 93a97efd..b2e32310 100644 --- a/ably/rest_channel_test.go +++ b/ably/rest_channel_test.go @@ -18,7 +18,7 @@ import ( "github.com/ably/ably-go/ably/internal/ablyutil" "github.com/ably/ably-go/ably" - "github.com/ably/ably-go/ably/internal/ablytest" + "github.com/ably/ably-go/ablytest" ) func TestRESTChannel(t *testing.T) { diff --git a/ably/rest_client_test.go b/ably/rest_client_test.go index 5a1dd42a..e7cf7eb5 100644 --- a/ably/rest_client_test.go +++ b/ably/rest_client_test.go @@ -20,8 +20,8 @@ import ( "time" "github.com/ably/ably-go/ably" - "github.com/ably/ably-go/ably/internal/ablytest" "github.com/ably/ably-go/ably/internal/ablyutil" + "github.com/ably/ably-go/ablytest" ) func newHTTPClientMock(srv *httptest.Server) *http.Client { diff --git a/ably/rest_presence_spec_test.go b/ably/rest_presence_spec_test.go index a3e157c6..88be9a5b 100644 --- a/ably/rest_presence_spec_test.go +++ b/ably/rest_presence_spec_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/ably/ably-go/ably" - "github.com/ably/ably-go/ably/internal/ablytest" + "github.com/ably/ably-go/ablytest" ) func TestPresenceHistory_RSP4_RSP4b3(t *testing.T) { diff --git a/ably/transitioner_test.go b/ably/transitioner_test.go index 14869c8a..b84bd13c 100644 --- a/ably/transitioner_test.go +++ b/ably/transitioner_test.go @@ -9,7 +9,7 @@ import ( "time" "github.com/ably/ably-go/ably" - "github.com/ably/ably-go/ably/internal/ablytest" + "github.com/ably/ably-go/ablytest" ) type ConnTransitioner struct { diff --git a/ably/internal/ablytest/ablytest.go b/ablytest/ablytest.go similarity index 98% rename from ably/internal/ablytest/ablytest.go rename to ablytest/ablytest.go index 6a5fba76..fc7b8363 100644 --- a/ably/internal/ablytest/ablytest.go +++ b/ablytest/ablytest.go @@ -12,7 +12,6 @@ import ( "time" "github.com/ably/ably-go/ably" - "github.com/ably/ably-go/ably/internal/ablyutil" ) var Timeout = 30 * time.Second @@ -59,7 +58,7 @@ func encode(typ string, in interface{}) ([]byte, error) { case "application/json": return json.Marshal(in) case "application/x-msgpack": - return ablyutil.MarshalMsgpack(in) + return marshalMsgpack(in) case "text/plain": return []byte(fmt.Sprintf("%v", in)), nil default: diff --git a/ably/internal/ablytest/cryptodata.go b/ablytest/cryptodata.go similarity index 100% rename from ably/internal/ablytest/cryptodata.go rename to ablytest/cryptodata.go diff --git a/ably/internal/ablytest/fmt.go b/ablytest/fmt.go similarity index 100% rename from ably/internal/ablytest/fmt.go rename to ablytest/fmt.go diff --git a/ably/internal/ablytest/fmt_test.go b/ablytest/fmt_test.go similarity index 90% rename from ably/internal/ablytest/fmt_test.go rename to ablytest/fmt_test.go index d9c6381c..c4d4ea15 100644 --- a/ably/internal/ablytest/fmt_test.go +++ b/ablytest/fmt_test.go @@ -3,7 +3,7 @@ package ablytest_test import ( "fmt" - "github.com/ably/ably-go/ably/internal/ablytest" + "github.com/ably/ably-go/ablytest" ) func ExampleFmtFunc_Wrap() { diff --git a/ably/internal/ablytest/logger.go b/ablytest/logger.go similarity index 100% rename from ably/internal/ablytest/logger.go rename to ablytest/logger.go diff --git a/ablytest/msgpack.go b/ablytest/msgpack.go new file mode 100644 index 00000000..8c0d66df --- /dev/null +++ b/ablytest/msgpack.go @@ -0,0 +1,32 @@ +package ablytest + +import ( + "bytes" + "io" + + "github.com/ugorji/go/codec" +) + +var handle codec.MsgpackHandle + +func init() { + handle.Raw = true + handle.WriteExt = true + handle.RawToString = true +} + +// marshalMsgpack returns msgpack encoding of v +func marshalMsgpack(v interface{}) ([]byte, error) { + var buf bytes.Buffer + err := encodeMsg(&buf, v) + if err != nil { + return nil, err + } + return buf.Bytes(), nil +} + +// encodeMsg encodes v into msgpack format and writes the output to w. +func encodeMsg(w io.Writer, v interface{}) error { + enc := codec.NewEncoder(w, &handle) + return enc.Encode(v) +} diff --git a/ably/internal/ablytest/pagination.go b/ablytest/pagination.go similarity index 100% rename from ably/internal/ablytest/pagination.go rename to ablytest/pagination.go diff --git a/ably/internal/ablytest/proxies.go b/ablytest/proxies.go similarity index 100% rename from ably/internal/ablytest/proxies.go rename to ablytest/proxies.go diff --git a/ably/internal/ablytest/recorders.go b/ablytest/recorders.go similarity index 100% rename from ably/internal/ablytest/recorders.go rename to ablytest/recorders.go diff --git a/ably/internal/ablytest/resultgroup.go b/ablytest/resultgroup.go similarity index 100% rename from ably/internal/ablytest/resultgroup.go rename to ablytest/resultgroup.go diff --git a/ably/internal/ablytest/sandbox.go b/ablytest/sandbox.go similarity index 100% rename from ably/internal/ablytest/sandbox.go rename to ablytest/sandbox.go diff --git a/ably/internal/ablytest/test_utils.go b/ablytest/test_utils.go similarity index 100% rename from ably/internal/ablytest/test_utils.go rename to ablytest/test_utils.go diff --git a/ably/internal/ablytest/timeout.go b/ablytest/timeout.go similarity index 100% rename from ably/internal/ablytest/timeout.go rename to ablytest/timeout.go diff --git a/scripts/test_readme_examples/main.go b/scripts/test_readme_examples/main.go index 34b6e25c..ec4f3676 100644 --- a/scripts/test_readme_examples/main.go +++ b/scripts/test_readme_examples/main.go @@ -97,7 +97,7 @@ func (w *writer) writeHeader() state { w.writeln(`package ably_test`) w.writeln(`import "testing"`) w.writeln(`import "github.com/ably/ably-go/ably"`) - w.writeln(`import "github.com/ably/ably-go/ably/internal/ablytest"`) + w.writeln(`import "github.com/ably/ably-go/ablytest"`) loop: for {