...

Source file src/edge-infra.dev/pkg/edge/api/status/status_test.go

Documentation: edge-infra.dev/pkg/edge/api/status

     1  package status
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestIsNotReported(t *testing.T) {
    10  	testCases := []struct {
    11  		title           string
    12  		kind            string
    13  		notReportedElem map[string]bool
    14  		expected        bool
    15  	}{
    16  		{
    17  			title:           "Case 1 - Empty Map",
    18  			kind:            "Shipment",
    19  			notReportedElem: make(map[string]bool),
    20  			expected:        false,
    21  		},
    22  		{
    23  			title:           "Case 2 - Nil Map",
    24  			kind:            "Shipment",
    25  			notReportedElem: nil,
    26  			expected:        false,
    27  		},
    28  		{
    29  			title: "Case 3",
    30  			kind:  "Shipment",
    31  			notReportedElem: map[string]bool{
    32  				"Shipment":      true,
    33  				"Kustomization": true,
    34  				"Bucket":        false,
    35  			},
    36  			expected: true,
    37  		},
    38  		{
    39  			title: "Case 4",
    40  			kind:  "Shipment",
    41  			notReportedElem: map[string]bool{
    42  				"Shipment":      false,
    43  				"Kustomization": true,
    44  				"Bucket":        false,
    45  			},
    46  			expected: false,
    47  		},
    48  	}
    49  	for _, testCase := range testCases {
    50  		t.Run(testCase.title, func(t *testing.T) {
    51  			actual := IsNotReported(testCase.kind, testCase.notReportedElem)
    52  			assert.Equal(t, testCase.expected, actual)
    53  		})
    54  	}
    55  }
    56  
    57  func TestMergeErrorMessages(t *testing.T) {
    58  	testCases := []struct {
    59  		title    string
    60  		errors   []string
    61  		expected string
    62  	}{
    63  		{
    64  			title:    "Case 1 - nil",
    65  			errors:   nil,
    66  			expected: "",
    67  		},
    68  		{
    69  			title:    "Case 2 - empty array",
    70  			errors:   make([]string, 0),
    71  			expected: "",
    72  		},
    73  		{
    74  			title:    "Case 3 - length is 2",
    75  			errors:   []string{"hello", "world"},
    76  			expected: "hello and world",
    77  		},
    78  		{
    79  			title:    "Case 4 - length is 3",
    80  			errors:   []string{"hello", "beautiful", "world"},
    81  			expected: "hello, beautiful, and world",
    82  		},
    83  	}
    84  	for _, testCase := range testCases {
    85  		t.Run(testCase.title, func(t *testing.T) {
    86  			actual := MergeErrorMessages(testCase.errors)
    87  			assert.Equal(t, testCase.expected, actual)
    88  		})
    89  	}
    90  }
    91  

View as plain text