|
5 | 5 |
|
6 | 6 | config "github.com/openshift/api/config/v1" |
7 | 7 | "github.com/stretchr/testify/assert" |
| 8 | + "github.com/stretchr/testify/require" |
| 9 | + |
| 10 | + "github.com/openshift/windows-machine-config-operator/pkg/windows" |
8 | 11 | ) |
9 | 12 |
|
10 | 13 | func TestGetHostnameCmd(t *testing.T) { |
@@ -41,3 +44,109 @@ func TestGetHostnameCmd(t *testing.T) { |
41 | 44 | }) |
42 | 45 | } |
43 | 46 | } |
| 47 | + |
| 48 | +func TestHybridOverlayConfiguration(t *testing.T) { |
| 49 | + tests := []struct { |
| 50 | + name string |
| 51 | + vxlanPort string |
| 52 | + debug bool |
| 53 | + expectedCmdContains []string |
| 54 | + expectedCmdNotContains []string |
| 55 | + }{ |
| 56 | + { |
| 57 | + name: "Basic configuration with no optional flags", |
| 58 | + vxlanPort: "", |
| 59 | + debug: false, |
| 60 | + expectedCmdContains: []string{ |
| 61 | + windows.HybridOverlayPath, |
| 62 | + "--node NODE_NAME", |
| 63 | + "--bootstrap-kubeconfig=" + windows.KubeconfigPath, |
| 64 | + "--cert-dir=" + windows.CniConfDir, |
| 65 | + "--cert-duration=24h", |
| 66 | + "--windows-service", |
| 67 | + "--logfile", |
| 68 | + windows.HybridOverlayLogDir + "\\hybrid-overlay.log", |
| 69 | + "--k8s-cacert " + windows.TrustedCABundlePath, |
| 70 | + }, |
| 71 | + expectedCmdNotContains: []string{ |
| 72 | + "--hybrid-overlay-vxlan-port", |
| 73 | + "--loglevel 5", |
| 74 | + }, |
| 75 | + }, |
| 76 | + { |
| 77 | + name: "Configuration with debug logging enabled", |
| 78 | + vxlanPort: "", |
| 79 | + debug: true, |
| 80 | + expectedCmdContains: []string{ |
| 81 | + windows.HybridOverlayPath, |
| 82 | + "--node NODE_NAME", |
| 83 | + "--bootstrap-kubeconfig=" + windows.KubeconfigPath, |
| 84 | + "--cert-dir=" + windows.CniConfDir, |
| 85 | + "--cert-duration=24h", |
| 86 | + "--windows-service", |
| 87 | + "--logfile", |
| 88 | + windows.HybridOverlayLogDir + "\\hybrid-overlay.log", |
| 89 | + "--k8s-cacert " + windows.TrustedCABundlePath, |
| 90 | + "--loglevel 5", |
| 91 | + }, |
| 92 | + expectedCmdNotContains: []string{ |
| 93 | + "--hybrid-overlay-vxlan-port", |
| 94 | + }, |
| 95 | + }, |
| 96 | + { |
| 97 | + name: "Configuration with all optional flags enabled", |
| 98 | + vxlanPort: "4789", |
| 99 | + debug: true, |
| 100 | + expectedCmdContains: []string{ |
| 101 | + windows.HybridOverlayPath, |
| 102 | + "--node NODE_NAME", |
| 103 | + "--bootstrap-kubeconfig=" + windows.KubeconfigPath, |
| 104 | + "--cert-dir=" + windows.CniConfDir, |
| 105 | + "--cert-duration=24h", |
| 106 | + "--windows-service", |
| 107 | + "--logfile", |
| 108 | + windows.HybridOverlayLogDir + "\\hybrid-overlay.log", |
| 109 | + "--k8s-cacert " + windows.TrustedCABundlePath, |
| 110 | + "--hybrid-overlay-vxlan-port 4789", |
| 111 | + "--loglevel 5", |
| 112 | + }, |
| 113 | + expectedCmdNotContains: []string{}, |
| 114 | + }, |
| 115 | + } |
| 116 | + |
| 117 | + for _, test := range tests { |
| 118 | + t.Run(test.name, func(t *testing.T) { |
| 119 | + result := hybridOverlayConfiguration(test.vxlanPort, test.debug) |
| 120 | + |
| 121 | + assert.Equal(t, windows.HybridOverlayServiceName, result.Name, |
| 122 | + "Service name should match expected value") |
| 123 | + assert.False(t, result.Bootstrap, |
| 124 | + "Service should not be a bootstrap service") |
| 125 | + assert.Equal(t, uint(2), result.Priority, |
| 126 | + "Service priority should be 2") |
| 127 | + assert.Equal(t, []string{windows.KubeletServiceName}, result.Dependencies, |
| 128 | + "Service should depend on kubelet service") |
| 129 | + assert.Nil(t, result.PowershellPreScripts, |
| 130 | + "Service should not have PowerShell pre-scripts") |
| 131 | + |
| 132 | + require.Len(t, result.NodeVariablesInCommand, 1, |
| 133 | + "Service should have exactly one node variable") |
| 134 | + assert.Equal(t, "NODE_NAME", result.NodeVariablesInCommand[0].Name, |
| 135 | + "Node variable name should be NODE_NAME") |
| 136 | + assert.Equal(t, "{.metadata.name}", result.NodeVariablesInCommand[0].NodeObjectJsonPath, |
| 137 | + "Node variable JSON path should match expected format") |
| 138 | + |
| 139 | + for _, expectedStr := range test.expectedCmdContains { |
| 140 | + assert.Contains(t, result.Command, expectedStr, |
| 141 | + "Command should contain: %s\nActual command: %s", |
| 142 | + expectedStr, result.Command) |
| 143 | + } |
| 144 | + |
| 145 | + for _, unexpectedStr := range test.expectedCmdNotContains { |
| 146 | + assert.NotContains(t, result.Command, unexpectedStr, |
| 147 | + "Command should not contain: %s\nActual command: %s", |
| 148 | + unexpectedStr, result.Command) |
| 149 | + } |
| 150 | + }) |
| 151 | + } |
| 152 | +} |
0 commit comments