2020-10-05 13:18:30 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-03-15 12:42:43 +00:00
|
|
|
"github.com/hashicorp/nomad/ci"
|
2020-10-05 13:18:30 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_formatScalingPolicyTarget(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
|
|
|
|
2020-10-05 13:18:30 +00:00
|
|
|
testCases := []struct {
|
|
|
|
inputMap map[string]string
|
|
|
|
expectedOutput string
|
|
|
|
name string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
inputMap: map[string]string{
|
|
|
|
"Namespace": "default",
|
|
|
|
"Job": "example",
|
|
|
|
"Group": "cache",
|
|
|
|
},
|
|
|
|
expectedOutput: "Namespace:default,Job:example,Group:cache",
|
|
|
|
name: "generic horizontal scaling policy target",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
inputMap: map[string]string{
|
|
|
|
"Namespace": "default",
|
|
|
|
"Job": "example",
|
|
|
|
"Group": "cache",
|
|
|
|
"Unknown": "alien",
|
|
|
|
},
|
|
|
|
expectedOutput: "Namespace:default,Job:example,Group:cache,Unknown:alien",
|
|
|
|
name: "extra key in input mapping",
|
|
|
|
},
|
2020-10-06 10:18:17 +00:00
|
|
|
{
|
|
|
|
inputMap: map[string]string{
|
|
|
|
"Namespace": "default",
|
|
|
|
},
|
|
|
|
expectedOutput: "Namespace:default",
|
|
|
|
name: "single entry in map",
|
|
|
|
},
|
2020-10-05 13:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
actualOutput := formatScalingPolicyTarget(tc.inputMap)
|
|
|
|
assert.Equal(t, tc.expectedOutput, actualOutput, tc.name)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|