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