| 180 | } |
| 181 | |
| 182 | func TestMessagef(t *testing.T) { |
| 183 | buf := new(bytes.Buffer) |
| 184 | SetOutput(buf) |
| 185 | defer SetOutput(os.Stdout) |
| 186 | |
| 187 | Printf(context.Background(), "test round %d", 0) |
| 188 | |
| 189 | read, err := ioutil.ReadAll(buf) |
| 190 | if err != nil { |
| 191 | t.Fatal("read buffer error:", err) |
| 192 | } |
| 193 | |
| 194 | got := string(read) |
| 195 | want := []string{ |
| 196 | "at=log_test.go:", |
| 197 | `message="test round 0"`, |
| 198 | } |
| 199 | |
| 200 | for _, w := range want { |
| 201 | if !strings.Contains(got, w) { |
| 202 | t.Errorf("Result did not contain string:\ngot: %s\nwant: %s", got, w) |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | func TestPrintkvStack(t *testing.T) { |
| 208 | buf := new(bytes.Buffer) |