vendor: update all dependencies
This commit is contained in:
+66
@@ -0,0 +1,66 @@
|
||||
// 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.
|
||||
|
||||
// AUTO-GENERATED CODE. DO NOT EDIT.
|
||||
|
||||
package logging
|
||||
|
||||
import (
|
||||
loggingpb "google.golang.org/genproto/googleapis/logging/v2"
|
||||
)
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"cloud.google.com/go/internal/testutil"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/api/iterator"
|
||||
"google.golang.org/api/option"
|
||||
)
|
||||
|
||||
var _ = iterator.Done
|
||||
var _ = strconv.FormatUint
|
||||
var _ = time.Now
|
||||
|
||||
func TestLoggingServiceV2Smoke(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping smoke test in short mode")
|
||||
}
|
||||
ctx := context.Background()
|
||||
ts := testutil.TokenSource(ctx, DefaultAuthScopes()...)
|
||||
if ts == nil {
|
||||
t.Skip("Integration tests skipped. See CONTRIBUTING.md for details")
|
||||
}
|
||||
|
||||
projectId := testutil.ProjID()
|
||||
_ = projectId
|
||||
|
||||
c, err := NewClient(ctx, option.WithTokenSource(ts))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var entries []*loggingpb.LogEntry = nil
|
||||
var formattedLogName string = LogPath(projectId, "test-"+strconv.FormatInt(time.Now().UnixNano(), 10)+"")
|
||||
var request = &loggingpb.WriteLogEntriesRequest{
|
||||
Entries: entries,
|
||||
LogName: formattedLogName,
|
||||
}
|
||||
|
||||
if _, err := c.WriteLogEntries(ctx, request); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
+30
-41
@@ -48,13 +48,7 @@ type ConfigCallOptions struct {
|
||||
func defaultConfigClientOptions() []option.ClientOption {
|
||||
return []option.ClientOption{
|
||||
option.WithEndpoint("logging.googleapis.com:443"),
|
||||
option.WithScopes(
|
||||
"https://www.googleapis.com/auth/cloud-platform",
|
||||
"https://www.googleapis.com/auth/cloud-platform.read-only",
|
||||
"https://www.googleapis.com/auth/logging.admin",
|
||||
"https://www.googleapis.com/auth/logging.read",
|
||||
"https://www.googleapis.com/auth/logging.write",
|
||||
),
|
||||
option.WithScopes(DefaultAuthScopes()...),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,17 +58,7 @@ func defaultConfigCallOptions() *ConfigCallOptions {
|
||||
gax.WithRetry(func() gax.Retryer {
|
||||
return gax.OnCodes([]codes.Code{
|
||||
codes.DeadlineExceeded,
|
||||
codes.Unavailable,
|
||||
}, gax.Backoff{
|
||||
Initial: 100 * time.Millisecond,
|
||||
Max: 1000 * time.Millisecond,
|
||||
Multiplier: 1.2,
|
||||
})
|
||||
}),
|
||||
},
|
||||
{"default", "non_idempotent"}: {
|
||||
gax.WithRetry(func() gax.Retryer {
|
||||
return gax.OnCodes([]codes.Code{
|
||||
codes.Internal,
|
||||
codes.Unavailable,
|
||||
}, gax.Backoff{
|
||||
Initial: 100 * time.Millisecond,
|
||||
@@ -105,7 +89,7 @@ type ConfigClient struct {
|
||||
CallOptions *ConfigCallOptions
|
||||
|
||||
// The metadata to be sent with each request.
|
||||
xGoogHeader string
|
||||
xGoogHeader []string
|
||||
}
|
||||
|
||||
// NewConfigClient creates a new config service v2 client.
|
||||
@@ -143,8 +127,8 @@ func (c *ConfigClient) Close() error {
|
||||
// use by Google-written clients.
|
||||
func (c *ConfigClient) SetGoogleClientInfo(keyval ...string) {
|
||||
kv := append([]string{"gl-go", version.Go()}, keyval...)
|
||||
kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", "")
|
||||
c.xGoogHeader = gax.XGoogHeader(kv...)
|
||||
kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", grpc.Version)
|
||||
c.xGoogHeader = []string{gax.XGoogHeader(kv...)}
|
||||
}
|
||||
|
||||
// ConfigProjectPath returns the path for the project resource.
|
||||
@@ -171,8 +155,9 @@ func ConfigSinkPath(project, sink string) string {
|
||||
}
|
||||
|
||||
// ListSinks lists sinks.
|
||||
func (c *ConfigClient) ListSinks(ctx context.Context, req *loggingpb.ListSinksRequest) *LogSinkIterator {
|
||||
func (c *ConfigClient) ListSinks(ctx context.Context, req *loggingpb.ListSinksRequest, opts ...gax.CallOption) *LogSinkIterator {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
opts = append(c.CallOptions.ListSinks[0:len(c.CallOptions.ListSinks):len(c.CallOptions.ListSinks)], opts...)
|
||||
it := &LogSinkIterator{}
|
||||
it.InternalFetch = func(pageSize int, pageToken string) ([]*loggingpb.LogSink, string, error) {
|
||||
var resp *loggingpb.ListSinksResponse
|
||||
@@ -182,11 +167,11 @@ func (c *ConfigClient) ListSinks(ctx context.Context, req *loggingpb.ListSinksRe
|
||||
} else {
|
||||
req.PageSize = int32(pageSize)
|
||||
}
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
resp, err = c.configClient.ListSinks(ctx, req)
|
||||
resp, err = c.configClient.ListSinks(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.ListSinks...)
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
@@ -205,14 +190,15 @@ func (c *ConfigClient) ListSinks(ctx context.Context, req *loggingpb.ListSinksRe
|
||||
}
|
||||
|
||||
// GetSink gets a sink.
|
||||
func (c *ConfigClient) GetSink(ctx context.Context, req *loggingpb.GetSinkRequest) (*loggingpb.LogSink, error) {
|
||||
func (c *ConfigClient) GetSink(ctx context.Context, req *loggingpb.GetSinkRequest, opts ...gax.CallOption) (*loggingpb.LogSink, error) {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
opts = append(c.CallOptions.GetSink[0:len(c.CallOptions.GetSink):len(c.CallOptions.GetSink)], opts...)
|
||||
var resp *loggingpb.LogSink
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
resp, err = c.configClient.GetSink(ctx, req)
|
||||
resp, err = c.configClient.GetSink(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.GetSink...)
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -224,14 +210,15 @@ func (c *ConfigClient) GetSink(ctx context.Context, req *loggingpb.GetSinkReques
|
||||
// time is outside the sink's start and end times or the sink's
|
||||
// `writer_identity` is not permitted to write to the destination. A sink can
|
||||
// export log entries only from the resource owning the sink.
|
||||
func (c *ConfigClient) CreateSink(ctx context.Context, req *loggingpb.CreateSinkRequest) (*loggingpb.LogSink, error) {
|
||||
func (c *ConfigClient) CreateSink(ctx context.Context, req *loggingpb.CreateSinkRequest, opts ...gax.CallOption) (*loggingpb.LogSink, error) {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
opts = append(c.CallOptions.CreateSink[0:len(c.CallOptions.CreateSink):len(c.CallOptions.CreateSink)], opts...)
|
||||
var resp *loggingpb.LogSink
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
resp, err = c.configClient.CreateSink(ctx, req)
|
||||
resp, err = c.configClient.CreateSink(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.CreateSink...)
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -246,14 +233,15 @@ func (c *ConfigClient) CreateSink(ctx context.Context, req *loggingpb.CreateSink
|
||||
// `filter`, `output_version_format`, `start_time`, and `end_time`.
|
||||
// The updated filter might also have a new `writer_identity`; see the
|
||||
// `unique_writer_identity` field.
|
||||
func (c *ConfigClient) UpdateSink(ctx context.Context, req *loggingpb.UpdateSinkRequest) (*loggingpb.LogSink, error) {
|
||||
func (c *ConfigClient) UpdateSink(ctx context.Context, req *loggingpb.UpdateSinkRequest, opts ...gax.CallOption) (*loggingpb.LogSink, error) {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
opts = append(c.CallOptions.UpdateSink[0:len(c.CallOptions.UpdateSink):len(c.CallOptions.UpdateSink)], opts...)
|
||||
var resp *loggingpb.LogSink
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
resp, err = c.configClient.UpdateSink(ctx, req)
|
||||
resp, err = c.configClient.UpdateSink(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.UpdateSink...)
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -262,13 +250,14 @@ func (c *ConfigClient) UpdateSink(ctx context.Context, req *loggingpb.UpdateSink
|
||||
|
||||
// DeleteSink deletes a sink. If the sink has a unique `writer_identity`, then that
|
||||
// service account is also deleted.
|
||||
func (c *ConfigClient) DeleteSink(ctx context.Context, req *loggingpb.DeleteSinkRequest) error {
|
||||
func (c *ConfigClient) DeleteSink(ctx context.Context, req *loggingpb.DeleteSinkRequest, opts ...gax.CallOption) error {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
opts = append(c.CallOptions.DeleteSink[0:len(c.CallOptions.DeleteSink):len(c.CallOptions.DeleteSink)], opts...)
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
_, err = c.configClient.DeleteSink(ctx, req)
|
||||
_, err = c.configClient.DeleteSink(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.DeleteSink...)
|
||||
}, opts...)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -19,6 +19,7 @@ package logging_test
|
||||
import (
|
||||
"cloud.google.com/go/logging/apiv2"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/api/iterator"
|
||||
loggingpb "google.golang.org/genproto/googleapis/logging/v2"
|
||||
)
|
||||
|
||||
@@ -45,9 +46,11 @@ func ExampleConfigClient_ListSinks() {
|
||||
it := c.ListSinks(ctx, req)
|
||||
for {
|
||||
resp, err := it.Next()
|
||||
if err == iterator.Done {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
// TODO: Handle error.
|
||||
break
|
||||
}
|
||||
// TODO: Use resp.
|
||||
_ = resp
|
||||
|
||||
+17
-5
@@ -15,7 +15,7 @@
|
||||
// AUTO-GENERATED CODE. DO NOT EDIT.
|
||||
|
||||
// Package logging is an experimental, auto-generated package for the
|
||||
// logging API.
|
||||
// Stackdriver Logging API.
|
||||
//
|
||||
// The Stackdriver Logging API lets you write log entries and manage your
|
||||
// logs, log sinks and logs-based metrics.
|
||||
@@ -28,9 +28,21 @@ import (
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
func insertXGoog(ctx context.Context, val string) context.Context {
|
||||
md, _ := metadata.FromContext(ctx)
|
||||
func insertXGoog(ctx context.Context, val []string) context.Context {
|
||||
md, _ := metadata.FromOutgoingContext(ctx)
|
||||
md = md.Copy()
|
||||
md["x-goog-api-client"] = []string{val}
|
||||
return metadata.NewContext(ctx, md)
|
||||
md["x-goog-api-client"] = val
|
||||
return metadata.NewOutgoingContext(ctx, md)
|
||||
}
|
||||
|
||||
// DefaultAuthScopes reports the authentication scopes required
|
||||
// by this package.
|
||||
func DefaultAuthScopes() []string {
|
||||
return []string{
|
||||
"https://www.googleapis.com/auth/cloud-platform",
|
||||
"https://www.googleapis.com/auth/cloud-platform.read-only",
|
||||
"https://www.googleapis.com/auth/logging.admin",
|
||||
"https://www.googleapis.com/auth/logging.read",
|
||||
"https://www.googleapis.com/auth/logging.write",
|
||||
}
|
||||
}
|
||||
|
||||
+39
-48
@@ -49,13 +49,7 @@ type CallOptions struct {
|
||||
func defaultClientOptions() []option.ClientOption {
|
||||
return []option.ClientOption{
|
||||
option.WithEndpoint("logging.googleapis.com:443"),
|
||||
option.WithScopes(
|
||||
"https://www.googleapis.com/auth/cloud-platform",
|
||||
"https://www.googleapis.com/auth/cloud-platform.read-only",
|
||||
"https://www.googleapis.com/auth/logging.admin",
|
||||
"https://www.googleapis.com/auth/logging.read",
|
||||
"https://www.googleapis.com/auth/logging.write",
|
||||
),
|
||||
option.WithScopes(DefaultAuthScopes()...),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,17 +59,7 @@ func defaultCallOptions() *CallOptions {
|
||||
gax.WithRetry(func() gax.Retryer {
|
||||
return gax.OnCodes([]codes.Code{
|
||||
codes.DeadlineExceeded,
|
||||
codes.Unavailable,
|
||||
}, gax.Backoff{
|
||||
Initial: 100 * time.Millisecond,
|
||||
Max: 1000 * time.Millisecond,
|
||||
Multiplier: 1.2,
|
||||
})
|
||||
}),
|
||||
},
|
||||
{"default", "non_idempotent"}: {
|
||||
gax.WithRetry(func() gax.Retryer {
|
||||
return gax.OnCodes([]codes.Code{
|
||||
codes.Internal,
|
||||
codes.Unavailable,
|
||||
}, gax.Backoff{
|
||||
Initial: 100 * time.Millisecond,
|
||||
@@ -88,6 +72,7 @@ func defaultCallOptions() *CallOptions {
|
||||
gax.WithRetry(func() gax.Retryer {
|
||||
return gax.OnCodes([]codes.Code{
|
||||
codes.DeadlineExceeded,
|
||||
codes.Internal,
|
||||
codes.Unavailable,
|
||||
}, gax.Backoff{
|
||||
Initial: 100 * time.Millisecond,
|
||||
@@ -118,7 +103,7 @@ type Client struct {
|
||||
CallOptions *CallOptions
|
||||
|
||||
// The metadata to be sent with each request.
|
||||
xGoogHeader string
|
||||
xGoogHeader []string
|
||||
}
|
||||
|
||||
// NewClient creates a new logging service v2 client.
|
||||
@@ -155,12 +140,12 @@ func (c *Client) Close() error {
|
||||
// use by Google-written clients.
|
||||
func (c *Client) SetGoogleClientInfo(keyval ...string) {
|
||||
kv := append([]string{"gl-go", version.Go()}, keyval...)
|
||||
kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", "")
|
||||
c.xGoogHeader = gax.XGoogHeader(kv...)
|
||||
kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", grpc.Version)
|
||||
c.xGoogHeader = []string{gax.XGoogHeader(kv...)}
|
||||
}
|
||||
|
||||
// LoggingProjectPath returns the path for the project resource.
|
||||
func LoggingProjectPath(project string) string {
|
||||
// ProjectPath returns the path for the project resource.
|
||||
func ProjectPath(project string) string {
|
||||
path, err := loggingProjectPathTemplate.Render(map[string]string{
|
||||
"project": project,
|
||||
})
|
||||
@@ -170,8 +155,8 @@ func LoggingProjectPath(project string) string {
|
||||
return path
|
||||
}
|
||||
|
||||
// LoggingLogPath returns the path for the log resource.
|
||||
func LoggingLogPath(project, log string) string {
|
||||
// LogPath returns the path for the log resource.
|
||||
func LogPath(project, log string) string {
|
||||
path, err := loggingLogPathTemplate.Render(map[string]string{
|
||||
"project": project,
|
||||
"log": log,
|
||||
@@ -184,26 +169,29 @@ func LoggingLogPath(project, log string) string {
|
||||
|
||||
// DeleteLog deletes all the log entries in a log.
|
||||
// The log reappears if it receives new entries.
|
||||
func (c *Client) DeleteLog(ctx context.Context, req *loggingpb.DeleteLogRequest) error {
|
||||
// Log entries written shortly before the delete operation might not be
|
||||
// deleted.
|
||||
func (c *Client) DeleteLog(ctx context.Context, req *loggingpb.DeleteLogRequest, opts ...gax.CallOption) error {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
opts = append(c.CallOptions.DeleteLog[0:len(c.CallOptions.DeleteLog):len(c.CallOptions.DeleteLog)], opts...)
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
_, err = c.client.DeleteLog(ctx, req)
|
||||
_, err = c.client.DeleteLog(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.DeleteLog...)
|
||||
}, opts...)
|
||||
return err
|
||||
}
|
||||
|
||||
// WriteLogEntries writes log entries to Stackdriver Logging. All log entries are
|
||||
// written by this method.
|
||||
func (c *Client) WriteLogEntries(ctx context.Context, req *loggingpb.WriteLogEntriesRequest) (*loggingpb.WriteLogEntriesResponse, error) {
|
||||
// WriteLogEntries writes log entries to Stackdriver Logging.
|
||||
func (c *Client) WriteLogEntries(ctx context.Context, req *loggingpb.WriteLogEntriesRequest, opts ...gax.CallOption) (*loggingpb.WriteLogEntriesResponse, error) {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
opts = append(c.CallOptions.WriteLogEntries[0:len(c.CallOptions.WriteLogEntries):len(c.CallOptions.WriteLogEntries)], opts...)
|
||||
var resp *loggingpb.WriteLogEntriesResponse
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
resp, err = c.client.WriteLogEntries(ctx, req)
|
||||
resp, err = c.client.WriteLogEntries(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.WriteLogEntries...)
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -213,8 +201,9 @@ func (c *Client) WriteLogEntries(ctx context.Context, req *loggingpb.WriteLogEnt
|
||||
// ListLogEntries lists log entries. Use this method to retrieve log entries from
|
||||
// Stackdriver Logging. For ways to export log entries, see
|
||||
// [Exporting Logs](/logging/docs/export).
|
||||
func (c *Client) ListLogEntries(ctx context.Context, req *loggingpb.ListLogEntriesRequest) *LogEntryIterator {
|
||||
func (c *Client) ListLogEntries(ctx context.Context, req *loggingpb.ListLogEntriesRequest, opts ...gax.CallOption) *LogEntryIterator {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
opts = append(c.CallOptions.ListLogEntries[0:len(c.CallOptions.ListLogEntries):len(c.CallOptions.ListLogEntries)], opts...)
|
||||
it := &LogEntryIterator{}
|
||||
it.InternalFetch = func(pageSize int, pageToken string) ([]*loggingpb.LogEntry, string, error) {
|
||||
var resp *loggingpb.ListLogEntriesResponse
|
||||
@@ -224,11 +213,11 @@ func (c *Client) ListLogEntries(ctx context.Context, req *loggingpb.ListLogEntri
|
||||
} else {
|
||||
req.PageSize = int32(pageSize)
|
||||
}
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
resp, err = c.client.ListLogEntries(ctx, req)
|
||||
resp, err = c.client.ListLogEntries(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.ListLogEntries...)
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
@@ -248,8 +237,9 @@ func (c *Client) ListLogEntries(ctx context.Context, req *loggingpb.ListLogEntri
|
||||
|
||||
// ListMonitoredResourceDescriptors lists the descriptors for monitored resource types used by Stackdriver
|
||||
// Logging.
|
||||
func (c *Client) ListMonitoredResourceDescriptors(ctx context.Context, req *loggingpb.ListMonitoredResourceDescriptorsRequest) *MonitoredResourceDescriptorIterator {
|
||||
func (c *Client) ListMonitoredResourceDescriptors(ctx context.Context, req *loggingpb.ListMonitoredResourceDescriptorsRequest, opts ...gax.CallOption) *MonitoredResourceDescriptorIterator {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
opts = append(c.CallOptions.ListMonitoredResourceDescriptors[0:len(c.CallOptions.ListMonitoredResourceDescriptors):len(c.CallOptions.ListMonitoredResourceDescriptors)], opts...)
|
||||
it := &MonitoredResourceDescriptorIterator{}
|
||||
it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoredrespb.MonitoredResourceDescriptor, string, error) {
|
||||
var resp *loggingpb.ListMonitoredResourceDescriptorsResponse
|
||||
@@ -259,11 +249,11 @@ func (c *Client) ListMonitoredResourceDescriptors(ctx context.Context, req *logg
|
||||
} else {
|
||||
req.PageSize = int32(pageSize)
|
||||
}
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
resp, err = c.client.ListMonitoredResourceDescriptors(ctx, req)
|
||||
resp, err = c.client.ListMonitoredResourceDescriptors(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.ListMonitoredResourceDescriptors...)
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
@@ -281,10 +271,11 @@ func (c *Client) ListMonitoredResourceDescriptors(ctx context.Context, req *logg
|
||||
return it
|
||||
}
|
||||
|
||||
// ListLogs lists the logs in projects or organizations.
|
||||
// ListLogs lists the logs in projects, organizations, folders, or billing accounts.
|
||||
// Only logs that have entries are listed.
|
||||
func (c *Client) ListLogs(ctx context.Context, req *loggingpb.ListLogsRequest) *StringIterator {
|
||||
func (c *Client) ListLogs(ctx context.Context, req *loggingpb.ListLogsRequest, opts ...gax.CallOption) *StringIterator {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
opts = append(c.CallOptions.ListLogs[0:len(c.CallOptions.ListLogs):len(c.CallOptions.ListLogs)], opts...)
|
||||
it := &StringIterator{}
|
||||
it.InternalFetch = func(pageSize int, pageToken string) ([]string, string, error) {
|
||||
var resp *loggingpb.ListLogsResponse
|
||||
@@ -294,11 +285,11 @@ func (c *Client) ListLogs(ctx context.Context, req *loggingpb.ListLogsRequest) *
|
||||
} else {
|
||||
req.PageSize = int32(pageSize)
|
||||
}
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
resp, err = c.client.ListLogs(ctx, req)
|
||||
resp, err = c.client.ListLogs(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.ListLogs...)
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
+10
-3
@@ -19,6 +19,7 @@ package logging_test
|
||||
import (
|
||||
"cloud.google.com/go/logging/apiv2"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/api/iterator"
|
||||
loggingpb "google.golang.org/genproto/googleapis/logging/v2"
|
||||
)
|
||||
|
||||
@@ -79,9 +80,11 @@ func ExampleClient_ListLogEntries() {
|
||||
it := c.ListLogEntries(ctx, req)
|
||||
for {
|
||||
resp, err := it.Next()
|
||||
if err == iterator.Done {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
// TODO: Handle error.
|
||||
break
|
||||
}
|
||||
// TODO: Use resp.
|
||||
_ = resp
|
||||
@@ -101,9 +104,11 @@ func ExampleClient_ListMonitoredResourceDescriptors() {
|
||||
it := c.ListMonitoredResourceDescriptors(ctx, req)
|
||||
for {
|
||||
resp, err := it.Next()
|
||||
if err == iterator.Done {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
// TODO: Handle error.
|
||||
break
|
||||
}
|
||||
// TODO: Use resp.
|
||||
_ = resp
|
||||
@@ -123,9 +128,11 @@ func ExampleClient_ListLogs() {
|
||||
it := c.ListLogs(ctx, req)
|
||||
for {
|
||||
resp, err := it.Next()
|
||||
if err == iterator.Done {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
// TODO: Handle error.
|
||||
break
|
||||
}
|
||||
// TODO: Use resp.
|
||||
_ = resp
|
||||
|
||||
+30
-41
@@ -48,13 +48,7 @@ type MetricsCallOptions struct {
|
||||
func defaultMetricsClientOptions() []option.ClientOption {
|
||||
return []option.ClientOption{
|
||||
option.WithEndpoint("logging.googleapis.com:443"),
|
||||
option.WithScopes(
|
||||
"https://www.googleapis.com/auth/cloud-platform",
|
||||
"https://www.googleapis.com/auth/cloud-platform.read-only",
|
||||
"https://www.googleapis.com/auth/logging.admin",
|
||||
"https://www.googleapis.com/auth/logging.read",
|
||||
"https://www.googleapis.com/auth/logging.write",
|
||||
),
|
||||
option.WithScopes(DefaultAuthScopes()...),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,17 +58,7 @@ func defaultMetricsCallOptions() *MetricsCallOptions {
|
||||
gax.WithRetry(func() gax.Retryer {
|
||||
return gax.OnCodes([]codes.Code{
|
||||
codes.DeadlineExceeded,
|
||||
codes.Unavailable,
|
||||
}, gax.Backoff{
|
||||
Initial: 100 * time.Millisecond,
|
||||
Max: 1000 * time.Millisecond,
|
||||
Multiplier: 1.2,
|
||||
})
|
||||
}),
|
||||
},
|
||||
{"default", "non_idempotent"}: {
|
||||
gax.WithRetry(func() gax.Retryer {
|
||||
return gax.OnCodes([]codes.Code{
|
||||
codes.Internal,
|
||||
codes.Unavailable,
|
||||
}, gax.Backoff{
|
||||
Initial: 100 * time.Millisecond,
|
||||
@@ -105,7 +89,7 @@ type MetricsClient struct {
|
||||
CallOptions *MetricsCallOptions
|
||||
|
||||
// The metadata to be sent with each request.
|
||||
xGoogHeader string
|
||||
xGoogHeader []string
|
||||
}
|
||||
|
||||
// NewMetricsClient creates a new metrics service v2 client.
|
||||
@@ -142,8 +126,8 @@ func (c *MetricsClient) Close() error {
|
||||
// use by Google-written clients.
|
||||
func (c *MetricsClient) SetGoogleClientInfo(keyval ...string) {
|
||||
kv := append([]string{"gl-go", version.Go()}, keyval...)
|
||||
kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", "")
|
||||
c.xGoogHeader = gax.XGoogHeader(kv...)
|
||||
kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", grpc.Version)
|
||||
c.xGoogHeader = []string{gax.XGoogHeader(kv...)}
|
||||
}
|
||||
|
||||
// MetricsProjectPath returns the path for the project resource.
|
||||
@@ -170,8 +154,9 @@ func MetricsMetricPath(project, metric string) string {
|
||||
}
|
||||
|
||||
// ListLogMetrics lists logs-based metrics.
|
||||
func (c *MetricsClient) ListLogMetrics(ctx context.Context, req *loggingpb.ListLogMetricsRequest) *LogMetricIterator {
|
||||
func (c *MetricsClient) ListLogMetrics(ctx context.Context, req *loggingpb.ListLogMetricsRequest, opts ...gax.CallOption) *LogMetricIterator {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
opts = append(c.CallOptions.ListLogMetrics[0:len(c.CallOptions.ListLogMetrics):len(c.CallOptions.ListLogMetrics)], opts...)
|
||||
it := &LogMetricIterator{}
|
||||
it.InternalFetch = func(pageSize int, pageToken string) ([]*loggingpb.LogMetric, string, error) {
|
||||
var resp *loggingpb.ListLogMetricsResponse
|
||||
@@ -181,11 +166,11 @@ func (c *MetricsClient) ListLogMetrics(ctx context.Context, req *loggingpb.ListL
|
||||
} else {
|
||||
req.PageSize = int32(pageSize)
|
||||
}
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
resp, err = c.metricsClient.ListLogMetrics(ctx, req)
|
||||
resp, err = c.metricsClient.ListLogMetrics(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.ListLogMetrics...)
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
@@ -204,14 +189,15 @@ func (c *MetricsClient) ListLogMetrics(ctx context.Context, req *loggingpb.ListL
|
||||
}
|
||||
|
||||
// GetLogMetric gets a logs-based metric.
|
||||
func (c *MetricsClient) GetLogMetric(ctx context.Context, req *loggingpb.GetLogMetricRequest) (*loggingpb.LogMetric, error) {
|
||||
func (c *MetricsClient) GetLogMetric(ctx context.Context, req *loggingpb.GetLogMetricRequest, opts ...gax.CallOption) (*loggingpb.LogMetric, error) {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
opts = append(c.CallOptions.GetLogMetric[0:len(c.CallOptions.GetLogMetric):len(c.CallOptions.GetLogMetric)], opts...)
|
||||
var resp *loggingpb.LogMetric
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
resp, err = c.metricsClient.GetLogMetric(ctx, req)
|
||||
resp, err = c.metricsClient.GetLogMetric(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.GetLogMetric...)
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -219,14 +205,15 @@ func (c *MetricsClient) GetLogMetric(ctx context.Context, req *loggingpb.GetLogM
|
||||
}
|
||||
|
||||
// CreateLogMetric creates a logs-based metric.
|
||||
func (c *MetricsClient) CreateLogMetric(ctx context.Context, req *loggingpb.CreateLogMetricRequest) (*loggingpb.LogMetric, error) {
|
||||
func (c *MetricsClient) CreateLogMetric(ctx context.Context, req *loggingpb.CreateLogMetricRequest, opts ...gax.CallOption) (*loggingpb.LogMetric, error) {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
opts = append(c.CallOptions.CreateLogMetric[0:len(c.CallOptions.CreateLogMetric):len(c.CallOptions.CreateLogMetric)], opts...)
|
||||
var resp *loggingpb.LogMetric
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
resp, err = c.metricsClient.CreateLogMetric(ctx, req)
|
||||
resp, err = c.metricsClient.CreateLogMetric(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.CreateLogMetric...)
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -234,14 +221,15 @@ func (c *MetricsClient) CreateLogMetric(ctx context.Context, req *loggingpb.Crea
|
||||
}
|
||||
|
||||
// UpdateLogMetric creates or updates a logs-based metric.
|
||||
func (c *MetricsClient) UpdateLogMetric(ctx context.Context, req *loggingpb.UpdateLogMetricRequest) (*loggingpb.LogMetric, error) {
|
||||
func (c *MetricsClient) UpdateLogMetric(ctx context.Context, req *loggingpb.UpdateLogMetricRequest, opts ...gax.CallOption) (*loggingpb.LogMetric, error) {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
opts = append(c.CallOptions.UpdateLogMetric[0:len(c.CallOptions.UpdateLogMetric):len(c.CallOptions.UpdateLogMetric)], opts...)
|
||||
var resp *loggingpb.LogMetric
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
resp, err = c.metricsClient.UpdateLogMetric(ctx, req)
|
||||
resp, err = c.metricsClient.UpdateLogMetric(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.UpdateLogMetric...)
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -249,13 +237,14 @@ func (c *MetricsClient) UpdateLogMetric(ctx context.Context, req *loggingpb.Upda
|
||||
}
|
||||
|
||||
// DeleteLogMetric deletes a logs-based metric.
|
||||
func (c *MetricsClient) DeleteLogMetric(ctx context.Context, req *loggingpb.DeleteLogMetricRequest) error {
|
||||
func (c *MetricsClient) DeleteLogMetric(ctx context.Context, req *loggingpb.DeleteLogMetricRequest, opts ...gax.CallOption) error {
|
||||
ctx = insertXGoog(ctx, c.xGoogHeader)
|
||||
err := gax.Invoke(ctx, func(ctx context.Context) error {
|
||||
opts = append(c.CallOptions.DeleteLogMetric[0:len(c.CallOptions.DeleteLogMetric):len(c.CallOptions.DeleteLogMetric)], opts...)
|
||||
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
|
||||
var err error
|
||||
_, err = c.metricsClient.DeleteLogMetric(ctx, req)
|
||||
_, err = c.metricsClient.DeleteLogMetric(ctx, req, settings.GRPC...)
|
||||
return err
|
||||
}, c.CallOptions.DeleteLogMetric...)
|
||||
}, opts...)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -19,6 +19,7 @@ package logging_test
|
||||
import (
|
||||
"cloud.google.com/go/logging/apiv2"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/api/iterator"
|
||||
loggingpb "google.golang.org/genproto/googleapis/logging/v2"
|
||||
)
|
||||
|
||||
@@ -45,9 +46,11 @@ func ExampleMetricsClient_ListLogMetrics() {
|
||||
it := c.ListLogMetrics(ctx, req)
|
||||
for {
|
||||
resp, err := it.Next()
|
||||
if err == iterator.Done {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
// TODO: Handle error.
|
||||
break
|
||||
}
|
||||
// TODO: Use resp.
|
||||
_ = resp
|
||||
|
||||
+183
-83
@@ -17,17 +17,19 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
google_protobuf "github.com/golang/protobuf/ptypes/empty"
|
||||
emptypb "github.com/golang/protobuf/ptypes/empty"
|
||||
monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres"
|
||||
loggingpb "google.golang.org/genproto/googleapis/logging/v2"
|
||||
)
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
@@ -37,6 +39,8 @@ import (
|
||||
status "google.golang.org/genproto/googleapis/rpc/status"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
gstatus "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
var _ = io.EOF
|
||||
@@ -58,15 +62,23 @@ type mockLoggingServer struct {
|
||||
resps []proto.Message
|
||||
}
|
||||
|
||||
func (s *mockLoggingServer) DeleteLog(_ context.Context, req *loggingpb.DeleteLogRequest) (*google_protobuf.Empty, error) {
|
||||
func (s *mockLoggingServer) DeleteLog(ctx context.Context, req *loggingpb.DeleteLogRequest) (*emptypb.Empty, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
}
|
||||
return s.resps[0].(*google_protobuf.Empty), nil
|
||||
return s.resps[0].(*emptypb.Empty), nil
|
||||
}
|
||||
|
||||
func (s *mockLoggingServer) WriteLogEntries(_ context.Context, req *loggingpb.WriteLogEntriesRequest) (*loggingpb.WriteLogEntriesResponse, error) {
|
||||
func (s *mockLoggingServer) WriteLogEntries(ctx context.Context, req *loggingpb.WriteLogEntriesRequest) (*loggingpb.WriteLogEntriesResponse, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
@@ -74,7 +86,11 @@ func (s *mockLoggingServer) WriteLogEntries(_ context.Context, req *loggingpb.Wr
|
||||
return s.resps[0].(*loggingpb.WriteLogEntriesResponse), nil
|
||||
}
|
||||
|
||||
func (s *mockLoggingServer) ListLogEntries(_ context.Context, req *loggingpb.ListLogEntriesRequest) (*loggingpb.ListLogEntriesResponse, error) {
|
||||
func (s *mockLoggingServer) ListLogEntries(ctx context.Context, req *loggingpb.ListLogEntriesRequest) (*loggingpb.ListLogEntriesResponse, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
@@ -82,7 +98,11 @@ func (s *mockLoggingServer) ListLogEntries(_ context.Context, req *loggingpb.Lis
|
||||
return s.resps[0].(*loggingpb.ListLogEntriesResponse), nil
|
||||
}
|
||||
|
||||
func (s *mockLoggingServer) ListMonitoredResourceDescriptors(_ context.Context, req *loggingpb.ListMonitoredResourceDescriptorsRequest) (*loggingpb.ListMonitoredResourceDescriptorsResponse, error) {
|
||||
func (s *mockLoggingServer) ListMonitoredResourceDescriptors(ctx context.Context, req *loggingpb.ListMonitoredResourceDescriptorsRequest) (*loggingpb.ListMonitoredResourceDescriptorsResponse, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
@@ -90,7 +110,11 @@ func (s *mockLoggingServer) ListMonitoredResourceDescriptors(_ context.Context,
|
||||
return s.resps[0].(*loggingpb.ListMonitoredResourceDescriptorsResponse), nil
|
||||
}
|
||||
|
||||
func (s *mockLoggingServer) ListLogs(_ context.Context, req *loggingpb.ListLogsRequest) (*loggingpb.ListLogsResponse, error) {
|
||||
func (s *mockLoggingServer) ListLogs(ctx context.Context, req *loggingpb.ListLogsRequest) (*loggingpb.ListLogsResponse, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
@@ -113,7 +137,11 @@ type mockConfigServer struct {
|
||||
resps []proto.Message
|
||||
}
|
||||
|
||||
func (s *mockConfigServer) ListSinks(_ context.Context, req *loggingpb.ListSinksRequest) (*loggingpb.ListSinksResponse, error) {
|
||||
func (s *mockConfigServer) ListSinks(ctx context.Context, req *loggingpb.ListSinksRequest) (*loggingpb.ListSinksResponse, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
@@ -121,7 +149,11 @@ func (s *mockConfigServer) ListSinks(_ context.Context, req *loggingpb.ListSinks
|
||||
return s.resps[0].(*loggingpb.ListSinksResponse), nil
|
||||
}
|
||||
|
||||
func (s *mockConfigServer) GetSink(_ context.Context, req *loggingpb.GetSinkRequest) (*loggingpb.LogSink, error) {
|
||||
func (s *mockConfigServer) GetSink(ctx context.Context, req *loggingpb.GetSinkRequest) (*loggingpb.LogSink, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
@@ -129,7 +161,11 @@ func (s *mockConfigServer) GetSink(_ context.Context, req *loggingpb.GetSinkRequ
|
||||
return s.resps[0].(*loggingpb.LogSink), nil
|
||||
}
|
||||
|
||||
func (s *mockConfigServer) CreateSink(_ context.Context, req *loggingpb.CreateSinkRequest) (*loggingpb.LogSink, error) {
|
||||
func (s *mockConfigServer) CreateSink(ctx context.Context, req *loggingpb.CreateSinkRequest) (*loggingpb.LogSink, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
@@ -137,7 +173,11 @@ func (s *mockConfigServer) CreateSink(_ context.Context, req *loggingpb.CreateSi
|
||||
return s.resps[0].(*loggingpb.LogSink), nil
|
||||
}
|
||||
|
||||
func (s *mockConfigServer) UpdateSink(_ context.Context, req *loggingpb.UpdateSinkRequest) (*loggingpb.LogSink, error) {
|
||||
func (s *mockConfigServer) UpdateSink(ctx context.Context, req *loggingpb.UpdateSinkRequest) (*loggingpb.LogSink, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
@@ -145,12 +185,16 @@ func (s *mockConfigServer) UpdateSink(_ context.Context, req *loggingpb.UpdateSi
|
||||
return s.resps[0].(*loggingpb.LogSink), nil
|
||||
}
|
||||
|
||||
func (s *mockConfigServer) DeleteSink(_ context.Context, req *loggingpb.DeleteSinkRequest) (*google_protobuf.Empty, error) {
|
||||
func (s *mockConfigServer) DeleteSink(ctx context.Context, req *loggingpb.DeleteSinkRequest) (*emptypb.Empty, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
}
|
||||
return s.resps[0].(*google_protobuf.Empty), nil
|
||||
return s.resps[0].(*emptypb.Empty), nil
|
||||
}
|
||||
|
||||
type mockMetricsServer struct {
|
||||
@@ -168,7 +212,11 @@ type mockMetricsServer struct {
|
||||
resps []proto.Message
|
||||
}
|
||||
|
||||
func (s *mockMetricsServer) ListLogMetrics(_ context.Context, req *loggingpb.ListLogMetricsRequest) (*loggingpb.ListLogMetricsResponse, error) {
|
||||
func (s *mockMetricsServer) ListLogMetrics(ctx context.Context, req *loggingpb.ListLogMetricsRequest) (*loggingpb.ListLogMetricsResponse, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
@@ -176,7 +224,11 @@ func (s *mockMetricsServer) ListLogMetrics(_ context.Context, req *loggingpb.Lis
|
||||
return s.resps[0].(*loggingpb.ListLogMetricsResponse), nil
|
||||
}
|
||||
|
||||
func (s *mockMetricsServer) GetLogMetric(_ context.Context, req *loggingpb.GetLogMetricRequest) (*loggingpb.LogMetric, error) {
|
||||
func (s *mockMetricsServer) GetLogMetric(ctx context.Context, req *loggingpb.GetLogMetricRequest) (*loggingpb.LogMetric, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
@@ -184,7 +236,11 @@ func (s *mockMetricsServer) GetLogMetric(_ context.Context, req *loggingpb.GetLo
|
||||
return s.resps[0].(*loggingpb.LogMetric), nil
|
||||
}
|
||||
|
||||
func (s *mockMetricsServer) CreateLogMetric(_ context.Context, req *loggingpb.CreateLogMetricRequest) (*loggingpb.LogMetric, error) {
|
||||
func (s *mockMetricsServer) CreateLogMetric(ctx context.Context, req *loggingpb.CreateLogMetricRequest) (*loggingpb.LogMetric, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
@@ -192,7 +248,11 @@ func (s *mockMetricsServer) CreateLogMetric(_ context.Context, req *loggingpb.Cr
|
||||
return s.resps[0].(*loggingpb.LogMetric), nil
|
||||
}
|
||||
|
||||
func (s *mockMetricsServer) UpdateLogMetric(_ context.Context, req *loggingpb.UpdateLogMetricRequest) (*loggingpb.LogMetric, error) {
|
||||
func (s *mockMetricsServer) UpdateLogMetric(ctx context.Context, req *loggingpb.UpdateLogMetricRequest) (*loggingpb.LogMetric, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
@@ -200,12 +260,16 @@ func (s *mockMetricsServer) UpdateLogMetric(_ context.Context, req *loggingpb.Up
|
||||
return s.resps[0].(*loggingpb.LogMetric), nil
|
||||
}
|
||||
|
||||
func (s *mockMetricsServer) DeleteLogMetric(_ context.Context, req *loggingpb.DeleteLogMetricRequest) (*google_protobuf.Empty, error) {
|
||||
func (s *mockMetricsServer) DeleteLogMetric(ctx context.Context, req *loggingpb.DeleteLogMetricRequest) (*emptypb.Empty, error) {
|
||||
md, _ := metadata.FromIncomingContext(ctx)
|
||||
if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
|
||||
return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
|
||||
}
|
||||
s.reqs = append(s.reqs, req)
|
||||
if s.err != nil {
|
||||
return nil, s.err
|
||||
}
|
||||
return s.resps[0].(*google_protobuf.Empty), nil
|
||||
return s.resps[0].(*emptypb.Empty), nil
|
||||
}
|
||||
|
||||
// clientOpt is the option tests should use to connect to the test server.
|
||||
@@ -242,14 +306,14 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
func TestLoggingServiceV2DeleteLog(t *testing.T) {
|
||||
var expectedResponse *google_protobuf.Empty = &google_protobuf.Empty{}
|
||||
var expectedResponse *emptypb.Empty = &emptypb.Empty{}
|
||||
|
||||
mockLogging.err = nil
|
||||
mockLogging.reqs = nil
|
||||
|
||||
mockLogging.resps = append(mockLogging.resps[:0], expectedResponse)
|
||||
|
||||
var formattedLogName string = LoggingLogPath("[PROJECT]", "[LOG]")
|
||||
var formattedLogName string = LogPath("[PROJECT]", "[LOG]")
|
||||
var request = &loggingpb.DeleteLogRequest{
|
||||
LogName: formattedLogName,
|
||||
}
|
||||
@@ -272,10 +336,10 @@ func TestLoggingServiceV2DeleteLog(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoggingServiceV2DeleteLogError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockLogging.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockLogging.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedLogName string = LoggingLogPath("[PROJECT]", "[LOG]")
|
||||
var formattedLogName string = LogPath("[PROJECT]", "[LOG]")
|
||||
var request = &loggingpb.DeleteLogRequest{
|
||||
LogName: formattedLogName,
|
||||
}
|
||||
@@ -287,7 +351,9 @@ func TestLoggingServiceV2DeleteLogError(t *testing.T) {
|
||||
|
||||
err = c.DeleteLog(context.Background(), request)
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
}
|
||||
@@ -325,8 +391,8 @@ func TestLoggingServiceV2WriteLogEntries(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoggingServiceV2WriteLogEntriesError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockLogging.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockLogging.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var entries []*loggingpb.LogEntry = nil
|
||||
var request = &loggingpb.WriteLogEntriesRequest{
|
||||
@@ -340,7 +406,9 @@ func TestLoggingServiceV2WriteLogEntriesError(t *testing.T) {
|
||||
|
||||
resp, err := c.WriteLogEntries(context.Background(), request)
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
_ = resp
|
||||
@@ -395,8 +463,8 @@ func TestLoggingServiceV2ListLogEntries(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoggingServiceV2ListLogEntriesError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockLogging.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockLogging.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var resourceNames []string = nil
|
||||
var request = &loggingpb.ListLogEntriesRequest{
|
||||
@@ -410,7 +478,9 @@ func TestLoggingServiceV2ListLogEntriesError(t *testing.T) {
|
||||
|
||||
resp, err := c.ListLogEntries(context.Background(), request).Next()
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
_ = resp
|
||||
@@ -462,8 +532,8 @@ func TestLoggingServiceV2ListMonitoredResourceDescriptors(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoggingServiceV2ListMonitoredResourceDescriptorsError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockLogging.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockLogging.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var request *loggingpb.ListMonitoredResourceDescriptorsRequest = &loggingpb.ListMonitoredResourceDescriptorsRequest{}
|
||||
|
||||
@@ -474,7 +544,9 @@ func TestLoggingServiceV2ListMonitoredResourceDescriptorsError(t *testing.T) {
|
||||
|
||||
resp, err := c.ListMonitoredResourceDescriptors(context.Background(), request).Next()
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
_ = resp
|
||||
@@ -493,7 +565,7 @@ func TestLoggingServiceV2ListLogs(t *testing.T) {
|
||||
|
||||
mockLogging.resps = append(mockLogging.resps[:0], expectedResponse)
|
||||
|
||||
var formattedParent string = LoggingProjectPath("[PROJECT]")
|
||||
var formattedParent string = ProjectPath("[PROJECT]")
|
||||
var request = &loggingpb.ListLogsRequest{
|
||||
Parent: formattedParent,
|
||||
}
|
||||
@@ -529,10 +601,10 @@ func TestLoggingServiceV2ListLogs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoggingServiceV2ListLogsError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockLogging.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockLogging.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedParent string = LoggingProjectPath("[PROJECT]")
|
||||
var formattedParent string = ProjectPath("[PROJECT]")
|
||||
var request = &loggingpb.ListLogsRequest{
|
||||
Parent: formattedParent,
|
||||
}
|
||||
@@ -544,7 +616,9 @@ func TestLoggingServiceV2ListLogsError(t *testing.T) {
|
||||
|
||||
resp, err := c.ListLogs(context.Background(), request).Next()
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
_ = resp
|
||||
@@ -599,8 +673,8 @@ func TestConfigServiceV2ListSinks(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConfigServiceV2ListSinksError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockConfig.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockConfig.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedParent string = ConfigProjectPath("[PROJECT]")
|
||||
var request = &loggingpb.ListSinksRequest{
|
||||
@@ -614,7 +688,9 @@ func TestConfigServiceV2ListSinksError(t *testing.T) {
|
||||
|
||||
resp, err := c.ListSinks(context.Background(), request).Next()
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
_ = resp
|
||||
@@ -624,11 +700,13 @@ func TestConfigServiceV2GetSink(t *testing.T) {
|
||||
var destination string = "destination-1429847026"
|
||||
var filter string = "filter-1274492040"
|
||||
var writerIdentity string = "writerIdentity775638794"
|
||||
var includeChildren bool = true
|
||||
var expectedResponse = &loggingpb.LogSink{
|
||||
Name: name,
|
||||
Destination: destination,
|
||||
Filter: filter,
|
||||
WriterIdentity: writerIdentity,
|
||||
Name: name,
|
||||
Destination: destination,
|
||||
Filter: filter,
|
||||
WriterIdentity: writerIdentity,
|
||||
IncludeChildren: includeChildren,
|
||||
}
|
||||
|
||||
mockConfig.err = nil
|
||||
@@ -662,8 +740,8 @@ func TestConfigServiceV2GetSink(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConfigServiceV2GetSinkError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockConfig.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockConfig.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedSinkName string = ConfigSinkPath("[PROJECT]", "[SINK]")
|
||||
var request = &loggingpb.GetSinkRequest{
|
||||
@@ -677,7 +755,9 @@ func TestConfigServiceV2GetSinkError(t *testing.T) {
|
||||
|
||||
resp, err := c.GetSink(context.Background(), request)
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
_ = resp
|
||||
@@ -687,11 +767,13 @@ func TestConfigServiceV2CreateSink(t *testing.T) {
|
||||
var destination string = "destination-1429847026"
|
||||
var filter string = "filter-1274492040"
|
||||
var writerIdentity string = "writerIdentity775638794"
|
||||
var includeChildren bool = true
|
||||
var expectedResponse = &loggingpb.LogSink{
|
||||
Name: name,
|
||||
Destination: destination,
|
||||
Filter: filter,
|
||||
WriterIdentity: writerIdentity,
|
||||
Name: name,
|
||||
Destination: destination,
|
||||
Filter: filter,
|
||||
WriterIdentity: writerIdentity,
|
||||
IncludeChildren: includeChildren,
|
||||
}
|
||||
|
||||
mockConfig.err = nil
|
||||
@@ -727,8 +809,8 @@ func TestConfigServiceV2CreateSink(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConfigServiceV2CreateSinkError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockConfig.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockConfig.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedParent string = ConfigProjectPath("[PROJECT]")
|
||||
var sink *loggingpb.LogSink = &loggingpb.LogSink{}
|
||||
@@ -744,7 +826,9 @@ func TestConfigServiceV2CreateSinkError(t *testing.T) {
|
||||
|
||||
resp, err := c.CreateSink(context.Background(), request)
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
_ = resp
|
||||
@@ -754,11 +838,13 @@ func TestConfigServiceV2UpdateSink(t *testing.T) {
|
||||
var destination string = "destination-1429847026"
|
||||
var filter string = "filter-1274492040"
|
||||
var writerIdentity string = "writerIdentity775638794"
|
||||
var includeChildren bool = true
|
||||
var expectedResponse = &loggingpb.LogSink{
|
||||
Name: name,
|
||||
Destination: destination,
|
||||
Filter: filter,
|
||||
WriterIdentity: writerIdentity,
|
||||
Name: name,
|
||||
Destination: destination,
|
||||
Filter: filter,
|
||||
WriterIdentity: writerIdentity,
|
||||
IncludeChildren: includeChildren,
|
||||
}
|
||||
|
||||
mockConfig.err = nil
|
||||
@@ -794,8 +880,8 @@ func TestConfigServiceV2UpdateSink(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConfigServiceV2UpdateSinkError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockConfig.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockConfig.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedSinkName string = ConfigSinkPath("[PROJECT]", "[SINK]")
|
||||
var sink *loggingpb.LogSink = &loggingpb.LogSink{}
|
||||
@@ -811,13 +897,15 @@ func TestConfigServiceV2UpdateSinkError(t *testing.T) {
|
||||
|
||||
resp, err := c.UpdateSink(context.Background(), request)
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
_ = resp
|
||||
}
|
||||
func TestConfigServiceV2DeleteSink(t *testing.T) {
|
||||
var expectedResponse *google_protobuf.Empty = &google_protobuf.Empty{}
|
||||
var expectedResponse *emptypb.Empty = &emptypb.Empty{}
|
||||
|
||||
mockConfig.err = nil
|
||||
mockConfig.reqs = nil
|
||||
@@ -847,8 +935,8 @@ func TestConfigServiceV2DeleteSink(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConfigServiceV2DeleteSinkError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockConfig.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockConfig.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedSinkName string = ConfigSinkPath("[PROJECT]", "[SINK]")
|
||||
var request = &loggingpb.DeleteSinkRequest{
|
||||
@@ -862,7 +950,9 @@ func TestConfigServiceV2DeleteSinkError(t *testing.T) {
|
||||
|
||||
err = c.DeleteSink(context.Background(), request)
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
}
|
||||
@@ -916,8 +1006,8 @@ func TestMetricsServiceV2ListLogMetrics(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMetricsServiceV2ListLogMetricsError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockMetrics.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockMetrics.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedParent string = MetricsProjectPath("[PROJECT]")
|
||||
var request = &loggingpb.ListLogMetricsRequest{
|
||||
@@ -931,7 +1021,9 @@ func TestMetricsServiceV2ListLogMetricsError(t *testing.T) {
|
||||
|
||||
resp, err := c.ListLogMetrics(context.Background(), request).Next()
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
_ = resp
|
||||
@@ -977,8 +1069,8 @@ func TestMetricsServiceV2GetLogMetric(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMetricsServiceV2GetLogMetricError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockMetrics.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockMetrics.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedMetricName string = MetricsMetricPath("[PROJECT]", "[METRIC]")
|
||||
var request = &loggingpb.GetLogMetricRequest{
|
||||
@@ -992,7 +1084,9 @@ func TestMetricsServiceV2GetLogMetricError(t *testing.T) {
|
||||
|
||||
resp, err := c.GetLogMetric(context.Background(), request)
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
_ = resp
|
||||
@@ -1040,8 +1134,8 @@ func TestMetricsServiceV2CreateLogMetric(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMetricsServiceV2CreateLogMetricError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockMetrics.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockMetrics.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedParent string = MetricsProjectPath("[PROJECT]")
|
||||
var metric *loggingpb.LogMetric = &loggingpb.LogMetric{}
|
||||
@@ -1057,7 +1151,9 @@ func TestMetricsServiceV2CreateLogMetricError(t *testing.T) {
|
||||
|
||||
resp, err := c.CreateLogMetric(context.Background(), request)
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
_ = resp
|
||||
@@ -1105,8 +1201,8 @@ func TestMetricsServiceV2UpdateLogMetric(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMetricsServiceV2UpdateLogMetricError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockMetrics.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockMetrics.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedMetricName string = MetricsMetricPath("[PROJECT]", "[METRIC]")
|
||||
var metric *loggingpb.LogMetric = &loggingpb.LogMetric{}
|
||||
@@ -1122,13 +1218,15 @@ func TestMetricsServiceV2UpdateLogMetricError(t *testing.T) {
|
||||
|
||||
resp, err := c.UpdateLogMetric(context.Background(), request)
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
_ = resp
|
||||
}
|
||||
func TestMetricsServiceV2DeleteLogMetric(t *testing.T) {
|
||||
var expectedResponse *google_protobuf.Empty = &google_protobuf.Empty{}
|
||||
var expectedResponse *emptypb.Empty = &emptypb.Empty{}
|
||||
|
||||
mockMetrics.err = nil
|
||||
mockMetrics.reqs = nil
|
||||
@@ -1158,8 +1256,8 @@ func TestMetricsServiceV2DeleteLogMetric(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMetricsServiceV2DeleteLogMetricError(t *testing.T) {
|
||||
errCode := codes.Internal
|
||||
mockMetrics.err = grpc.Errorf(errCode, "test error")
|
||||
errCode := codes.PermissionDenied
|
||||
mockMetrics.err = gstatus.Error(errCode, "test error")
|
||||
|
||||
var formattedMetricName string = MetricsMetricPath("[PROJECT]", "[METRIC]")
|
||||
var request = &loggingpb.DeleteLogMetricRequest{
|
||||
@@ -1173,7 +1271,9 @@ func TestMetricsServiceV2DeleteLogMetricError(t *testing.T) {
|
||||
|
||||
err = c.DeleteLogMetric(context.Background(), request)
|
||||
|
||||
if c := grpc.Code(err); c != errCode {
|
||||
if st, ok := gstatus.FromError(err); !ok {
|
||||
t.Errorf("got error %v, expected grpc error", err)
|
||||
} else if c := st.Code(); c != errCode {
|
||||
t.Errorf("got error code %q, want %q", c, errCode)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user