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 15package containeranalysis_test 16 17import ( 18 "context" 19 "fmt" 20 "testing" 21 22 containeranalysis "cloud.google.com/go/containeranalysis/apiv1" 23 "cloud.google.com/go/internal/testutil" 24 "google.golang.org/api/iterator" 25 grafeaspb "google.golang.org/genproto/googleapis/grafeas/v1" 26 iampb "google.golang.org/genproto/googleapis/iam/v1" 27 "google.golang.org/grpc/codes" 28 "google.golang.org/grpc/status" 29) 30 31func TestIntegration(t *testing.T) { 32 if testing.Short() { 33 t.Skip("integration tests skipped in short mode") 34 } 35 36 ctx := context.Background() 37 c, err := containeranalysis.NewClient(ctx) 38 if err != nil { 39 t.Fatal(err) 40 } 41 defer c.Close() 42 43 _, err = c.GetIamPolicy(ctx, &iampb.GetIamPolicyRequest{Resource: "some-non-existent-resource"}) 44 // We expect to get an InvalidArgument from the API. If things weren't 45 // wired up properly, we would get something like Internal, Uknown, 46 // Unathenticated, etc. 47 if err != nil && status.Code(err) != codes.InvalidArgument { 48 t.Fatal(err) 49 } 50} 51 52func TestIntegration_GetGrafeasClient(t *testing.T) { 53 if testing.Short() { 54 t.Skip("integration tests skipped in short mode") 55 } 56 57 ctx := context.Background() 58 cac, err := containeranalysis.NewClient(ctx) 59 if err != nil { 60 t.Fatal(err) 61 } 62 defer cac.Close() 63 64 gc := cac.GetGrafeasClient() 65 66 projID := testutil.ProjID() 67 68 ni := gc.ListNotes(ctx, &grafeaspb.ListNotesRequest{ 69 Parent: fmt.Sprintf("projects/%s", projID), 70 }) 71 for _, err := ni.Next(); err != iterator.Done; _, err = ni.Next() { 72 if err != nil { 73 t.Fatal(err) 74 } 75 } 76} 77