vendor: update all dependencies
This commit is contained in:
+9
@@ -28,3 +28,12 @@ func LogPath(parent, logID string) string {
|
||||
logID = strings.Replace(logID, "/", "%2F", -1)
|
||||
return fmt.Sprintf("%s/logs/%s", parent, logID)
|
||||
}
|
||||
|
||||
func LogIDFromPath(parent, path string) string {
|
||||
start := len(parent) + len("/logs/")
|
||||
if len(path) < start {
|
||||
return ""
|
||||
}
|
||||
logID := path[start:]
|
||||
return strings.Replace(logID, "%2F", "/", -1)
|
||||
}
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Copyright 2017 Google Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package testing
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
// Compare two payloads, assuming they are both proto.Messages
|
||||
// or both strings.
|
||||
func PayloadEqual(a, b interface{}) bool {
|
||||
if a == nil && b == nil {
|
||||
return true
|
||||
}
|
||||
if a == nil || b == nil {
|
||||
return false
|
||||
}
|
||||
switch a := a.(type) {
|
||||
case proto.Message:
|
||||
return proto.Equal(a, b.(proto.Message))
|
||||
case string:
|
||||
return a == b.(string)
|
||||
default:
|
||||
panic(fmt.Sprintf("payloadEqual: unexpected type %T", a))
|
||||
}
|
||||
}
|
||||
+14
-4
@@ -264,6 +264,20 @@ func (h *loggingHandler) ListMonitoredResourceDescriptors(context.Context, *logp
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Lists logs.
|
||||
func (h *loggingHandler) ListLogs(_ context.Context, req *logpb.ListLogsRequest) (*logpb.ListLogsResponse, error) {
|
||||
// Return fixed, fake response.
|
||||
logNames := []string{"a", "b", "c"}
|
||||
from, to, npt, err := getPage(int(req.PageSize), req.PageToken, len(logNames))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &logpb.ListLogsResponse{
|
||||
LogNames: logNames[from:to],
|
||||
NextPageToken: npt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Gets a sink.
|
||||
func (h *configHandler) GetSink(_ context.Context, req *logpb.GetSinkRequest) (*logpb.LogSink, error) {
|
||||
h.mu.Lock()
|
||||
@@ -323,8 +337,6 @@ func (h *configHandler) ListSinks(_ context.Context, req *logpb.ListSinksRequest
|
||||
Sinks: sinks[from:to],
|
||||
NextPageToken: nextPageToken,
|
||||
}, nil
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
type sinksByName []*logpb.LogSink
|
||||
@@ -392,8 +404,6 @@ func (h *metricHandler) ListLogMetrics(_ context.Context, req *logpb.ListLogMetr
|
||||
Metrics: metrics[from:to],
|
||||
NextPageToken: nextPageToken,
|
||||
}, nil
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
type metricsByName []*logpb.LogMetric
|
||||
|
||||
+14
-2
@@ -20,10 +20,10 @@ limitations under the License.
|
||||
package testing
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
tspb "github.com/golang/protobuf/ptypes/timestamp"
|
||||
logpb "google.golang.org/genproto/googleapis/logging/v2"
|
||||
grpc "google.golang.org/grpc"
|
||||
@@ -103,8 +103,20 @@ func TestSortEntries(t *testing.T) {
|
||||
for i, j := range test.want {
|
||||
want[i] = entries[j]
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
if !logEntriesEqual(got, want) {
|
||||
t.Errorf("%q: got %v, want %v", test.orderBy, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func logEntriesEqual(a, b []*logpb.LogEntry) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
for i, aa := range a {
|
||||
if !proto.Equal(aa, b[i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
-73
@@ -1,73 +0,0 @@
|
||||
// Copyright 2016 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// This file supports generating unique IDs so that multiple test executions
|
||||
// don't interfere with each other, and cleaning up old entities that may
|
||||
// remain if tests exit early.
|
||||
|
||||
package testing
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
startTime = time.Now()
|
||||
uniqueIDCounter int
|
||||
// Items older than expiredAge are remnants from previous tests and can be deleted.
|
||||
expiredAge = 24 * time.Hour
|
||||
)
|
||||
|
||||
// UniqueID generates unique IDs so tests don't interfere with each other.
|
||||
// All unique IDs generated in the same test execution will have the same timestamp.
|
||||
func UniqueID(prefix string) string {
|
||||
uniqueIDCounter++
|
||||
// Zero-pad the counter for lexical sort order.
|
||||
return fmt.Sprintf("%s-t%d-%04d", prefix, startTime.UnixNano(), uniqueIDCounter)
|
||||
}
|
||||
|
||||
// ExpiredUniqueIDs returns a subset of ids that are unique IDs as generated by
|
||||
// UniqueID(prefix) and are older than expiredAge.
|
||||
func ExpiredUniqueIDs(ids []string, prefix string) []string {
|
||||
var expired []string
|
||||
for _, id := range ids {
|
||||
t, ok := extractTime(id, prefix)
|
||||
if ok && time.Since(t) > expiredAge {
|
||||
expired = append(expired, id)
|
||||
}
|
||||
}
|
||||
return expired
|
||||
}
|
||||
|
||||
// extractTime extracts the timestamp of s, which must begin with prefix and
|
||||
// match the form generated by uniqueID. The second return value is true on
|
||||
// success, false if there was a problem.
|
||||
func extractTime(s, prefix string) (time.Time, bool) {
|
||||
if !strings.HasPrefix(s, prefix+"-t") {
|
||||
return time.Time{}, false
|
||||
}
|
||||
s = s[len(prefix)+2:]
|
||||
i := strings.Index(s, "-")
|
||||
if i < 0 {
|
||||
return time.Time{}, false
|
||||
}
|
||||
nanos, err := strconv.ParseInt(s[:i], 10, 64)
|
||||
if err != nil {
|
||||
return time.Time{}, false
|
||||
}
|
||||
return time.Unix(0, nanos), true
|
||||
}
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
// Copyright 2016 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// This file supports generating unique IDs so that multiple test executions
|
||||
// don't interfere with each other, and cleaning up old entities that may
|
||||
// remain if tests exit early.
|
||||
|
||||
package testing
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestExtractTime(t *testing.T) {
|
||||
uid := UniqueID("unique-ID")
|
||||
got, ok := extractTime(uid, "unique-ID")
|
||||
if !ok {
|
||||
t.Fatal("got ok = false, want true")
|
||||
}
|
||||
if !startTime.Equal(got) {
|
||||
t.Errorf("got %s, want %s", got, startTime)
|
||||
}
|
||||
|
||||
got, ok = extractTime("p-t0-doesnotmatter", "p")
|
||||
if !ok {
|
||||
t.Fatal("got false, want true")
|
||||
}
|
||||
if want := time.Unix(0, 0); !want.Equal(got) {
|
||||
t.Errorf("got %s, want %s", got, want)
|
||||
}
|
||||
if _, ok = extractTime("invalid-time-1234", "invalid"); ok {
|
||||
t.Error("got true, want false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpiredUniqueIDs(t *testing.T) {
|
||||
const prefix = "uid"
|
||||
// The freshly unique IDs will have startTime as their timestamp.
|
||||
uids := []string{UniqueID(prefix), "uid-tinvalid-1234", UniqueID(prefix), "uid-t0-1111"}
|
||||
|
||||
// This test hasn't been running for very long, so only the last ID is expired.
|
||||
got := ExpiredUniqueIDs(uids, prefix)
|
||||
want := []string{uids[3]}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("got %v, want %v", got, want)
|
||||
}
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
prev := expiredAge
|
||||
expiredAge = 10 * time.Millisecond
|
||||
defer func() { expiredAge = prev }()
|
||||
// This test has been running for at least 10ms, so all but the invalid ID have expired.
|
||||
got = ExpiredUniqueIDs(uids, prefix)
|
||||
want = []string{uids[0], uids[2], uids[3]}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("got %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user