mirror of
https://github.com/openfaas/faasd.git
synced 2025-06-21 14:23:34 +00:00
Improve clarity of testcase table
Signed-off-by: Alex Tomic <atomic777@gmail.com>
This commit is contained in:
@ -11,37 +11,52 @@ import (
|
|||||||
func Test_BuildLabels_WithAnnotations(t *testing.T) {
|
func Test_BuildLabels_WithAnnotations(t *testing.T) {
|
||||||
// Test each combination of nil/non-nil annotation + label
|
// Test each combination of nil/non-nil annotation + label
|
||||||
tables := []struct {
|
tables := []struct {
|
||||||
|
name string
|
||||||
label map[string]string
|
label map[string]string
|
||||||
annotation map[string]string
|
annotation map[string]string
|
||||||
result map[string]string
|
result map[string]string
|
||||||
}{
|
}{
|
||||||
{nil, nil, map[string]string{}},
|
{"Empty label and annotations returns empty table map", nil, nil, map[string]string{}},
|
||||||
{map[string]string{"L1": "V1"}, nil, map[string]string{"L1": "V1"}},
|
|
||||||
{nil, map[string]string{"A1": "V2"}, map[string]string{fmt.Sprintf("%sA1", annotationLabelPrefix): "V2"}},
|
|
||||||
{
|
{
|
||||||
map[string]string{"L1": "V1"}, map[string]string{"A1": "V2"},
|
"Label with empty annotation returns valid map",
|
||||||
map[string]string{"L1": "V1", fmt.Sprintf("%sA1", annotationLabelPrefix): "V2"},
|
map[string]string{"L1": "V1"},
|
||||||
|
nil,
|
||||||
|
map[string]string{"L1": "V1"}},
|
||||||
|
{
|
||||||
|
"Annotation with empty label returns valid map",
|
||||||
|
nil,
|
||||||
|
map[string]string{"A1": "V2"},
|
||||||
|
map[string]string{fmt.Sprintf("%sA1", annotationLabelPrefix): "V2"}},
|
||||||
|
{
|
||||||
|
"Label and annotation provided returns valid combined map",
|
||||||
|
map[string]string{"L1": "V1"},
|
||||||
|
map[string]string{"A1": "V2"},
|
||||||
|
map[string]string{
|
||||||
|
"L1": "V1",
|
||||||
|
fmt.Sprintf("%sA1", annotationLabelPrefix): "V2",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, pair := range tables {
|
for _, tc := range tables {
|
||||||
|
|
||||||
request := &types.FunctionDeployment{
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
Labels: &pair.label,
|
request := &types.FunctionDeployment{
|
||||||
Annotations: &pair.annotation,
|
Labels: &tc.label,
|
||||||
}
|
Annotations: &tc.annotation,
|
||||||
|
}
|
||||||
|
|
||||||
val, err := buildLabels(request)
|
val, err := buildLabels(request)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("want: no error got: %v", err)
|
t.Fatalf("want: no error got: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(val, pair.result) {
|
if !reflect.DeepEqual(val, tc.result) {
|
||||||
t.Errorf("Got: %s, expected %s", val, pair.result)
|
t.Errorf("Got: %s, expected %s", val, tc.result)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_BuildLabels_WithAnnotationCollision(t *testing.T) {
|
func Test_BuildLabels_WithAnnotationCollision(t *testing.T) {
|
||||||
@ -55,7 +70,6 @@ func Test_BuildLabels_WithAnnotationCollision(t *testing.T) {
|
|||||||
|
|
||||||
val, err := buildLabels(request)
|
val, err := buildLabels(request)
|
||||||
|
|
||||||
fmt.Printf("%s, %s\n", val, err)
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("Expected an error, got %d values", len(val))
|
t.Errorf("Expected an error, got %d values", len(val))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user