Skip to content

Commit

Permalink
add tests for no-keepalive
Browse files Browse the repository at this point in the history
  • Loading branch information
petersutter committed Mar 20, 2023
1 parent a96cd2e commit c44c05f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/cmd/ssh/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ var (

return cmd.Run()
}

// waitForSignal informs the user about their SSHOptions and keeps the
// bastion alive until gardenctl exits.
waitForSignal = func(ctx context.Context, o *SSHOptions, shootClient client.Client, bastion *operationsv1alpha1.Bastion, nodeHostname string, nodePrivateKeyFiles []string, signalChan <-chan struct{}) error {
Expand Down
49 changes: 49 additions & 0 deletions pkg/cmd/ssh/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,33 @@ var _ = Describe("SSH Command", func() {

Expect(logs).To(ContainSubstring("Bastion is ready, skipping availability check"))
})

It("should not keep alive the bastion", func() {
options := ssh.NewSSHOptions(streams)
options.NoKeepalive = true
options.KeepBastion = true
options.Interactive = false

cmd := ssh.NewCmdSSH(factory, options)

ssh.SetWaitForSignal(func(ctx context.Context, o *ssh.SSHOptions, shootClient client.Client, bastion *operationsv1alpha1.Bastion, nodeHostname string, nodePrivateKeyFiles []string, signalChan <-chan struct{}) error {
err := errors.New("this function should not be executed as of NoKeepalive = true")
Fail(err.Error())
return err
})
ssh.SetExecCommand(func(ctx context.Context, command string, args []string, o *ssh.SSHOptions) error {
err := errors.New("this function should not be executed as of NoKeepalive = true")
Fail(err.Error())
return err
})

// simulate an external controller processing the bastion and proving a successful status
go waitForBastionThenSetBastionReady(ctx, gardenClient, bastionName, *testProject.Spec.Namespace, bastionHostname, bastionIP)

Expect(cmd.RunE(cmd, nil)).To(Succeed())

Expect(logs).To(ContainSubstring("Bastion host became available."))
})
})

Describe("ValidArgsFunction", func() {
Expand Down Expand Up @@ -598,6 +625,28 @@ var _ = Describe("SSH Options", func() {
Expect(o.Validate()).NotTo(Succeed())
})

Context("no-keepalive", func() {
It("should require non-interactive mode", func() {
o := ssh.NewSSHOptions(streams)
o.NoKeepalive = true
o.KeepBastion = true

o.Interactive = true

Expect(o.Validate()).NotTo(Succeed())
})

It("should require keep bastion", func() {
o := ssh.NewSSHOptions(streams)
o.NoKeepalive = true
o.Interactive = false

o.KeepBastion = false

Expect(o.Validate()).NotTo(Succeed())
})
})

It("should require a public SSH key file", func() {
o := ssh.NewSSHOptions(streams)
o.CIDRs = []string{"8.8.8.8/32"}
Expand Down

0 comments on commit c44c05f

Please sign in to comment.