diff --git a/pkg/minikube/cluster/cluster_test.go b/pkg/minikube/cluster/cluster_test.go index 42d7129cbf01f38ac450523f7c1bbde67b228ed4..a6645c852c86bd795625031921a9a2c63a8e1852 100644 --- a/pkg/minikube/cluster/cluster_test.go +++ b/pkg/minikube/cluster/cluster_test.go @@ -520,7 +520,7 @@ func TestCreateSSHShell(t *testing.T) { t.Fatalf("Error running ssh command: %s", err) } - if !s.HadASessionRequested { + if !s.IsSessionRequested() { t.Fatalf("Expected ssh session to be run") } } diff --git a/pkg/minikube/tests/ssh_mock.go b/pkg/minikube/tests/ssh_mock.go index f5c7b11ba73147e0b591d6c497af4ea551e0cf17..61b142f9c91fbdcc793b9041e57af4f30ff0b0c3 100644 --- a/pkg/minikube/tests/ssh_mock.go +++ b/pkg/minikube/tests/ssh_mock.go @@ -23,6 +23,7 @@ import ( "io" "net" "strconv" + "sync/atomic" "github.com/golang/glog" "github.com/pkg/errors" @@ -33,10 +34,11 @@ import ( type SSHServer struct { Config *ssh.ServerConfig // Commands stores the raw commands executed against the server. - Commands map[string]int - Connected bool - Transfers *bytes.Buffer - HadASessionRequested bool + Commands map[string]int + Connected bool + Transfers *bytes.Buffer + // Only access this with atomic ops + hadASessionRequested int32 // CommandsToOutput can be used to mock what the SSHServer returns for a given command CommandToOutput map[string]string } @@ -59,6 +61,7 @@ func NewSSHServer() (*SSHServer, error) { return nil, errors.Wrap(err, "Error creating signer from key") } s.Config.AddHostKey(signer) + s.SetSessionRequested(false) return s, nil } @@ -92,7 +95,7 @@ func (s *SSHServer) Start() (int, error) { // Service the incoming Channel channel. for newChannel := range chans { if newChannel.ChannelType() == "session" { - s.HadASessionRequested = true + s.SetSessionRequested(true) } channel, requests, err := newChannel.Accept() s.Connected = true @@ -136,3 +139,15 @@ func (s *SSHServer) Start() (int, error) { } return port, nil } + +func (s *SSHServer) SetSessionRequested(b bool) { + var i int32 + if b { + i = 1 + } + atomic.StoreInt32(&s.hadASessionRequested, i) +} + +func (s *SSHServer) IsSessionRequested() bool { + return atomic.LoadInt32(&s.hadASessionRequested) != 0 +}