vendor: update all dependencies
This commit is contained in:
+32
-18
@@ -18,26 +18,27 @@ import (
|
||||
"log"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
ltesting "cloud.google.com/go/logging/internal/testing"
|
||||
"cloud.google.com/go/internal/testutil"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/api/iterator"
|
||||
itesting "google.golang.org/api/iterator/testing"
|
||||
)
|
||||
|
||||
const testMetricIDPrefix = "GO-CLIENT-TEST-METRIC"
|
||||
var metricIDs = testutil.NewUIDSpace("GO-CLIENT-TEST-METRIC")
|
||||
|
||||
// Initializes the tests before they run.
|
||||
func initMetrics(ctx context.Context) {
|
||||
// Clean up from aborted tests.
|
||||
var IDs []string
|
||||
it := client.Metrics(ctx)
|
||||
loop:
|
||||
for {
|
||||
m, err := it.Next()
|
||||
switch err {
|
||||
case nil:
|
||||
IDs = append(IDs, m.ID)
|
||||
if metricIDs.Older(m.ID, 24*time.Hour) {
|
||||
client.DeleteMetric(ctx, m.ID)
|
||||
}
|
||||
case iterator.Done:
|
||||
break loop
|
||||
default:
|
||||
@@ -45,15 +46,12 @@ loop:
|
||||
return
|
||||
}
|
||||
}
|
||||
for _, mID := range ltesting.ExpiredUniqueIDs(IDs, testMetricIDPrefix) {
|
||||
client.DeleteMetric(ctx, mID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateDeleteMetric(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
metric := &Metric{
|
||||
ID: ltesting.UniqueID(testMetricIDPrefix),
|
||||
ID: metricIDs.New(),
|
||||
Description: "DESC",
|
||||
Filter: "FILTER",
|
||||
}
|
||||
@@ -82,7 +80,7 @@ func TestCreateDeleteMetric(t *testing.T) {
|
||||
func TestUpdateMetric(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
metric := &Metric{
|
||||
ID: ltesting.UniqueID(testMetricIDPrefix),
|
||||
ID: metricIDs.New(),
|
||||
Description: "DESC",
|
||||
Filter: "FILTER",
|
||||
}
|
||||
@@ -118,12 +116,15 @@ func TestListMetrics(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
var metrics []*Metric
|
||||
want := map[string]*Metric{}
|
||||
for i := 0; i < 10; i++ {
|
||||
metrics = append(metrics, &Metric{
|
||||
ID: ltesting.UniqueID(testMetricIDPrefix),
|
||||
m := &Metric{
|
||||
ID: metricIDs.New(),
|
||||
Description: "DESC",
|
||||
Filter: "FILTER",
|
||||
})
|
||||
}
|
||||
metrics = append(metrics, m)
|
||||
want[m.ID] = m
|
||||
}
|
||||
for _, m := range metrics {
|
||||
if err := client.CreateMetric(ctx, m); err != nil {
|
||||
@@ -132,10 +133,23 @@ func TestListMetrics(t *testing.T) {
|
||||
defer client.DeleteMetric(ctx, m.ID)
|
||||
}
|
||||
|
||||
msg, ok := itesting.TestIterator(metrics,
|
||||
func() interface{} { return client.Metrics(ctx) },
|
||||
func(it interface{}) (interface{}, error) { return it.(*MetricIterator).Next() })
|
||||
if !ok {
|
||||
t.Fatal(msg)
|
||||
got := map[string]*Metric{}
|
||||
it := client.Metrics(ctx)
|
||||
for {
|
||||
m, err := it.Next()
|
||||
if err == iterator.Done {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// If tests run simultaneously, we may have more metrics than we
|
||||
// created. So only check for our own.
|
||||
if _, ok := want[m.ID]; ok {
|
||||
got[m.ID] = m
|
||||
}
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("got %+v, want %+v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user