sshchat: Fix tests to use new rendering format.

This commit is contained in:
Andrey Petrov 2019-03-21 13:39:33 -04:00
parent 418c991677
commit 9d2230eaff
2 changed files with 10 additions and 10 deletions

View File

@ -26,7 +26,7 @@ debug: $(BINARY) $(KEY)
./$(BINARY) --pprof 6060 -i $(KEY) --bind ":$(PORT)" -vv
test:
go test ./...
go test -race -test.timeout 5s ./...
release:
# We use static linking for release build. LDFLAGS via

View File

@ -225,7 +225,7 @@ func TestHostKick(t *testing.T) {
scanner := bufio.NewScanner(r)
// Consume the initial buffer
scanner.Scan()
scanner.Scan() // Joined
// Make op
member, _ := host.Room.MemberByID("foo")
@ -237,19 +237,14 @@ func TestHostKick(t *testing.T) {
// Change nicks, make sure op sticks
w.Write([]byte("/nick quux\r\n"))
scanner.Scan() // Prompt
scanner.Scan() // Prompt echo
scanner.Scan() // Nick change response
// Signal for the second client to connect
connected <- struct{}{}
// Block until second client is here
connected <- struct{}{}
scanner.Scan() // Connected message
w.Write([]byte("/kick bar\r\n"))
scanner.Scan() // Prompt
scanner.Scan() // Prompt echo
scanner.Scan() // Kick result
if actual, expected := stripPrompt(scanner.Text()), " * bar was kicked by quux.\r"; actual != expected {
@ -264,12 +259,11 @@ func TestHostKick(t *testing.T) {
connected <- struct{}{}
close(connected)
t.Fatal(err)
close(done)
}
}()
go func() {
<-connected
// Second client
err := sshd.ConnectShell(addr, "bar", func(r io.Reader, w io.WriteCloser) error {
scanner := bufio.NewScanner(r)
@ -278,10 +272,16 @@ func TestHostKick(t *testing.T) {
<-kicked
if _, err := w.Write([]byte("am I still here?\r\n")); err != nil {
return err
}
scanner.Scan()
return scanner.Err()
})
if err != nil {
if err == io.EOF {
// All good, we got kicked.
} else if err != nil {
close(done)
t.Fatal(err)
}