diff --git a/database/repo/opts_test.go b/database/repo/opts_test.go index 78bfb826e..4f9e981ae 100644 --- a/database/repo/opts_test.go +++ b/database/repo/opts_test.go @@ -5,6 +5,7 @@ package repo import ( + "context" "reflect" "testing" @@ -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) + } + }) + } +}