diff --git a/logging/logadmin/logadmin_test.go b/logging/logadmin/logadmin_test.go index 0407b7e5f1d..d29d8e91d4a 100644 --- a/logging/logadmin/logadmin_test.go +++ b/logging/logadmin/logadmin_test.go @@ -30,7 +30,6 @@ import ( "cloud.google.com/go/internal/testutil" "cloud.google.com/go/logging" ltesting "cloud.google.com/go/logging/internal/testing" - "github.com/golang/protobuf/proto" "github.com/golang/protobuf/ptypes" durpb "github.com/golang/protobuf/ptypes/duration" structpb "github.com/golang/protobuf/ptypes/struct" @@ -269,11 +268,11 @@ func TestListLogEntriesRequestDefaults(t *testing.T) { // parse time from filter if len(got.Filter) < len(timeFilterPrefix) { - t.Errorf("expect default filter to start with %v; got %v", timeFilterPrefix, got.Filter) + t.Errorf("got %v; want len(%v) start with '%v'", got, got.Filter, timeFilterPrefix) } - filterTime, e := time.Parse(time.RFC3339, strings.Trim(got.Filter[len(timeFilterPrefix):], "\"")) - if e != nil { - t.Errorf("expect default filter to have time in RFC3339; got %v", got.Filter) + filterTime, err := time.Parse(time.RFC3339, strings.Trim(got.Filter[len(timeFilterPrefix):], "\"")) + if err != nil { + t.Errorf("%v: expect default filter to have time in RFC3339; got %v", err, got.Filter) } timeDiff := time.Now().UTC().Sub(filterTime) @@ -287,35 +286,34 @@ func TestListLogEntriesRequest(t *testing.T) { for _, test := range []struct { opts []EntriesOption resourceNames []string - filter string filterPrefix string orderBy string }{ // Timestamp default does not override user's filter {[]EntriesOption{NewestFirst(), Filter(`timestamp > "2020-10-30T15:39:09Z"`)}, - []string{"projects/PROJECT_ID"}, `timestamp > "2020-10-30T15:39:09Z"`, "", "timestamp desc"}, + []string{"projects/PROJECT_ID"}, `timestamp > "2020-10-30T15:39:09Z"`, "timestamp desc"}, {[]EntriesOption{NewestFirst(), Filter("f")}, - []string{"projects/PROJECT_ID"}, "", "f AND timestamp >= \"", "timestamp desc"}, + []string{"projects/PROJECT_ID"}, "f AND timestamp >= \"", "timestamp desc"}, {[]EntriesOption{ProjectIDs([]string{"foo"})}, - []string{"projects/foo"}, "", "timestamp >= \"", ""}, + []string{"projects/foo"}, "timestamp >= \"", ""}, {[]EntriesOption{ResourceNames([]string{"folders/F", "organizations/O"})}, - []string{"folders/F", "organizations/O"}, "", "timestamp >= \"", ""}, + []string{"folders/F", "organizations/O"}, "timestamp >= \"", ""}, {[]EntriesOption{NewestFirst(), Filter("f"), ProjectIDs([]string{"foo"})}, - []string{"projects/foo"}, "", "f AND timestamp >= \"", "timestamp desc"}, + []string{"projects/foo"}, "f AND timestamp >= \"", "timestamp desc"}, {[]EntriesOption{NewestFirst(), Filter("f"), ProjectIDs([]string{"foo"})}, - []string{"projects/foo"}, "", "f AND timestamp >= \"", "timestamp desc"}, + []string{"projects/foo"}, "f AND timestamp >= \"", "timestamp desc"}, // If there are repeats, last one wins. {[]EntriesOption{NewestFirst(), Filter("no"), ProjectIDs([]string{"foo"}), Filter("f")}, - []string{"projects/foo"}, "", "f AND timestamp >= \"", "timestamp desc"}, + []string{"projects/foo"}, "f AND timestamp >= \"", "timestamp desc"}, } { got := listLogEntriesRequest("projects/PROJECT_ID", test.opts) want := &logpb.ListLogEntriesRequest{ ResourceNames: test.resourceNames, - Filter: test.filter, + Filter: test.filterPrefix, OrderBy: test.orderBy, } - if (test.filterPrefix == "" && !proto.Equal(got, want)) || !strings.HasPrefix(got.Filter, test.filterPrefix) || got.OrderBy != test.orderBy || !testutil.Equal(got.ResourceNames, test.resourceNames) { - t.Errorf("%v:\ngot %v\nwant %v", test.opts, got, want) + if !testutil.Equal(got.ResourceNames, want.ResourceNames) || !strings.HasPrefix(got.Filter, want.Filter) || got.OrderBy != want.OrderBy { + t.Errorf("got: %v; want %v (mind wanted Filter is prefix)", got, want) } } }