~samwhited/xmpp

668bf0eefa58fc605dcbcacb5687e4237c35ac2a — Sam Whited 10 months ago 5083328
all: compare custom error types with errors.Is

Previously these errors were being compared with == and != but soon
we'll want to support error wrapping on these errors and may want to add
fields that will make them uncomparable.

Signed-off-by: Sam Whited <sam@samwhited.com>
2 files changed, 8 insertions(+), 7 deletions(-)

M internal/stream/reader_test.go
M session_test.go
M internal/stream/reader_test.go => internal/stream/reader_test.go +3 -2
@@ 7,6 7,7 @@ package stream_test
import (
	"bytes"
	"encoding/xml"
	"errors"
	"reflect"
	"strconv"
	"strings"


@@ 109,7 110,7 @@ func TestReader(t *testing.T) {
				if reflect.TypeOf(tc.errType) != reflect.TypeOf(err) {
					t.Errorf("unexpected error type: want=%T, got=%T", tc.err, err)
				}
			case err != tc.err:
			case !errors.Is(err, tc.err):
				t.Errorf("unexpected error: want=%v, got=%#v", tc.err, err)
			}
			if err = e.Flush(); err != nil {


@@ 128,7 129,7 @@ func TestBadFormat(t *testing.T) {
	var out strings.Builder
	e := xml.NewEncoder(&out)
	_, err := xmlstream.Copy(e, r)
	if err != streamerr.BadFormat {
	if !errors.Is(err, streamerr.BadFormat) {
		t.Errorf("unexpected error: want=%v, got=%v", streamerr.BadFormat, err)
	}
	err = e.Flush()

M session_test.go => session_test.go +5 -5
@@ 314,14 314,14 @@ func TestServe(t *testing.T) {
			})

			err := s.Serve(tc.handler)
			if err != tc.err {
				t.Errorf("Unexpected error: want=%q, got=%q", tc.err, err)
			if !errors.Is(err, tc.err) {
				t.Errorf("unexpected error: want=%v, got=%v", tc.err, err)
			}
			if s := out.String(); s != tc.out {
				t.Errorf("Unexpected output:\nwant=%q,\n got=%q", tc.out, s)
				t.Errorf("unexpected output:\nwant=%s,\n got=%s", tc.out, s)
			}
			if l := in.Len(); l != 0 {
				t.Errorf("Did not finish read, %d bytes left", l)
				t.Errorf("did not finish read, %d bytes left", l)
			}
		})
	}


@@ 349,7 349,7 @@ func TestNegotiateStreamError(t *testing.T) {
	_, err := xmpp.NegotiateSession(ctx, clientJID, clientJID.Bare(), clientConn, false, xmpp.NewNegotiator(xmpp.StreamConfig{
		Features: []xmpp.StreamFeature{xmpp.StartTLS(nil)},
	}))
	if err != stream.Conflict {
	if !errors.Is(err, stream.Conflict) {
		t.Errorf("unexpected client err: want=%v, got=%v", stream.Conflict, err)
	}
}