ExpectPattern reads a line from the connection socket and checks whether is matches the supplied shell pattern (as defined by path.Match). The original line is returned.
(pat string)
| 128 | // matches the supplied shell pattern (as defined by path.Match). The original |
| 129 | // line is returned. |
| 130 | func (c *Conn) ExpectPattern(pat string) string { |
| 131 | c.T.Helper() |
| 132 | |
| 133 | line, err := c.Readln() |
| 134 | if err != nil { |
| 135 | c.T.Fatal("Unexpected I/O error:", err) |
| 136 | } |
| 137 | |
| 138 | match, err := path.Match(pat, line) |
| 139 | if err != nil { |
| 140 | c.T.Fatal("Malformed pattern:", err) |
| 141 | } |
| 142 | if !match { |
| 143 | c.T.Fatalf("Response line not matching the expected pattern, want %q", pat) |
| 144 | } |
| 145 | |
| 146 | return line |
| 147 | } |
| 148 | |
| 149 | func (c *Conn) fatal(f string, args ...interface{}) { |
| 150 | c.T.Helper() |