in pkg/mgmapi/fake_mgm_server.go [44:74]
func (fmc *fakeMgmServer) run(replies ...[]byte) {
// Emulate the fake Management Server in a go routine
go func() {
// Consume the command sent by the client
scanner := bufio.NewScanner(fmc.connection)
text := "nil"
// Command ends when an empty line is read
for text != "" && scanner.Scan() {
text = scanner.Text()
}
if err := scanner.Err(); err != nil {
fmc.t.Errorf("Fake Mgm Server failed to read request from the client : %s", err)
return
}
// Send the replies back to client
for _, reply := range replies {
if _, err := fmc.connection.Write(reply); err != nil {
fmc.t.Errorf("Fake Mgm Server failed to send reply to the client : %s", err)
return
}
}
// Send empty line to mark end of reply
if _, err := fmc.connection.Write([]byte("\n\n")); err != nil {
fmc.t.Errorf("Fake Mgm Server failed to send reply to the client : %s", err)
return
}
}()
}