From 00e993c686ed1ddc2a45298691bbd630de2ab38e Mon Sep 17 00:00:00 2001 From: Somtochi Onyekwere Date: Mon, 20 Sep 2021 23:17:27 +0100 Subject: [PATCH] Add test for fieldIsMandatory Signed-off-by: Somtochi Onyekwere --- pkg/canary/config_tracker_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pkg/canary/config_tracker_test.go b/pkg/canary/config_tracker_test.go index 41c7ce03..2134a5f6 100644 --- a/pkg/canary/config_tracker_test.go +++ b/pkg/canary/config_tracker_test.go @@ -372,3 +372,30 @@ func TestConfigTracker_HasConfigChanged_ShouldReturnErrorWhenAPIServerIsDown(t * assert.Error(t, err) }) } + +func Test_fieldIsMandatory(t *testing.T) { + falsy := false + truthy := true + tests := []struct { + optional *bool + expected bool + }{ + { + optional: nil, + expected: true, + }, + { + optional: &falsy, + expected: true, + }, + { + optional: &truthy, + expected: false, + }, + } + + for _, tt := range tests { + actual := fieldIsMandatory(tt.optional) + assert.Equal(t, tt.expected, actual) + } +}