github.com/hernad/nomad@v1.6.112/command/scaling_policy_test.go (about)

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