From dd5a04dda8d2cc4b82d1022ae7c96cc851342824 Mon Sep 17 00:00:00 2001 From: Brandon Bennett Date: Fri, 16 Jun 2023 11:00:39 -0300 Subject: [PATCH] fix CreateSubscription test (#55) Since the xml namespace for `` is different from the base namespace it need to be explicit and it was missing from the match side of the tests. Also moved to `time.Date` from `time.Parse` to get rid of some unneeded error handling and migrated the tests to use testify to make the output more clear. --- ops_test.go | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/ops_test.go b/ops_test.go index c89eb76..b3879ee 100644 --- a/ops_test.go +++ b/ops_test.go @@ -539,14 +539,9 @@ func TestCancelCommit(t *testing.T) { } func TestCreateSubscription(t *testing.T) { - st, err := time.Parse(time.RFC3339, "2023-06-07T18:31:48+02:00") - if err != nil { - t.Fatalf("invalid startTime: %s", st) - } - et, err := time.Parse(time.RFC3339, "2023-06-07T18:33:48+02:00") - if err != nil { - t.Fatalf("invalid endTime: %s", et) - } + start := time.Date(2023, time.June, 07, 18, 31, 48, 00, time.UTC) + end := time.Date(2023, time.June, 07, 18, 33, 48, 00, time.UTC) + tt := []struct { name string options []CreateSubscriptionOption @@ -555,28 +550,28 @@ func TestCreateSubscription(t *testing.T) { { name: "noOptions", matches: []*regexp.Regexp{ - regexp.MustCompile(``), + regexp.MustCompile(``), }, }, { name: "startTime option", - options: []CreateSubscriptionOption{WithStartTimeOption(st)}, + options: []CreateSubscriptionOption{WithStartTimeOption(start)}, matches: []*regexp.Regexp{ - regexp.MustCompile(`` + regexp.QuoteMeta(st.Format(time.RFC3339)) + ``), + regexp.MustCompile(`` + regexp.QuoteMeta(start.Format(time.RFC3339)) + ``), }, }, { name: "endTime option", - options: []CreateSubscriptionOption{WithEndTimeOption(et)}, + options: []CreateSubscriptionOption{WithEndTimeOption(end)}, matches: []*regexp.Regexp{ - regexp.MustCompile(`` + regexp.QuoteMeta(et.Format(time.RFC3339)) + ``), + regexp.MustCompile(`` + regexp.QuoteMeta(end.Format(time.RFC3339)) + ``), }, }, { name: "stream option", options: []CreateSubscriptionOption{WithStreamOption("thestream")}, matches: []*regexp.Regexp{ - regexp.MustCompile(`thestream`), + regexp.MustCompile(`thestream`), }, }, } @@ -590,19 +585,13 @@ func TestCreateSubscription(t *testing.T) { ts.queueRespString(``) err := sess.CreateSubscription(context.Background(), tc.options...) - if err != nil { - t.Errorf("unexpected error: %v", err) - } + assert.NoError(t, err) sentMsg, err := ts.popReq() - if err != nil { - t.Errorf("failed to read message sent to sever: %v", err) - } + assert.NoError(t, err) for _, match := range tc.matches { - if !match.Match(sentMsg) { - t.Errorf("sent message didn't match `%s`", match.String()) - } + assert.Regexp(t, match, string(sentMsg)) } }) }