Newer
Older
func TestReadFromCommand(t *testing.T) {
strs := []string{}
pusher: func(s []byte) bool { strs = append(strs, string(s)); return true },
eventBox: eb,
event: int32(EvtReady)}
reader.startEventPoller()
reader.fin(reader.readFromCommand("sh", `echo abc && echo def`))
if len(strs) != 2 || strs[0] != "abc" || strs[1] != "def" {
t.Errorf("%s", strs)
}
// Check EventBox again
// Make sure that event poller is finished
time.Sleep(readerPollIntervalMax)
// Restart event poller
reader.startEventPoller()
reader.fin(reader.readFromCommand("sh", `no-such-command`))
strs = []string{}
if len(strs) > 0 {
t.Errorf("%s", strs)
}
// Check EventBox again
t.Error("Command failed. EvtReadNew should not be set")
}
if !eb.Peek(EvtReadFin) {
t.Error("EvtReadFin should be set")