From 26aa0b67266384527dd09e94f3af463e0ef63e83 Mon Sep 17 00:00:00 2001 From: dave vader <48764154+plyr4@users.noreply.github.com> Date: Thu, 17 Aug 2023 10:16:13 -0500 Subject: [PATCH] chore: add WithContext test to builds (#931) --- database/build/opts_test.go | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/database/build/opts_test.go b/database/build/opts_test.go index 2d41cc676..69afe0b4a 100644 --- a/database/build/opts_test.go +++ b/database/build/opts_test.go @@ -5,6 +5,7 @@ package build import ( + "context" "reflect" "testing" @@ -159,3 +160,52 @@ func TestBuild_EngineOpt_WithSkipCreation(t *testing.T) { }) } } + +func TestBuild_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) + } + }) + } +}