1// Copyright 2019 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// Code generated by gapic-generator. DO NOT EDIT.
16
17package grafeas
18
19import (
20	"context"
21	"flag"
22	"fmt"
23	"io"
24	"log"
25	"net"
26	"os"
27	"strings"
28	"testing"
29
30	"github.com/golang/protobuf/proto"
31	"github.com/golang/protobuf/ptypes"
32	emptypb "github.com/golang/protobuf/ptypes/empty"
33	"google.golang.org/api/option"
34	grafeaspb "google.golang.org/genproto/googleapis/grafeas/v1"
35
36	status "google.golang.org/genproto/googleapis/rpc/status"
37	"google.golang.org/grpc"
38	"google.golang.org/grpc/codes"
39	"google.golang.org/grpc/metadata"
40
41	gstatus "google.golang.org/grpc/status"
42)
43
44var _ = io.EOF
45var _ = ptypes.MarshalAny
46var _ status.Status
47
48type mockGrafeasServer struct {
49	// Embed for forward compatibility.
50	// Tests will keep working if more methods are added
51	// in the future.
52	grafeaspb.GrafeasServer
53
54	reqs []proto.Message
55
56	// If set, all calls return this error.
57	err error
58
59	// responses to return if err == nil
60	resps []proto.Message
61}
62
63func (s *mockGrafeasServer) GetOccurrence(ctx context.Context, req *grafeaspb.GetOccurrenceRequest) (*grafeaspb.Occurrence, error) {
64	md, _ := metadata.FromIncomingContext(ctx)
65	if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
66		return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
67	}
68	s.reqs = append(s.reqs, req)
69	if s.err != nil {
70		return nil, s.err
71	}
72	return s.resps[0].(*grafeaspb.Occurrence), nil
73}
74
75func (s *mockGrafeasServer) ListOccurrences(ctx context.Context, req *grafeaspb.ListOccurrencesRequest) (*grafeaspb.ListOccurrencesResponse, error) {
76	md, _ := metadata.FromIncomingContext(ctx)
77	if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
78		return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
79	}
80	s.reqs = append(s.reqs, req)
81	if s.err != nil {
82		return nil, s.err
83	}
84	return s.resps[0].(*grafeaspb.ListOccurrencesResponse), nil
85}
86
87func (s *mockGrafeasServer) DeleteOccurrence(ctx context.Context, req *grafeaspb.DeleteOccurrenceRequest) (*emptypb.Empty, error) {
88	md, _ := metadata.FromIncomingContext(ctx)
89	if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
90		return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
91	}
92	s.reqs = append(s.reqs, req)
93	if s.err != nil {
94		return nil, s.err
95	}
96	return s.resps[0].(*emptypb.Empty), nil
97}
98
99func (s *mockGrafeasServer) CreateOccurrence(ctx context.Context, req *grafeaspb.CreateOccurrenceRequest) (*grafeaspb.Occurrence, error) {
100	md, _ := metadata.FromIncomingContext(ctx)
101	if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
102		return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
103	}
104	s.reqs = append(s.reqs, req)
105	if s.err != nil {
106		return nil, s.err
107	}
108	return s.resps[0].(*grafeaspb.Occurrence), nil
109}
110
111func (s *mockGrafeasServer) BatchCreateOccurrences(ctx context.Context, req *grafeaspb.BatchCreateOccurrencesRequest) (*grafeaspb.BatchCreateOccurrencesResponse, error) {
112	md, _ := metadata.FromIncomingContext(ctx)
113	if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
114		return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
115	}
116	s.reqs = append(s.reqs, req)
117	if s.err != nil {
118		return nil, s.err
119	}
120	return s.resps[0].(*grafeaspb.BatchCreateOccurrencesResponse), nil
121}
122
123func (s *mockGrafeasServer) UpdateOccurrence(ctx context.Context, req *grafeaspb.UpdateOccurrenceRequest) (*grafeaspb.Occurrence, error) {
124	md, _ := metadata.FromIncomingContext(ctx)
125	if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
126		return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
127	}
128	s.reqs = append(s.reqs, req)
129	if s.err != nil {
130		return nil, s.err
131	}
132	return s.resps[0].(*grafeaspb.Occurrence), nil
133}
134
135func (s *mockGrafeasServer) GetOccurrenceNote(ctx context.Context, req *grafeaspb.GetOccurrenceNoteRequest) (*grafeaspb.Note, error) {
136	md, _ := metadata.FromIncomingContext(ctx)
137	if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
138		return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
139	}
140	s.reqs = append(s.reqs, req)
141	if s.err != nil {
142		return nil, s.err
143	}
144	return s.resps[0].(*grafeaspb.Note), nil
145}
146
147func (s *mockGrafeasServer) GetNote(ctx context.Context, req *grafeaspb.GetNoteRequest) (*grafeaspb.Note, error) {
148	md, _ := metadata.FromIncomingContext(ctx)
149	if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
150		return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
151	}
152	s.reqs = append(s.reqs, req)
153	if s.err != nil {
154		return nil, s.err
155	}
156	return s.resps[0].(*grafeaspb.Note), nil
157}
158
159func (s *mockGrafeasServer) ListNotes(ctx context.Context, req *grafeaspb.ListNotesRequest) (*grafeaspb.ListNotesResponse, error) {
160	md, _ := metadata.FromIncomingContext(ctx)
161	if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
162		return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
163	}
164	s.reqs = append(s.reqs, req)
165	if s.err != nil {
166		return nil, s.err
167	}
168	return s.resps[0].(*grafeaspb.ListNotesResponse), nil
169}
170
171func (s *mockGrafeasServer) DeleteNote(ctx context.Context, req *grafeaspb.DeleteNoteRequest) (*emptypb.Empty, error) {
172	md, _ := metadata.FromIncomingContext(ctx)
173	if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
174		return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
175	}
176	s.reqs = append(s.reqs, req)
177	if s.err != nil {
178		return nil, s.err
179	}
180	return s.resps[0].(*emptypb.Empty), nil
181}
182
183func (s *mockGrafeasServer) CreateNote(ctx context.Context, req *grafeaspb.CreateNoteRequest) (*grafeaspb.Note, error) {
184	md, _ := metadata.FromIncomingContext(ctx)
185	if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
186		return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
187	}
188	s.reqs = append(s.reqs, req)
189	if s.err != nil {
190		return nil, s.err
191	}
192	return s.resps[0].(*grafeaspb.Note), nil
193}
194
195func (s *mockGrafeasServer) BatchCreateNotes(ctx context.Context, req *grafeaspb.BatchCreateNotesRequest) (*grafeaspb.BatchCreateNotesResponse, error) {
196	md, _ := metadata.FromIncomingContext(ctx)
197	if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
198		return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
199	}
200	s.reqs = append(s.reqs, req)
201	if s.err != nil {
202		return nil, s.err
203	}
204	return s.resps[0].(*grafeaspb.BatchCreateNotesResponse), nil
205}
206
207func (s *mockGrafeasServer) UpdateNote(ctx context.Context, req *grafeaspb.UpdateNoteRequest) (*grafeaspb.Note, error) {
208	md, _ := metadata.FromIncomingContext(ctx)
209	if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
210		return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
211	}
212	s.reqs = append(s.reqs, req)
213	if s.err != nil {
214		return nil, s.err
215	}
216	return s.resps[0].(*grafeaspb.Note), nil
217}
218
219func (s *mockGrafeasServer) ListNoteOccurrences(ctx context.Context, req *grafeaspb.ListNoteOccurrencesRequest) (*grafeaspb.ListNoteOccurrencesResponse, error) {
220	md, _ := metadata.FromIncomingContext(ctx)
221	if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
222		return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
223	}
224	s.reqs = append(s.reqs, req)
225	if s.err != nil {
226		return nil, s.err
227	}
228	return s.resps[0].(*grafeaspb.ListNoteOccurrencesResponse), nil
229}
230
231// clientOpt is the option tests should use to connect to the test server.
232// It is initialized by TestMain.
233var clientOpt option.ClientOption
234
235var (
236	mockGrafeas mockGrafeasServer
237)
238
239func TestMain(m *testing.M) {
240	flag.Parse()
241
242	serv := grpc.NewServer()
243	grafeaspb.RegisterGrafeasServer(serv, &mockGrafeas)
244
245	lis, err := net.Listen("tcp", "localhost:0")
246	if err != nil {
247		log.Fatal(err)
248	}
249	go serv.Serve(lis)
250
251	conn, err := grpc.Dial(lis.Addr().String(), grpc.WithInsecure())
252	if err != nil {
253		log.Fatal(err)
254	}
255	clientOpt = option.WithGRPCConn(conn)
256
257	os.Exit(m.Run())
258}
259
260func TestGrafeasGetOccurrence(t *testing.T) {
261	var name2 string = "name2-1052831874"
262	var resourceUri string = "resourceUri-384040517"
263	var noteName string = "noteName1780787896"
264	var remediation string = "remediation779381797"
265	var expectedResponse = &grafeaspb.Occurrence{
266		Name:        name2,
267		ResourceUri: resourceUri,
268		NoteName:    noteName,
269		Remediation: remediation,
270	}
271
272	mockGrafeas.err = nil
273	mockGrafeas.reqs = nil
274
275	mockGrafeas.resps = append(mockGrafeas.resps[:0], expectedResponse)
276
277	var formattedName string = fmt.Sprintf("projects/%s/occurrences/%s", "[PROJECT]", "[OCCURRENCE]")
278	var request = &grafeaspb.GetOccurrenceRequest{
279		Name: formattedName,
280	}
281
282	c, err := NewClient(context.Background(), clientOpt)
283	if err != nil {
284		t.Fatal(err)
285	}
286
287	resp, err := c.GetOccurrence(context.Background(), request)
288
289	if err != nil {
290		t.Fatal(err)
291	}
292
293	if want, got := request, mockGrafeas.reqs[0]; !proto.Equal(want, got) {
294		t.Errorf("wrong request %q, want %q", got, want)
295	}
296
297	if want, got := expectedResponse, resp; !proto.Equal(want, got) {
298		t.Errorf("wrong response %q, want %q)", got, want)
299	}
300}
301
302func TestGrafeasGetOccurrenceError(t *testing.T) {
303	errCode := codes.PermissionDenied
304	mockGrafeas.err = gstatus.Error(errCode, "test error")
305
306	var formattedName string = fmt.Sprintf("projects/%s/occurrences/%s", "[PROJECT]", "[OCCURRENCE]")
307	var request = &grafeaspb.GetOccurrenceRequest{
308		Name: formattedName,
309	}
310
311	c, err := NewClient(context.Background(), clientOpt)
312	if err != nil {
313		t.Fatal(err)
314	}
315
316	resp, err := c.GetOccurrence(context.Background(), request)
317
318	if st, ok := gstatus.FromError(err); !ok {
319		t.Errorf("got error %v, expected grpc error", err)
320	} else if c := st.Code(); c != errCode {
321		t.Errorf("got error code %q, want %q", c, errCode)
322	}
323	_ = resp
324}
325func TestGrafeasListOccurrences(t *testing.T) {
326	var nextPageToken string = ""
327	var occurrencesElement *grafeaspb.Occurrence = &grafeaspb.Occurrence{}
328	var occurrences = []*grafeaspb.Occurrence{occurrencesElement}
329	var expectedResponse = &grafeaspb.ListOccurrencesResponse{
330		NextPageToken: nextPageToken,
331		Occurrences:   occurrences,
332	}
333
334	mockGrafeas.err = nil
335	mockGrafeas.reqs = nil
336
337	mockGrafeas.resps = append(mockGrafeas.resps[:0], expectedResponse)
338
339	var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
340	var request = &grafeaspb.ListOccurrencesRequest{
341		Parent: formattedParent,
342	}
343
344	c, err := NewClient(context.Background(), clientOpt)
345	if err != nil {
346		t.Fatal(err)
347	}
348
349	resp, err := c.ListOccurrences(context.Background(), request).Next()
350
351	if err != nil {
352		t.Fatal(err)
353	}
354
355	if want, got := request, mockGrafeas.reqs[0]; !proto.Equal(want, got) {
356		t.Errorf("wrong request %q, want %q", got, want)
357	}
358
359	want := (interface{})(expectedResponse.Occurrences[0])
360	got := (interface{})(resp)
361	var ok bool
362
363	switch want := (want).(type) {
364	case proto.Message:
365		ok = proto.Equal(want, got.(proto.Message))
366	default:
367		ok = want == got
368	}
369	if !ok {
370		t.Errorf("wrong response %q, want %q)", got, want)
371	}
372}
373
374func TestGrafeasListOccurrencesError(t *testing.T) {
375	errCode := codes.PermissionDenied
376	mockGrafeas.err = gstatus.Error(errCode, "test error")
377
378	var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
379	var request = &grafeaspb.ListOccurrencesRequest{
380		Parent: formattedParent,
381	}
382
383	c, err := NewClient(context.Background(), clientOpt)
384	if err != nil {
385		t.Fatal(err)
386	}
387
388	resp, err := c.ListOccurrences(context.Background(), request).Next()
389
390	if st, ok := gstatus.FromError(err); !ok {
391		t.Errorf("got error %v, expected grpc error", err)
392	} else if c := st.Code(); c != errCode {
393		t.Errorf("got error code %q, want %q", c, errCode)
394	}
395	_ = resp
396}
397func TestGrafeasDeleteOccurrence(t *testing.T) {
398	var expectedResponse *emptypb.Empty = &emptypb.Empty{}
399
400	mockGrafeas.err = nil
401	mockGrafeas.reqs = nil
402
403	mockGrafeas.resps = append(mockGrafeas.resps[:0], expectedResponse)
404
405	var formattedName string = fmt.Sprintf("projects/%s/occurrences/%s", "[PROJECT]", "[OCCURRENCE]")
406	var request = &grafeaspb.DeleteOccurrenceRequest{
407		Name: formattedName,
408	}
409
410	c, err := NewClient(context.Background(), clientOpt)
411	if err != nil {
412		t.Fatal(err)
413	}
414
415	err = c.DeleteOccurrence(context.Background(), request)
416
417	if err != nil {
418		t.Fatal(err)
419	}
420
421	if want, got := request, mockGrafeas.reqs[0]; !proto.Equal(want, got) {
422		t.Errorf("wrong request %q, want %q", got, want)
423	}
424
425}
426
427func TestGrafeasDeleteOccurrenceError(t *testing.T) {
428	errCode := codes.PermissionDenied
429	mockGrafeas.err = gstatus.Error(errCode, "test error")
430
431	var formattedName string = fmt.Sprintf("projects/%s/occurrences/%s", "[PROJECT]", "[OCCURRENCE]")
432	var request = &grafeaspb.DeleteOccurrenceRequest{
433		Name: formattedName,
434	}
435
436	c, err := NewClient(context.Background(), clientOpt)
437	if err != nil {
438		t.Fatal(err)
439	}
440
441	err = c.DeleteOccurrence(context.Background(), request)
442
443	if st, ok := gstatus.FromError(err); !ok {
444		t.Errorf("got error %v, expected grpc error", err)
445	} else if c := st.Code(); c != errCode {
446		t.Errorf("got error code %q, want %q", c, errCode)
447	}
448}
449func TestGrafeasCreateOccurrence(t *testing.T) {
450	var name string = "name3373707"
451	var resourceUri string = "resourceUri-384040517"
452	var noteName string = "noteName1780787896"
453	var remediation string = "remediation779381797"
454	var expectedResponse = &grafeaspb.Occurrence{
455		Name:        name,
456		ResourceUri: resourceUri,
457		NoteName:    noteName,
458		Remediation: remediation,
459	}
460
461	mockGrafeas.err = nil
462	mockGrafeas.reqs = nil
463
464	mockGrafeas.resps = append(mockGrafeas.resps[:0], expectedResponse)
465
466	var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
467	var occurrence *grafeaspb.Occurrence = &grafeaspb.Occurrence{}
468	var request = &grafeaspb.CreateOccurrenceRequest{
469		Parent:     formattedParent,
470		Occurrence: occurrence,
471	}
472
473	c, err := NewClient(context.Background(), clientOpt)
474	if err != nil {
475		t.Fatal(err)
476	}
477
478	resp, err := c.CreateOccurrence(context.Background(), request)
479
480	if err != nil {
481		t.Fatal(err)
482	}
483
484	if want, got := request, mockGrafeas.reqs[0]; !proto.Equal(want, got) {
485		t.Errorf("wrong request %q, want %q", got, want)
486	}
487
488	if want, got := expectedResponse, resp; !proto.Equal(want, got) {
489		t.Errorf("wrong response %q, want %q)", got, want)
490	}
491}
492
493func TestGrafeasCreateOccurrenceError(t *testing.T) {
494	errCode := codes.PermissionDenied
495	mockGrafeas.err = gstatus.Error(errCode, "test error")
496
497	var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
498	var occurrence *grafeaspb.Occurrence = &grafeaspb.Occurrence{}
499	var request = &grafeaspb.CreateOccurrenceRequest{
500		Parent:     formattedParent,
501		Occurrence: occurrence,
502	}
503
504	c, err := NewClient(context.Background(), clientOpt)
505	if err != nil {
506		t.Fatal(err)
507	}
508
509	resp, err := c.CreateOccurrence(context.Background(), request)
510
511	if st, ok := gstatus.FromError(err); !ok {
512		t.Errorf("got error %v, expected grpc error", err)
513	} else if c := st.Code(); c != errCode {
514		t.Errorf("got error code %q, want %q", c, errCode)
515	}
516	_ = resp
517}
518func TestGrafeasBatchCreateOccurrences(t *testing.T) {
519	var expectedResponse *grafeaspb.BatchCreateOccurrencesResponse = &grafeaspb.BatchCreateOccurrencesResponse{}
520
521	mockGrafeas.err = nil
522	mockGrafeas.reqs = nil
523
524	mockGrafeas.resps = append(mockGrafeas.resps[:0], expectedResponse)
525
526	var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
527	var occurrences []*grafeaspb.Occurrence = nil
528	var request = &grafeaspb.BatchCreateOccurrencesRequest{
529		Parent:      formattedParent,
530		Occurrences: occurrences,
531	}
532
533	c, err := NewClient(context.Background(), clientOpt)
534	if err != nil {
535		t.Fatal(err)
536	}
537
538	resp, err := c.BatchCreateOccurrences(context.Background(), request)
539
540	if err != nil {
541		t.Fatal(err)
542	}
543
544	if want, got := request, mockGrafeas.reqs[0]; !proto.Equal(want, got) {
545		t.Errorf("wrong request %q, want %q", got, want)
546	}
547
548	if want, got := expectedResponse, resp; !proto.Equal(want, got) {
549		t.Errorf("wrong response %q, want %q)", got, want)
550	}
551}
552
553func TestGrafeasBatchCreateOccurrencesError(t *testing.T) {
554	errCode := codes.PermissionDenied
555	mockGrafeas.err = gstatus.Error(errCode, "test error")
556
557	var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
558	var occurrences []*grafeaspb.Occurrence = nil
559	var request = &grafeaspb.BatchCreateOccurrencesRequest{
560		Parent:      formattedParent,
561		Occurrences: occurrences,
562	}
563
564	c, err := NewClient(context.Background(), clientOpt)
565	if err != nil {
566		t.Fatal(err)
567	}
568
569	resp, err := c.BatchCreateOccurrences(context.Background(), request)
570
571	if st, ok := gstatus.FromError(err); !ok {
572		t.Errorf("got error %v, expected grpc error", err)
573	} else if c := st.Code(); c != errCode {
574		t.Errorf("got error code %q, want %q", c, errCode)
575	}
576	_ = resp
577}
578func TestGrafeasUpdateOccurrence(t *testing.T) {
579	var name2 string = "name2-1052831874"
580	var resourceUri string = "resourceUri-384040517"
581	var noteName string = "noteName1780787896"
582	var remediation string = "remediation779381797"
583	var expectedResponse = &grafeaspb.Occurrence{
584		Name:        name2,
585		ResourceUri: resourceUri,
586		NoteName:    noteName,
587		Remediation: remediation,
588	}
589
590	mockGrafeas.err = nil
591	mockGrafeas.reqs = nil
592
593	mockGrafeas.resps = append(mockGrafeas.resps[:0], expectedResponse)
594
595	var formattedName string = fmt.Sprintf("projects/%s/occurrences/%s", "[PROJECT]", "[OCCURRENCE]")
596	var occurrence *grafeaspb.Occurrence = &grafeaspb.Occurrence{}
597	var request = &grafeaspb.UpdateOccurrenceRequest{
598		Name:       formattedName,
599		Occurrence: occurrence,
600	}
601
602	c, err := NewClient(context.Background(), clientOpt)
603	if err != nil {
604		t.Fatal(err)
605	}
606
607	resp, err := c.UpdateOccurrence(context.Background(), request)
608
609	if err != nil {
610		t.Fatal(err)
611	}
612
613	if want, got := request, mockGrafeas.reqs[0]; !proto.Equal(want, got) {
614		t.Errorf("wrong request %q, want %q", got, want)
615	}
616
617	if want, got := expectedResponse, resp; !proto.Equal(want, got) {
618		t.Errorf("wrong response %q, want %q)", got, want)
619	}
620}
621
622func TestGrafeasUpdateOccurrenceError(t *testing.T) {
623	errCode := codes.PermissionDenied
624	mockGrafeas.err = gstatus.Error(errCode, "test error")
625
626	var formattedName string = fmt.Sprintf("projects/%s/occurrences/%s", "[PROJECT]", "[OCCURRENCE]")
627	var occurrence *grafeaspb.Occurrence = &grafeaspb.Occurrence{}
628	var request = &grafeaspb.UpdateOccurrenceRequest{
629		Name:       formattedName,
630		Occurrence: occurrence,
631	}
632
633	c, err := NewClient(context.Background(), clientOpt)
634	if err != nil {
635		t.Fatal(err)
636	}
637
638	resp, err := c.UpdateOccurrence(context.Background(), request)
639
640	if st, ok := gstatus.FromError(err); !ok {
641		t.Errorf("got error %v, expected grpc error", err)
642	} else if c := st.Code(); c != errCode {
643		t.Errorf("got error code %q, want %q", c, errCode)
644	}
645	_ = resp
646}
647func TestGrafeasGetOccurrenceNote(t *testing.T) {
648	var name2 string = "name2-1052831874"
649	var shortDescription string = "shortDescription-235369287"
650	var longDescription string = "longDescription-1747792199"
651	var expectedResponse = &grafeaspb.Note{
652		Name:             name2,
653		ShortDescription: shortDescription,
654		LongDescription:  longDescription,
655	}
656
657	mockGrafeas.err = nil
658	mockGrafeas.reqs = nil
659
660	mockGrafeas.resps = append(mockGrafeas.resps[:0], expectedResponse)
661
662	var formattedName string = fmt.Sprintf("projects/%s/occurrences/%s", "[PROJECT]", "[OCCURRENCE]")
663	var request = &grafeaspb.GetOccurrenceNoteRequest{
664		Name: formattedName,
665	}
666
667	c, err := NewClient(context.Background(), clientOpt)
668	if err != nil {
669		t.Fatal(err)
670	}
671
672	resp, err := c.GetOccurrenceNote(context.Background(), request)
673
674	if err != nil {
675		t.Fatal(err)
676	}
677
678	if want, got := request, mockGrafeas.reqs[0]; !proto.Equal(want, got) {
679		t.Errorf("wrong request %q, want %q", got, want)
680	}
681
682	if want, got := expectedResponse, resp; !proto.Equal(want, got) {
683		t.Errorf("wrong response %q, want %q)", got, want)
684	}
685}
686
687func TestGrafeasGetOccurrenceNoteError(t *testing.T) {
688	errCode := codes.PermissionDenied
689	mockGrafeas.err = gstatus.Error(errCode, "test error")
690
691	var formattedName string = fmt.Sprintf("projects/%s/occurrences/%s", "[PROJECT]", "[OCCURRENCE]")
692	var request = &grafeaspb.GetOccurrenceNoteRequest{
693		Name: formattedName,
694	}
695
696	c, err := NewClient(context.Background(), clientOpt)
697	if err != nil {
698		t.Fatal(err)
699	}
700
701	resp, err := c.GetOccurrenceNote(context.Background(), request)
702
703	if st, ok := gstatus.FromError(err); !ok {
704		t.Errorf("got error %v, expected grpc error", err)
705	} else if c := st.Code(); c != errCode {
706		t.Errorf("got error code %q, want %q", c, errCode)
707	}
708	_ = resp
709}
710func TestGrafeasGetNote(t *testing.T) {
711	var name2 string = "name2-1052831874"
712	var shortDescription string = "shortDescription-235369287"
713	var longDescription string = "longDescription-1747792199"
714	var expectedResponse = &grafeaspb.Note{
715		Name:             name2,
716		ShortDescription: shortDescription,
717		LongDescription:  longDescription,
718	}
719
720	mockGrafeas.err = nil
721	mockGrafeas.reqs = nil
722
723	mockGrafeas.resps = append(mockGrafeas.resps[:0], expectedResponse)
724
725	var formattedName string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
726	var request = &grafeaspb.GetNoteRequest{
727		Name: formattedName,
728	}
729
730	c, err := NewClient(context.Background(), clientOpt)
731	if err != nil {
732		t.Fatal(err)
733	}
734
735	resp, err := c.GetNote(context.Background(), request)
736
737	if err != nil {
738		t.Fatal(err)
739	}
740
741	if want, got := request, mockGrafeas.reqs[0]; !proto.Equal(want, got) {
742		t.Errorf("wrong request %q, want %q", got, want)
743	}
744
745	if want, got := expectedResponse, resp; !proto.Equal(want, got) {
746		t.Errorf("wrong response %q, want %q)", got, want)
747	}
748}
749
750func TestGrafeasGetNoteError(t *testing.T) {
751	errCode := codes.PermissionDenied
752	mockGrafeas.err = gstatus.Error(errCode, "test error")
753
754	var formattedName string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
755	var request = &grafeaspb.GetNoteRequest{
756		Name: formattedName,
757	}
758
759	c, err := NewClient(context.Background(), clientOpt)
760	if err != nil {
761		t.Fatal(err)
762	}
763
764	resp, err := c.GetNote(context.Background(), request)
765
766	if st, ok := gstatus.FromError(err); !ok {
767		t.Errorf("got error %v, expected grpc error", err)
768	} else if c := st.Code(); c != errCode {
769		t.Errorf("got error code %q, want %q", c, errCode)
770	}
771	_ = resp
772}
773func TestGrafeasListNotes(t *testing.T) {
774	var nextPageToken string = ""
775	var notesElement *grafeaspb.Note = &grafeaspb.Note{}
776	var notes = []*grafeaspb.Note{notesElement}
777	var expectedResponse = &grafeaspb.ListNotesResponse{
778		NextPageToken: nextPageToken,
779		Notes:         notes,
780	}
781
782	mockGrafeas.err = nil
783	mockGrafeas.reqs = nil
784
785	mockGrafeas.resps = append(mockGrafeas.resps[:0], expectedResponse)
786
787	var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
788	var request = &grafeaspb.ListNotesRequest{
789		Parent: formattedParent,
790	}
791
792	c, err := NewClient(context.Background(), clientOpt)
793	if err != nil {
794		t.Fatal(err)
795	}
796
797	resp, err := c.ListNotes(context.Background(), request).Next()
798
799	if err != nil {
800		t.Fatal(err)
801	}
802
803	if want, got := request, mockGrafeas.reqs[0]; !proto.Equal(want, got) {
804		t.Errorf("wrong request %q, want %q", got, want)
805	}
806
807	want := (interface{})(expectedResponse.Notes[0])
808	got := (interface{})(resp)
809	var ok bool
810
811	switch want := (want).(type) {
812	case proto.Message:
813		ok = proto.Equal(want, got.(proto.Message))
814	default:
815		ok = want == got
816	}
817	if !ok {
818		t.Errorf("wrong response %q, want %q)", got, want)
819	}
820}
821
822func TestGrafeasListNotesError(t *testing.T) {
823	errCode := codes.PermissionDenied
824	mockGrafeas.err = gstatus.Error(errCode, "test error")
825
826	var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
827	var request = &grafeaspb.ListNotesRequest{
828		Parent: formattedParent,
829	}
830
831	c, err := NewClient(context.Background(), clientOpt)
832	if err != nil {
833		t.Fatal(err)
834	}
835
836	resp, err := c.ListNotes(context.Background(), request).Next()
837
838	if st, ok := gstatus.FromError(err); !ok {
839		t.Errorf("got error %v, expected grpc error", err)
840	} else if c := st.Code(); c != errCode {
841		t.Errorf("got error code %q, want %q", c, errCode)
842	}
843	_ = resp
844}
845func TestGrafeasDeleteNote(t *testing.T) {
846	var expectedResponse *emptypb.Empty = &emptypb.Empty{}
847
848	mockGrafeas.err = nil
849	mockGrafeas.reqs = nil
850
851	mockGrafeas.resps = append(mockGrafeas.resps[:0], expectedResponse)
852
853	var formattedName string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
854	var request = &grafeaspb.DeleteNoteRequest{
855		Name: formattedName,
856	}
857
858	c, err := NewClient(context.Background(), clientOpt)
859	if err != nil {
860		t.Fatal(err)
861	}
862
863	err = c.DeleteNote(context.Background(), request)
864
865	if err != nil {
866		t.Fatal(err)
867	}
868
869	if want, got := request, mockGrafeas.reqs[0]; !proto.Equal(want, got) {
870		t.Errorf("wrong request %q, want %q", got, want)
871	}
872
873}
874
875func TestGrafeasDeleteNoteError(t *testing.T) {
876	errCode := codes.PermissionDenied
877	mockGrafeas.err = gstatus.Error(errCode, "test error")
878
879	var formattedName string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
880	var request = &grafeaspb.DeleteNoteRequest{
881		Name: formattedName,
882	}
883
884	c, err := NewClient(context.Background(), clientOpt)
885	if err != nil {
886		t.Fatal(err)
887	}
888
889	err = c.DeleteNote(context.Background(), request)
890
891	if st, ok := gstatus.FromError(err); !ok {
892		t.Errorf("got error %v, expected grpc error", err)
893	} else if c := st.Code(); c != errCode {
894		t.Errorf("got error code %q, want %q", c, errCode)
895	}
896}
897func TestGrafeasCreateNote(t *testing.T) {
898	var name string = "name3373707"
899	var shortDescription string = "shortDescription-235369287"
900	var longDescription string = "longDescription-1747792199"
901	var expectedResponse = &grafeaspb.Note{
902		Name:             name,
903		ShortDescription: shortDescription,
904		LongDescription:  longDescription,
905	}
906
907	mockGrafeas.err = nil
908	mockGrafeas.reqs = nil
909
910	mockGrafeas.resps = append(mockGrafeas.resps[:0], expectedResponse)
911
912	var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
913	var noteId string = "noteId2129224840"
914	var note *grafeaspb.Note = &grafeaspb.Note{}
915	var request = &grafeaspb.CreateNoteRequest{
916		Parent: formattedParent,
917		NoteId: noteId,
918		Note:   note,
919	}
920
921	c, err := NewClient(context.Background(), clientOpt)
922	if err != nil {
923		t.Fatal(err)
924	}
925
926	resp, err := c.CreateNote(context.Background(), request)
927
928	if err != nil {
929		t.Fatal(err)
930	}
931
932	if want, got := request, mockGrafeas.reqs[0]; !proto.Equal(want, got) {
933		t.Errorf("wrong request %q, want %q", got, want)
934	}
935
936	if want, got := expectedResponse, resp; !proto.Equal(want, got) {
937		t.Errorf("wrong response %q, want %q)", got, want)
938	}
939}
940
941func TestGrafeasCreateNoteError(t *testing.T) {
942	errCode := codes.PermissionDenied
943	mockGrafeas.err = gstatus.Error(errCode, "test error")
944
945	var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
946	var noteId string = "noteId2129224840"
947	var note *grafeaspb.Note = &grafeaspb.Note{}
948	var request = &grafeaspb.CreateNoteRequest{
949		Parent: formattedParent,
950		NoteId: noteId,
951		Note:   note,
952	}
953
954	c, err := NewClient(context.Background(), clientOpt)
955	if err != nil {
956		t.Fatal(err)
957	}
958
959	resp, err := c.CreateNote(context.Background(), request)
960
961	if st, ok := gstatus.FromError(err); !ok {
962		t.Errorf("got error %v, expected grpc error", err)
963	} else if c := st.Code(); c != errCode {
964		t.Errorf("got error code %q, want %q", c, errCode)
965	}
966	_ = resp
967}
968func TestGrafeasBatchCreateNotes(t *testing.T) {
969	var expectedResponse *grafeaspb.BatchCreateNotesResponse = &grafeaspb.BatchCreateNotesResponse{}
970
971	mockGrafeas.err = nil
972	mockGrafeas.reqs = nil
973
974	mockGrafeas.resps = append(mockGrafeas.resps[:0], expectedResponse)
975
976	var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
977	var notes map[string]*grafeaspb.Note = nil
978	var request = &grafeaspb.BatchCreateNotesRequest{
979		Parent: formattedParent,
980		Notes:  notes,
981	}
982
983	c, err := NewClient(context.Background(), clientOpt)
984	if err != nil {
985		t.Fatal(err)
986	}
987
988	resp, err := c.BatchCreateNotes(context.Background(), request)
989
990	if err != nil {
991		t.Fatal(err)
992	}
993
994	if want, got := request, mockGrafeas.reqs[0]; !proto.Equal(want, got) {
995		t.Errorf("wrong request %q, want %q", got, want)
996	}
997
998	if want, got := expectedResponse, resp; !proto.Equal(want, got) {
999		t.Errorf("wrong response %q, want %q)", got, want)
1000	}
1001}
1002
1003func TestGrafeasBatchCreateNotesError(t *testing.T) {
1004	errCode := codes.PermissionDenied
1005	mockGrafeas.err = gstatus.Error(errCode, "test error")
1006
1007	var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
1008	var notes map[string]*grafeaspb.Note = nil
1009	var request = &grafeaspb.BatchCreateNotesRequest{
1010		Parent: formattedParent,
1011		Notes:  notes,
1012	}
1013
1014	c, err := NewClient(context.Background(), clientOpt)
1015	if err != nil {
1016		t.Fatal(err)
1017	}
1018
1019	resp, err := c.BatchCreateNotes(context.Background(), request)
1020
1021	if st, ok := gstatus.FromError(err); !ok {
1022		t.Errorf("got error %v, expected grpc error", err)
1023	} else if c := st.Code(); c != errCode {
1024		t.Errorf("got error code %q, want %q", c, errCode)
1025	}
1026	_ = resp
1027}
1028func TestGrafeasUpdateNote(t *testing.T) {
1029	var name2 string = "name2-1052831874"
1030	var shortDescription string = "shortDescription-235369287"
1031	var longDescription string = "longDescription-1747792199"
1032	var expectedResponse = &grafeaspb.Note{
1033		Name:             name2,
1034		ShortDescription: shortDescription,
1035		LongDescription:  longDescription,
1036	}
1037
1038	mockGrafeas.err = nil
1039	mockGrafeas.reqs = nil
1040
1041	mockGrafeas.resps = append(mockGrafeas.resps[:0], expectedResponse)
1042
1043	var formattedName string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
1044	var note *grafeaspb.Note = &grafeaspb.Note{}
1045	var request = &grafeaspb.UpdateNoteRequest{
1046		Name: formattedName,
1047		Note: note,
1048	}
1049
1050	c, err := NewClient(context.Background(), clientOpt)
1051	if err != nil {
1052		t.Fatal(err)
1053	}
1054
1055	resp, err := c.UpdateNote(context.Background(), request)
1056
1057	if err != nil {
1058		t.Fatal(err)
1059	}
1060
1061	if want, got := request, mockGrafeas.reqs[0]; !proto.Equal(want, got) {
1062		t.Errorf("wrong request %q, want %q", got, want)
1063	}
1064
1065	if want, got := expectedResponse, resp; !proto.Equal(want, got) {
1066		t.Errorf("wrong response %q, want %q)", got, want)
1067	}
1068}
1069
1070func TestGrafeasUpdateNoteError(t *testing.T) {
1071	errCode := codes.PermissionDenied
1072	mockGrafeas.err = gstatus.Error(errCode, "test error")
1073
1074	var formattedName string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
1075	var note *grafeaspb.Note = &grafeaspb.Note{}
1076	var request = &grafeaspb.UpdateNoteRequest{
1077		Name: formattedName,
1078		Note: note,
1079	}
1080
1081	c, err := NewClient(context.Background(), clientOpt)
1082	if err != nil {
1083		t.Fatal(err)
1084	}
1085
1086	resp, err := c.UpdateNote(context.Background(), request)
1087
1088	if st, ok := gstatus.FromError(err); !ok {
1089		t.Errorf("got error %v, expected grpc error", err)
1090	} else if c := st.Code(); c != errCode {
1091		t.Errorf("got error code %q, want %q", c, errCode)
1092	}
1093	_ = resp
1094}
1095func TestGrafeasListNoteOccurrences(t *testing.T) {
1096	var nextPageToken string = ""
1097	var occurrencesElement *grafeaspb.Occurrence = &grafeaspb.Occurrence{}
1098	var occurrences = []*grafeaspb.Occurrence{occurrencesElement}
1099	var expectedResponse = &grafeaspb.ListNoteOccurrencesResponse{
1100		NextPageToken: nextPageToken,
1101		Occurrences:   occurrences,
1102	}
1103
1104	mockGrafeas.err = nil
1105	mockGrafeas.reqs = nil
1106
1107	mockGrafeas.resps = append(mockGrafeas.resps[:0], expectedResponse)
1108
1109	var formattedName string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
1110	var request = &grafeaspb.ListNoteOccurrencesRequest{
1111		Name: formattedName,
1112	}
1113
1114	c, err := NewClient(context.Background(), clientOpt)
1115	if err != nil {
1116		t.Fatal(err)
1117	}
1118
1119	resp, err := c.ListNoteOccurrences(context.Background(), request).Next()
1120
1121	if err != nil {
1122		t.Fatal(err)
1123	}
1124
1125	if want, got := request, mockGrafeas.reqs[0]; !proto.Equal(want, got) {
1126		t.Errorf("wrong request %q, want %q", got, want)
1127	}
1128
1129	want := (interface{})(expectedResponse.Occurrences[0])
1130	got := (interface{})(resp)
1131	var ok bool
1132
1133	switch want := (want).(type) {
1134	case proto.Message:
1135		ok = proto.Equal(want, got.(proto.Message))
1136	default:
1137		ok = want == got
1138	}
1139	if !ok {
1140		t.Errorf("wrong response %q, want %q)", got, want)
1141	}
1142}
1143
1144func TestGrafeasListNoteOccurrencesError(t *testing.T) {
1145	errCode := codes.PermissionDenied
1146	mockGrafeas.err = gstatus.Error(errCode, "test error")
1147
1148	var formattedName string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
1149	var request = &grafeaspb.ListNoteOccurrencesRequest{
1150		Name: formattedName,
1151	}
1152
1153	c, err := NewClient(context.Background(), clientOpt)
1154	if err != nil {
1155		t.Fatal(err)
1156	}
1157
1158	resp, err := c.ListNoteOccurrences(context.Background(), request).Next()
1159
1160	if st, ok := gstatus.FromError(err); !ok {
1161		t.Errorf("got error %v, expected grpc error", err)
1162	} else if c := st.Code(); c != errCode {
1163		t.Errorf("got error code %q, want %q", c, errCode)
1164	}
1165	_ = resp
1166}
1167