2020-08-25 18:42:54 +00:00
|
|
|
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package tstest
|
|
|
|
|
2020-09-04 15:09:56 +00:00
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
2020-08-25 18:42:54 +00:00
|
|
|
|
2020-09-04 15:09:56 +00:00
|
|
|
func TestLogLineTracker(t *testing.T) {
|
|
|
|
const (
|
2020-08-25 18:42:54 +00:00
|
|
|
l1 = "line 1: %s"
|
|
|
|
l2 = "line 2: %s"
|
|
|
|
l3 = "line 3: %s"
|
|
|
|
)
|
|
|
|
|
2020-09-04 15:09:56 +00:00
|
|
|
lt := NewLogLineTracker(t.Logf, []string{l1, l2})
|
2020-08-25 18:42:54 +00:00
|
|
|
|
2020-09-04 15:09:56 +00:00
|
|
|
if got, want := lt.Check(), []string{l1, l2}; !reflect.DeepEqual(got, want) {
|
|
|
|
t.Errorf("Check = %q; want %q", got, want)
|
2020-08-25 18:42:54 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 15:09:56 +00:00
|
|
|
lt.Logf(l3, "hi")
|
2020-08-25 18:42:54 +00:00
|
|
|
|
2020-09-04 15:09:56 +00:00
|
|
|
if got, want := lt.Check(), []string{l1, l2}; !reflect.DeepEqual(got, want) {
|
|
|
|
t.Errorf("Check = %q; want %q", got, want)
|
2020-08-25 18:42:54 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 15:09:56 +00:00
|
|
|
lt.Logf(l1, "hi")
|
2020-08-25 18:42:54 +00:00
|
|
|
|
2020-09-04 15:09:56 +00:00
|
|
|
if got, want := lt.Check(), []string{l2}; !reflect.DeepEqual(got, want) {
|
|
|
|
t.Errorf("Check = %q; want %q", got, want)
|
2020-08-25 18:42:54 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 15:09:56 +00:00
|
|
|
lt.Logf(l1, "bye")
|
2020-08-25 18:42:54 +00:00
|
|
|
|
2020-09-04 15:09:56 +00:00
|
|
|
if got, want := lt.Check(), []string{l2}; !reflect.DeepEqual(got, want) {
|
|
|
|
t.Errorf("Check = %q; want %q", got, want)
|
2020-08-25 18:42:54 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 15:09:56 +00:00
|
|
|
lt.Logf(l2, "hi")
|
|
|
|
|
|
|
|
if got, want := lt.Check(), []string(nil); !reflect.DeepEqual(got, want) {
|
|
|
|
t.Errorf("Check = %q; want %q", got, want)
|
2020-08-25 18:42:54 +00:00
|
|
|
}
|
|
|
|
}
|