Skip to content

Commit

Permalink
Add patch to stop tests flaking while using host machines termainal.
Browse files Browse the repository at this point in the history
Patch the "getTerminal" with nil to stop the terminal of the host
machine being used by default.
  • Loading branch information
Aflynn50 committed Mar 8, 2024
1 parent ee7235a commit da0f68e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 6 additions & 0 deletions ssh/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ func PatchTerminal(s *testing.CleanupSuite, rlw ReadLineWriter) {
c.Assert(atomic.LoadInt64(&balance), gc.Equals, int64(0))
})
}

func PatchNilTerminal(s *testing.CleanupSuite) {
s.PatchValue(&getTerminal, func() (readLineWriter, func(), error) {
return nil, func() {}, nil
})
}
5 changes: 1 addition & 4 deletions ssh/ssh_gocrypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,9 @@ func (s *SSHGoCryptoCommandSuite) SetUpTest(c *gc.C) {
generateKeyRestorer := overrideGenerateKey(c)
s.AddCleanup(func(*gc.C) { generateKeyRestorer.Restore() })

client, err := ssh.NewGoCryptoClient()
c.Assert(err, jc.ErrorIsNil)
s.client = client

s.knownHostsFile = filepath.Join(c.MkDir(), "known_hosts")
ssh.SetGoCryptoKnownHostsFile(s.knownHostsFile)
ssh.PatchNilTerminal(&s.CleanupSuite)
}

func (s *SSHGoCryptoCommandSuite) newServer(c *gc.C, serverConfig cryptossh.ServerConfig) (*sshServer, cryptossh.PublicKey) {
Expand Down

0 comments on commit da0f68e

Please sign in to comment.