github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/command/scaling_policy_test.go (about)

     1  package command
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func Test_formatScalingPolicyTarget(t *testing.T) {
    10  	testCases := []struct {
    11  		inputMap       map[string]string
    12  		expectedOutput string
    13  		name           string
    14  	}{
    15  		{
    16  			inputMap: map[string]string{
    17  				"Namespace": "default",
    18  				"Job":       "example",
    19  				"Group":     "cache",
    20  			},
    21  			expectedOutput: "Namespace:default,Job:example,Group:cache",
    22  			name:           "generic horizontal scaling policy target",
    23  		},
    24  		{
    25  			inputMap: map[string]string{
    26  				"Namespace": "default",
    27  				"Job":       "example",
    28  				"Group":     "cache",
    29  				"Unknown":   "alien",
    30  			},
    31  			expectedOutput: "Namespace:default,Job:example,Group:cache,Unknown:alien",
    32  			name:           "extra key in input mapping",
    33  		},
    34  		{
    35  			inputMap: map[string]string{
    36  				"Namespace": "default",
    37  			},
    38  			expectedOutput: "Namespace:default",
    39  			name:           "single entry in map",
    40  		},
    41  	}
    42  
    43  	for _, tc := range testCases {
    44  		t.Run(tc.name, func(t *testing.T) {
    45  			actualOutput := formatScalingPolicyTarget(tc.inputMap)
    46  			assert.Equal(t, tc.expectedOutput, actualOutput, tc.name)
    47  		})
    48  	}
    49  }