(t *testing.T)
| 241 | } |
| 242 | |
| 243 | func TestTransformForHostRoot(t *testing.T) { |
| 244 | hostRootVolumeName := "host-root" |
| 245 | hostDevCharVolumeName := "host-dev-char" |
| 246 | testCases := []struct { |
| 247 | description string |
| 248 | hostRoot string |
| 249 | input Daemonset |
| 250 | expectedOutput Daemonset |
| 251 | }{ |
| 252 | { |
| 253 | description: "no host root or host-dev-char volume in daemonset", |
| 254 | hostRoot: "/custom-root", |
| 255 | input: NewDaemonset(), |
| 256 | expectedOutput: NewDaemonset(), |
| 257 | }, |
| 258 | { |
| 259 | description: "empty host root is a no-op", |
| 260 | hostRoot: "", |
| 261 | input: NewDaemonset(). |
| 262 | WithHostPathVolume(hostRootVolumeName, "/", nil). |
| 263 | WithHostPathVolume(hostDevCharVolumeName, "/", nil), |
| 264 | expectedOutput: NewDaemonset(). |
| 265 | WithHostPathVolume(hostRootVolumeName, "/", nil). |
| 266 | WithHostPathVolume(hostDevCharVolumeName, "/", nil), |
| 267 | }, |
| 268 | { |
| 269 | description: "custom host root with host-root and host-dev-char volumes", |
| 270 | hostRoot: "/custom-root", |
| 271 | input: NewDaemonset(). |
| 272 | WithHostPathVolume(hostRootVolumeName, "/", nil). |
| 273 | WithHostPathVolume(hostDevCharVolumeName, "/", nil). |
| 274 | WithContainer(corev1.Container{Name: "test-ctr"}), |
| 275 | expectedOutput: NewDaemonset(). |
| 276 | WithHostPathVolume(hostRootVolumeName, "/custom-root", nil). |
| 277 | WithHostPathVolume(hostDevCharVolumeName, "/custom-root/dev/char", nil). |
| 278 | WithContainer(corev1.Container{Name: "test-ctr", Env: []corev1.EnvVar{{Name: HostRootEnvName, Value: "/custom-root"}}}), |
| 279 | }, |
| 280 | { |
| 281 | description: "custom host root with host-root volume", |
| 282 | hostRoot: "/custom-root", |
| 283 | input: NewDaemonset(). |
| 284 | WithHostPathVolume(hostRootVolumeName, "/", nil). |
| 285 | WithContainer(corev1.Container{Name: "test-ctr"}), |
| 286 | expectedOutput: NewDaemonset(). |
| 287 | WithHostPathVolume(hostRootVolumeName, "/custom-root", nil). |
| 288 | WithContainer(corev1.Container{Name: "test-ctr", Env: []corev1.EnvVar{{Name: HostRootEnvName, Value: "/custom-root"}}}), |
| 289 | }, |
| 290 | { |
| 291 | description: "custom host root with host-dev-char volume", |
| 292 | hostRoot: "/custom-root", |
| 293 | input: NewDaemonset(). |
| 294 | WithHostPathVolume(hostDevCharVolumeName, "/", nil), |
| 295 | expectedOutput: NewDaemonset(). |
| 296 | WithHostPathVolume(hostDevCharVolumeName, "/custom-root/dev/char", nil), |
| 297 | }, |
| 298 | } |
| 299 | |
| 300 | for _, tc := range testCases { |
nothing calls this directly
no test coverage detected