Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Assert Package 3/3 #1205

Merged
merged 12 commits into from
Sep 19, 2023
Merged
Empty file removed pkg/foundation/assert/.keep
Empty file.
84 changes: 0 additions & 84 deletions pkg/foundation/assert/test.go

This file was deleted.

23 changes: 13 additions & 10 deletions pkg/foundation/cerrors/cerrors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"runtime"
"testing"

"github.com/conduitio/conduit/pkg/foundation/assert"
"github.com/conduitio/conduit/pkg/foundation/cerrors"
"github.com/matryer/is"
)
Expand All @@ -45,22 +44,24 @@ func (w *unwrapPanicError) Unwrap() error {
}

func TestNew(t *testing.T) {
is := is.New(t)

err := newError()
s := fmt.Sprintf("%+v", err)
assert.Equal(
t,
is.Equal(
"foobar:\n github.com/conduitio/conduit/pkg/foundation/cerrors_test.newError\n "+helperFilePath+":26",
s,
)
}

func TestErrorf(t *testing.T) {
is := is.New(t)

err := cerrors.Errorf("caused by: %w", newError())
s := fmt.Sprintf("%+v", err)
assert.Equal(
t,
is.Equal(
"caused by:\n github.com/conduitio/conduit/pkg/foundation/cerrors_test.TestErrorf\n "+
testFileLocation+":58\n - "+
testFileLocation+":60\n - "+
"foobar:\n github.com/conduitio/conduit/pkg/foundation/cerrors_test.newError\n "+
helperFilePath+":26",
s,
Expand Down Expand Up @@ -90,7 +91,7 @@ func TestGetStackTrace(t *testing.T) {
{
Func: "github.com/conduitio/conduit/pkg/foundation/cerrors_test.TestGetStackTrace",
File: testFileLocation,
Line: 88,
Line: 89,
},
},
},
Expand Down Expand Up @@ -135,14 +136,16 @@ func TestGetStackTrace(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
is := is.New(t)

res := cerrors.GetStackTrace(tc.err)
if tc.expected == nil {
assert.Nil(t, res)
is.True(res == nil || len(res.([]cerrors.Frame)) == 0)
return
}
act, ok := res.([]cerrors.Frame)
assert.True(t, ok, "expected []cerrors.Frame")
assert.Equal(t, tc.expected, act)
is.True(ok) // expected []cerrors.Frame
is.Equal(tc.expected, act)
})
}
}
Expand Down
22 changes: 16 additions & 6 deletions pkg/foundation/ctxutil/filepath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,49 @@ import (
"fmt"
"testing"

"github.com/conduitio/conduit/pkg/foundation/assert"
"github.com/conduitio/conduit/pkg/foundation/log"
"github.com/google/uuid"
"github.com/matryer/is"
"github.com/rs/zerolog"
)

func TestContextWithFilepath_Success(t *testing.T) {
is := is.New(t)

ctx := context.Background()
filepath := uuid.NewString()

ctx = ContextWithFilepath(ctx, filepath)
got := FilepathFromContext(ctx)

assert.Equal(t, filepath, got)
is.Equal(filepath, got)
}

func TestContextWithFilepath_Twice(t *testing.T) {
is := is.New(t)

ctx := context.Background()
filepath := uuid.NewString()

ctx = ContextWithFilepath(ctx, "existing filepath")
ctx = ContextWithFilepath(ctx, filepath)
got := FilepathFromContext(ctx)

assert.Equal(t, filepath, got)
is.Equal(filepath, got)
}

func TestFilepathFromContext_Empty(t *testing.T) {
is := is.New(t)

ctx := context.Background()
got := FilepathFromContext(ctx)

assert.Equal(t, "", got)
is.Equal("", got)
}

func TestFilepathLogCtxHook_Success(t *testing.T) {
is := is.New(t)

ctx := context.Background()
filepath := uuid.NewString()

Expand All @@ -66,10 +74,12 @@ func TestFilepathLogCtxHook_Success(t *testing.T) {
FilepathLogCtxHook{}.Run(e, zerolog.InfoLevel, "")
e.Send()

assert.Equal(t, fmt.Sprintf(`{"level":"info","%s":"%s"}`, log.FilepathField, filepath)+"\n", logOutput.String())
is.Equal(fmt.Sprintf(`{"level":"info","%s":"%s"}`, log.FilepathField, filepath)+"\n", logOutput.String())
}

func TestFilepathLogCtxHook_EmptyCtx(t *testing.T) {
is := is.New(t)

ctx := context.Background()

var logOutput bytes.Buffer
Expand All @@ -78,5 +88,5 @@ func TestFilepathLogCtxHook_EmptyCtx(t *testing.T) {
FilepathLogCtxHook{}.Run(e, zerolog.InfoLevel, "")
e.Send()

assert.Equal(t, `{"level":"info"}`+"\n", logOutput.String())
is.Equal(`{"level":"info"}`+"\n", logOutput.String())
}
22 changes: 16 additions & 6 deletions pkg/foundation/ctxutil/messageid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,49 @@ import (
"fmt"
"testing"

"github.com/conduitio/conduit/pkg/foundation/assert"
"github.com/conduitio/conduit/pkg/foundation/log"
"github.com/google/uuid"
"github.com/matryer/is"
"github.com/rs/zerolog"
)

func TestContextWithMessageID_Success(t *testing.T) {
is := is.New(t)

ctx := context.Background()
messageID := uuid.NewString()

ctx = ContextWithMessageID(ctx, messageID)
got := MessageIDFromContext(ctx)

assert.Equal(t, messageID, got)
is.Equal(messageID, got)
}

func TestContextWithMessageID_Twice(t *testing.T) {
is := is.New(t)

ctx := context.Background()
messageID := uuid.NewString()

ctx = ContextWithMessageID(ctx, "existing message ID")
ctx = ContextWithMessageID(ctx, messageID)
got := MessageIDFromContext(ctx)

assert.Equal(t, messageID, got)
is.Equal(messageID, got)
}

func TestMessageIDFromContext_Empty(t *testing.T) {
is := is.New(t)

ctx := context.Background()
got := MessageIDFromContext(ctx)

assert.Equal(t, "", got)
is.Equal("", got)
}

func TestMessageIDLogCtxHook_Success(t *testing.T) {
is := is.New(t)

ctx := context.Background()
messageID := uuid.NewString()

Expand All @@ -66,10 +74,12 @@ func TestMessageIDLogCtxHook_Success(t *testing.T) {
MessageIDLogCtxHook{}.Run(e, zerolog.InfoLevel, "")
e.Send()

assert.Equal(t, fmt.Sprintf(`{"level":"info","%s":"%s"}`, log.MessageIDField, messageID)+"\n", logOutput.String())
is.Equal(fmt.Sprintf(`{"level":"info","%s":"%s"}`, log.MessageIDField, messageID)+"\n", logOutput.String())
}

func TestMessageIDLogCtxHook_EmptyCtx(t *testing.T) {
is := is.New(t)

ctx := context.Background()

var logOutput bytes.Buffer
Expand All @@ -78,5 +88,5 @@ func TestMessageIDLogCtxHook_EmptyCtx(t *testing.T) {
MessageIDLogCtxHook{}.Run(e, zerolog.InfoLevel, "")
e.Send()

assert.Equal(t, `{"level":"info"}`+"\n", logOutput.String())
is.Equal(`{"level":"info"}`+"\n", logOutput.String())
}
22 changes: 16 additions & 6 deletions pkg/foundation/ctxutil/requestid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,49 @@ import (
"fmt"
"testing"

"github.com/conduitio/conduit/pkg/foundation/assert"
"github.com/conduitio/conduit/pkg/foundation/log"
"github.com/google/uuid"
"github.com/matryer/is"
"github.com/rs/zerolog"
)

func TestContextWithRequestID_Success(t *testing.T) {
is := is.New(t)

ctx := context.Background()
requestID := uuid.NewString()

ctx = ContextWithRequestID(ctx, requestID)
got := RequestIDFromContext(ctx)

assert.Equal(t, requestID, got)
is.Equal(requestID, got)
}

func TestContextWithRequestID_Twice(t *testing.T) {
is := is.New(t)

ctx := context.Background()
requestID := uuid.NewString()

ctx = ContextWithRequestID(ctx, "existing request ID")
ctx = ContextWithRequestID(ctx, requestID)
got := RequestIDFromContext(ctx)

assert.Equal(t, requestID, got)
is.Equal(requestID, got)
}

func TestRequestIDFromContext_Empty(t *testing.T) {
is := is.New(t)

ctx := context.Background()
got := RequestIDFromContext(ctx)

assert.Equal(t, "", got)
is.Equal("", got)
}

func TestRequestIDLogCtxHook_Success(t *testing.T) {
is := is.New(t)

ctx := context.Background()
requestID := uuid.NewString()

Expand All @@ -66,10 +74,12 @@ func TestRequestIDLogCtxHook_Success(t *testing.T) {
RequestIDLogCtxHook{}.Run(e, zerolog.InfoLevel, "")
e.Send()

assert.Equal(t, fmt.Sprintf(`{"level":"info","%s":"%s"}`, log.RequestIDField, requestID)+"\n", logOutput.String())
is.Equal(fmt.Sprintf(`{"level":"info","%s":"%s"}`, log.RequestIDField, requestID)+"\n", logOutput.String())
}

func TestRequestIDLogCtxHook_EmptyCtx(t *testing.T) {
is := is.New(t)

ctx := context.Background()

var logOutput bytes.Buffer
Expand All @@ -78,5 +88,5 @@ func TestRequestIDLogCtxHook_EmptyCtx(t *testing.T) {
RequestIDLogCtxHook{}.Run(e, zerolog.InfoLevel, "")
e.Send()

assert.Equal(t, `{"level":"info"}`+"\n", logOutput.String())
is.Equal(`{"level":"info"}`+"\n", logOutput.String())
}
Loading