@@ -326,4 +326,60 @@ func TestCloudConfigInput(t *testing.T) {
326326 })
327327 }
328328 })
329+
330+ t .Run ("CustomCommands" , func (t * testing.T ) {
331+ for _ , tc := range []struct {
332+ name string
333+ makeCloudConfig func () (* cloudinit.CloudConfig , error )
334+ }{
335+ {
336+ name : "ControlPlaneInit" ,
337+ makeCloudConfig : func () (* cloudinit.CloudConfig , error ) {
338+ return cloudinit .NewInitControlPlane (& cloudinit.ControlPlaneInitInput {
339+ BootCommands : []string {"cmd1" },
340+ PreRunCommands : []string {"cmd2" },
341+ PostRunCommands : []string {"cmd3" },
342+ KubernetesVersion : "v1.25.0" ,
343+ Token : strings .Repeat ("a" , 32 ),
344+ TokenTTL : 100 ,
345+ })
346+ },
347+ },
348+ {
349+ name : "ControlPlaneJoin" ,
350+ makeCloudConfig : func () (* cloudinit.CloudConfig , error ) {
351+ return cloudinit .NewJoinControlPlane (& cloudinit.ControlPlaneJoinInput {
352+ BootCommands : []string {"cmd1" },
353+ PreRunCommands : []string {"cmd2" },
354+ PostRunCommands : []string {"cmd3" },
355+ KubernetesVersion : "v1.25.0" ,
356+ Token : strings .Repeat ("a" , 32 ),
357+ TokenTTL : 100 ,
358+ })
359+ },
360+ },
361+ {
362+ name : "Worker" ,
363+ makeCloudConfig : func () (* cloudinit.CloudConfig , error ) {
364+ return cloudinit .NewJoinWorker (& cloudinit.WorkerInput {
365+ BootCommands : []string {"cmd1" },
366+ PreRunCommands : []string {"cmd2" },
367+ PostRunCommands : []string {"cmd3" },
368+ KubernetesVersion : "v1.25.0" ,
369+ Token : strings .Repeat ("a" , 32 ),
370+ })
371+ },
372+ },
373+ } {
374+ t .Run (tc .name , func (t * testing.T ) {
375+ g := NewWithT (t )
376+ c , err := tc .makeCloudConfig ()
377+ g .Expect (err ).NotTo (HaveOccurred ())
378+
379+ g .Expect (c .BootCommands ).To (ConsistOf (`cmd1` ))
380+ g .Expect (c .RunCommands ).To (ContainElement (`cmd2` ))
381+ g .Expect (c .RunCommands [len (c .RunCommands )- 1 ]).To (Equal (`cmd3` ))
382+ })
383+ }
384+ })
329385}
0 commit comments