Skip to content

Commit 8071950

Browse files
committed
fix utils tests
1 parent 5eb1159 commit 8071950

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

internal/pkg/utils/utils_test.go

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -546,53 +546,45 @@ func TestBase64Bytes_MarshalYAML(t *testing.T) {
546546
}
547547
func TestGetSliceFromPointer(t *testing.T) {
548548
tests := []struct {
549-
name string
550-
input *[]string
551-
expected []string
552-
expectNil bool
549+
name string
550+
input *[]string
551+
expected []string
553552
}{
554553
{
555-
name: "nil pointer",
556-
input: nil,
557-
expected: []string{},
558-
expectNil: false,
554+
name: "nil pointer",
555+
input: nil,
556+
expected: []string{},
559557
},
560558
{
561559
name: "pointer to nil slice",
562560
input: func() *[]string {
563561
var s []string
564562
return &s
565563
}(),
566-
expected: nil,
567-
expectNil: true,
564+
expected: []string{},
568565
},
569566
{
570-
name: "empty slice",
571-
input: &[]string{},
572-
expected: []string{},
573-
expectNil: false,
567+
name: "empty slice",
568+
input: &[]string{},
569+
expected: []string{},
574570
},
575571
{
576-
name: "populated slice",
577-
input: &[]string{"item1", "item2"},
578-
expected: []string{"item1", "item2"},
579-
expectNil: false,
572+
name: "populated slice",
573+
input: &[]string{"item1", "item2"},
574+
expected: []string{"item1", "item2"},
580575
},
581576
}
582577

583578
for _, tt := range tests {
584579
t.Run(tt.name, func(t *testing.T) {
585580
result := GetSliceFromPointer(tt.input)
586581

587-
if tt.expectNil {
588-
if result != nil {
589-
t.Errorf("GetSliceFromPointer() = %v, want nil", result)
590-
}
582+
if result == nil && tt.expected == nil {
591583
return
592584
}
593585

594-
if result == nil {
595-
t.Errorf("GetSliceFromPointer() = nil, want %v", tt.expected)
586+
if (result == nil && tt.expected != nil) || (result != nil && tt.expected == nil) {
587+
t.Errorf("GetSliceFromPointer() = %v, want %v", result, tt.expected)
596588
return
597589
}
598590

0 commit comments

Comments
 (0)