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 cfd840a commit b876238
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions database/pipeline/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package pipeline

import (
"context"
"reflect"
"testing"

Expand Down Expand Up @@ -214,3 +215,52 @@ func TestPipeline_EngineOpt_WithSkipCreation(t *testing.T) {
})
}
}

func TestPipeline_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 b876238

Please sign in to comment.