|
| 1 | +/* |
| 2 | +Copyright the Velero contributors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package install |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/spf13/pflag" |
| 23 | + "github.com/stretchr/testify/assert" |
| 24 | + "github.com/stretchr/testify/require" |
| 25 | +) |
| 26 | + |
| 27 | +func TestPriorityClassNameFlag(t *testing.T) { |
| 28 | + // Test that the flag is properly defined |
| 29 | + o := NewInstallOptions() |
| 30 | + flags := pflag.NewFlagSet("test", pflag.ContinueOnError) |
| 31 | + o.BindFlags(flags) |
| 32 | + |
| 33 | + // Verify the server priority class flag exists |
| 34 | + serverFlag := flags.Lookup("server-priority-class-name") |
| 35 | + assert.NotNil(t, serverFlag, "server-priority-class-name flag should exist") |
| 36 | + assert.Equal(t, "Priority class name for the Velero server deployment. Optional.", serverFlag.Usage) |
| 37 | + |
| 38 | + // Verify the node agent priority class flag exists |
| 39 | + nodeAgentFlag := flags.Lookup("node-agent-priority-class-name") |
| 40 | + assert.NotNil(t, nodeAgentFlag, "node-agent-priority-class-name flag should exist") |
| 41 | + assert.Equal(t, "Priority class name for the node agent daemonset. Optional.", nodeAgentFlag.Usage) |
| 42 | + |
| 43 | + // Test with values for both server and node agent |
| 44 | + testCases := []struct { |
| 45 | + name string |
| 46 | + serverPriorityClassName string |
| 47 | + nodeAgentPriorityClassName string |
| 48 | + expectedServerValue string |
| 49 | + expectedNodeAgentValue string |
| 50 | + }{ |
| 51 | + { |
| 52 | + name: "with both priority class names", |
| 53 | + serverPriorityClassName: "high-priority", |
| 54 | + nodeAgentPriorityClassName: "medium-priority", |
| 55 | + expectedServerValue: "high-priority", |
| 56 | + expectedNodeAgentValue: "medium-priority", |
| 57 | + }, |
| 58 | + { |
| 59 | + name: "with only server priority class name", |
| 60 | + serverPriorityClassName: "high-priority", |
| 61 | + nodeAgentPriorityClassName: "", |
| 62 | + expectedServerValue: "high-priority", |
| 63 | + expectedNodeAgentValue: "", |
| 64 | + }, |
| 65 | + { |
| 66 | + name: "with only node agent priority class name", |
| 67 | + serverPriorityClassName: "", |
| 68 | + nodeAgentPriorityClassName: "medium-priority", |
| 69 | + expectedServerValue: "", |
| 70 | + expectedNodeAgentValue: "medium-priority", |
| 71 | + }, |
| 72 | + { |
| 73 | + name: "without priority class names", |
| 74 | + serverPriorityClassName: "", |
| 75 | + nodeAgentPriorityClassName: "", |
| 76 | + expectedServerValue: "", |
| 77 | + expectedNodeAgentValue: "", |
| 78 | + }, |
| 79 | + } |
| 80 | + |
| 81 | + for _, tc := range testCases { |
| 82 | + t.Run(tc.name, func(t *testing.T) { |
| 83 | + o := NewInstallOptions() |
| 84 | + o.ServerPriorityClassName = tc.serverPriorityClassName |
| 85 | + o.NodeAgentPriorityClassName = tc.nodeAgentPriorityClassName |
| 86 | + |
| 87 | + veleroOptions, err := o.AsVeleroOptions() |
| 88 | + require.NoError(t, err) |
| 89 | + assert.Equal(t, tc.expectedServerValue, veleroOptions.ServerPriorityClassName) |
| 90 | + assert.Equal(t, tc.expectedNodeAgentValue, veleroOptions.NodeAgentPriorityClassName) |
| 91 | + }) |
| 92 | + } |
| 93 | +} |
0 commit comments