2023-01-27 13:37:20 -08:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2020-08-25 12:42:54 -06:00
|
|
|
|
|
|
|
package tstest
|
|
|
|
|
2020-09-04 08:09:56 -07:00
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
2020-08-25 12:42:54 -06:00
|
|
|
|
2020-09-04 08:09:56 -07:00
|
|
|
func TestLogLineTracker(t *testing.T) {
|
|
|
|
const (
|
2020-08-25 12:42:54 -06:00
|
|
|
l1 = "line 1: %s"
|
|
|
|
l2 = "line 2: %s"
|
|
|
|
l3 = "line 3: %s"
|
|
|
|
)
|
|
|
|
|
2020-09-04 08:09:56 -07:00
|
|
|
lt := NewLogLineTracker(t.Logf, []string{l1, l2})
|
2020-08-25 12:42:54 -06:00
|
|
|
|
2020-09-04 08:09:56 -07:00
|
|
|
if got, want := lt.Check(), []string{l1, l2}; !reflect.DeepEqual(got, want) {
|
|
|
|
t.Errorf("Check = %q; want %q", got, want)
|
2020-08-25 12:42:54 -06:00
|
|
|
}
|
|
|
|
|
2020-09-04 08:09:56 -07:00
|
|
|
lt.Logf(l3, "hi")
|
2020-08-25 12:42:54 -06:00
|
|
|
|
2020-09-04 08:09:56 -07:00
|
|
|
if got, want := lt.Check(), []string{l1, l2}; !reflect.DeepEqual(got, want) {
|
|
|
|
t.Errorf("Check = %q; want %q", got, want)
|
2020-08-25 12:42:54 -06:00
|
|
|
}
|
|
|
|
|
2020-09-04 08:09:56 -07:00
|
|
|
lt.Logf(l1, "hi")
|
2020-08-25 12:42:54 -06:00
|
|
|
|
2020-09-04 08:09:56 -07:00
|
|
|
if got, want := lt.Check(), []string{l2}; !reflect.DeepEqual(got, want) {
|
|
|
|
t.Errorf("Check = %q; want %q", got, want)
|
2020-08-25 12:42:54 -06:00
|
|
|
}
|
|
|
|
|
2020-09-04 08:09:56 -07:00
|
|
|
lt.Logf(l1, "bye")
|
2020-08-25 12:42:54 -06:00
|
|
|
|
2020-09-04 08:09:56 -07:00
|
|
|
if got, want := lt.Check(), []string{l2}; !reflect.DeepEqual(got, want) {
|
|
|
|
t.Errorf("Check = %q; want %q", got, want)
|
2020-08-25 12:42:54 -06:00
|
|
|
}
|
|
|
|
|
2020-09-04 08:09:56 -07: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 12:42:54 -06:00
|
|
|
}
|
|
|
|
}
|