Skip to content

Commit

Permalink
chore: add WithContext test
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Aug 17, 2023
1 parent 8d862f3 commit c794a50
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions database/repo/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package repo

import (
"context"
"reflect"
"testing"

Expand Down Expand Up @@ -208,3 +209,52 @@ func TestRepo_EngineOpt_WithSkipCreation(t *testing.T) {
})
}
}

func TestRepo_EngineOpt_WithContext(t *testing.T) {
// setup types
e := &engine{config: new(config)}

// setup tests
tests := []struct {
failure bool
name string
ctx context.Context
want context.Context
}{
{
failure: false,
name: "context set to TODO",
ctx: context.TODO(),
want: context.TODO(),
},
{
failure: false,
name: "context set to nil",
ctx: nil,
want: nil,
},
}

// run tests
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
err := WithContext(test.ctx)(e)

if test.failure {
if err == nil {
t.Errorf("WithContext for %s should have returned err", test.name)
}

return
}

if err != nil {
t.Errorf("WithContext returned err: %v", err)
}

if !reflect.DeepEqual(e.ctx, test.want) {
t.Errorf("WithContext is %v, want %v", e.ctx, test.want)
}
})
}
}

0 comments on commit c794a50

Please sign in to comment.