You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1709 lines
51 KiB

  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. // Code generated by gapic-generator. DO NOT EDIT.
  15. package containeranalysis
  16. import (
  17. emptypb "github.com/golang/protobuf/ptypes/empty"
  18. containeranalysispb "google.golang.org/genproto/googleapis/devtools/containeranalysis/v1beta1"
  19. grafeaspb "google.golang.org/genproto/googleapis/devtools/containeranalysis/v1beta1/grafeas"
  20. iampb "google.golang.org/genproto/googleapis/iam/v1"
  21. )
  22. import (
  23. "context"
  24. "flag"
  25. "fmt"
  26. "io"
  27. "log"
  28. "net"
  29. "os"
  30. "strings"
  31. "testing"
  32. "github.com/golang/protobuf/proto"
  33. "github.com/golang/protobuf/ptypes"
  34. "google.golang.org/api/option"
  35. status "google.golang.org/genproto/googleapis/rpc/status"
  36. "google.golang.org/grpc"
  37. "google.golang.org/grpc/codes"
  38. "google.golang.org/grpc/metadata"
  39. gstatus "google.golang.org/grpc/status"
  40. )
  41. var _ = io.EOF
  42. var _ = ptypes.MarshalAny
  43. var _ status.Status
  44. type mockContainerAnalysisV1Beta1Server struct {
  45. // Embed for forward compatibility.
  46. // Tests will keep working if more methods are added
  47. // in the future.
  48. containeranalysispb.ContainerAnalysisV1Beta1Server
  49. reqs []proto.Message
  50. // If set, all calls return this error.
  51. err error
  52. // responses to return if err == nil
  53. resps []proto.Message
  54. }
  55. func (s *mockContainerAnalysisV1Beta1Server) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest) (*iampb.Policy, error) {
  56. md, _ := metadata.FromIncomingContext(ctx)
  57. if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
  58. return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
  59. }
  60. s.reqs = append(s.reqs, req)
  61. if s.err != nil {
  62. return nil, s.err
  63. }
  64. return s.resps[0].(*iampb.Policy), nil
  65. }
  66. func (s *mockContainerAnalysisV1Beta1Server) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest) (*iampb.Policy, error) {
  67. md, _ := metadata.FromIncomingContext(ctx)
  68. if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
  69. return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
  70. }
  71. s.reqs = append(s.reqs, req)
  72. if s.err != nil {
  73. return nil, s.err
  74. }
  75. return s.resps[0].(*iampb.Policy), nil
  76. }
  77. func (s *mockContainerAnalysisV1Beta1Server) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest) (*iampb.TestIamPermissionsResponse, error) {
  78. md, _ := metadata.FromIncomingContext(ctx)
  79. if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
  80. return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
  81. }
  82. s.reqs = append(s.reqs, req)
  83. if s.err != nil {
  84. return nil, s.err
  85. }
  86. return s.resps[0].(*iampb.TestIamPermissionsResponse), nil
  87. }
  88. func (s *mockContainerAnalysisV1Beta1Server) GetScanConfig(ctx context.Context, req *containeranalysispb.GetScanConfigRequest) (*containeranalysispb.ScanConfig, error) {
  89. md, _ := metadata.FromIncomingContext(ctx)
  90. if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
  91. return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
  92. }
  93. s.reqs = append(s.reqs, req)
  94. if s.err != nil {
  95. return nil, s.err
  96. }
  97. return s.resps[0].(*containeranalysispb.ScanConfig), nil
  98. }
  99. func (s *mockContainerAnalysisV1Beta1Server) ListScanConfigs(ctx context.Context, req *containeranalysispb.ListScanConfigsRequest) (*containeranalysispb.ListScanConfigsResponse, 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].(*containeranalysispb.ListScanConfigsResponse), nil
  109. }
  110. func (s *mockContainerAnalysisV1Beta1Server) UpdateScanConfig(ctx context.Context, req *containeranalysispb.UpdateScanConfigRequest) (*containeranalysispb.ScanConfig, error) {
  111. md, _ := metadata.FromIncomingContext(ctx)
  112. if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
  113. return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
  114. }
  115. s.reqs = append(s.reqs, req)
  116. if s.err != nil {
  117. return nil, s.err
  118. }
  119. return s.resps[0].(*containeranalysispb.ScanConfig), nil
  120. }
  121. type mockGrafeasV1Beta1Server struct {
  122. // Embed for forward compatibility.
  123. // Tests will keep working if more methods are added
  124. // in the future.
  125. grafeaspb.GrafeasV1Beta1Server
  126. reqs []proto.Message
  127. // If set, all calls return this error.
  128. err error
  129. // responses to return if err == nil
  130. resps []proto.Message
  131. }
  132. func (s *mockGrafeasV1Beta1Server) GetOccurrence(ctx context.Context, req *grafeaspb.GetOccurrenceRequest) (*grafeaspb.Occurrence, error) {
  133. md, _ := metadata.FromIncomingContext(ctx)
  134. if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
  135. return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
  136. }
  137. s.reqs = append(s.reqs, req)
  138. if s.err != nil {
  139. return nil, s.err
  140. }
  141. return s.resps[0].(*grafeaspb.Occurrence), nil
  142. }
  143. func (s *mockGrafeasV1Beta1Server) ListOccurrences(ctx context.Context, req *grafeaspb.ListOccurrencesRequest) (*grafeaspb.ListOccurrencesResponse, error) {
  144. md, _ := metadata.FromIncomingContext(ctx)
  145. if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
  146. return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
  147. }
  148. s.reqs = append(s.reqs, req)
  149. if s.err != nil {
  150. return nil, s.err
  151. }
  152. return s.resps[0].(*grafeaspb.ListOccurrencesResponse), nil
  153. }
  154. func (s *mockGrafeasV1Beta1Server) DeleteOccurrence(ctx context.Context, req *grafeaspb.DeleteOccurrenceRequest) (*emptypb.Empty, error) {
  155. md, _ := metadata.FromIncomingContext(ctx)
  156. if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
  157. return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
  158. }
  159. s.reqs = append(s.reqs, req)
  160. if s.err != nil {
  161. return nil, s.err
  162. }
  163. return s.resps[0].(*emptypb.Empty), nil
  164. }
  165. func (s *mockGrafeasV1Beta1Server) CreateOccurrence(ctx context.Context, req *grafeaspb.CreateOccurrenceRequest) (*grafeaspb.Occurrence, error) {
  166. md, _ := metadata.FromIncomingContext(ctx)
  167. if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
  168. return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
  169. }
  170. s.reqs = append(s.reqs, req)
  171. if s.err != nil {
  172. return nil, s.err
  173. }
  174. return s.resps[0].(*grafeaspb.Occurrence), nil
  175. }
  176. func (s *mockGrafeasV1Beta1Server) BatchCreateOccurrences(ctx context.Context, req *grafeaspb.BatchCreateOccurrencesRequest) (*grafeaspb.BatchCreateOccurrencesResponse, error) {
  177. md, _ := metadata.FromIncomingContext(ctx)
  178. if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
  179. return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
  180. }
  181. s.reqs = append(s.reqs, req)
  182. if s.err != nil {
  183. return nil, s.err
  184. }
  185. return s.resps[0].(*grafeaspb.BatchCreateOccurrencesResponse), nil
  186. }
  187. func (s *mockGrafeasV1Beta1Server) UpdateOccurrence(ctx context.Context, req *grafeaspb.UpdateOccurrenceRequest) (*grafeaspb.Occurrence, error) {
  188. md, _ := metadata.FromIncomingContext(ctx)
  189. if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
  190. return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
  191. }
  192. s.reqs = append(s.reqs, req)
  193. if s.err != nil {
  194. return nil, s.err
  195. }
  196. return s.resps[0].(*grafeaspb.Occurrence), nil
  197. }
  198. func (s *mockGrafeasV1Beta1Server) GetOccurrenceNote(ctx context.Context, req *grafeaspb.GetOccurrenceNoteRequest) (*grafeaspb.Note, error) {
  199. md, _ := metadata.FromIncomingContext(ctx)
  200. if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
  201. return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
  202. }
  203. s.reqs = append(s.reqs, req)
  204. if s.err != nil {
  205. return nil, s.err
  206. }
  207. return s.resps[0].(*grafeaspb.Note), nil
  208. }
  209. func (s *mockGrafeasV1Beta1Server) GetNote(ctx context.Context, req *grafeaspb.GetNoteRequest) (*grafeaspb.Note, error) {
  210. md, _ := metadata.FromIncomingContext(ctx)
  211. if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
  212. return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
  213. }
  214. s.reqs = append(s.reqs, req)
  215. if s.err != nil {
  216. return nil, s.err
  217. }
  218. return s.resps[0].(*grafeaspb.Note), nil
  219. }
  220. func (s *mockGrafeasV1Beta1Server) ListNotes(ctx context.Context, req *grafeaspb.ListNotesRequest) (*grafeaspb.ListNotesResponse, error) {
  221. md, _ := metadata.FromIncomingContext(ctx)
  222. if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
  223. return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
  224. }
  225. s.reqs = append(s.reqs, req)
  226. if s.err != nil {
  227. return nil, s.err
  228. }
  229. return s.resps[0].(*grafeaspb.ListNotesResponse), nil
  230. }
  231. func (s *mockGrafeasV1Beta1Server) DeleteNote(ctx context.Context, req *grafeaspb.DeleteNoteRequest) (*emptypb.Empty, error) {
  232. md, _ := metadata.FromIncomingContext(ctx)
  233. if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
  234. return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
  235. }
  236. s.reqs = append(s.reqs, req)
  237. if s.err != nil {
  238. return nil, s.err
  239. }
  240. return s.resps[0].(*emptypb.Empty), nil
  241. }
  242. func (s *mockGrafeasV1Beta1Server) CreateNote(ctx context.Context, req *grafeaspb.CreateNoteRequest) (*grafeaspb.Note, error) {
  243. md, _ := metadata.FromIncomingContext(ctx)
  244. if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
  245. return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
  246. }
  247. s.reqs = append(s.reqs, req)
  248. if s.err != nil {
  249. return nil, s.err
  250. }
  251. return s.resps[0].(*grafeaspb.Note), nil
  252. }
  253. func (s *mockGrafeasV1Beta1Server) BatchCreateNotes(ctx context.Context, req *grafeaspb.BatchCreateNotesRequest) (*grafeaspb.BatchCreateNotesResponse, error) {
  254. md, _ := metadata.FromIncomingContext(ctx)
  255. if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
  256. return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
  257. }
  258. s.reqs = append(s.reqs, req)
  259. if s.err != nil {
  260. return nil, s.err
  261. }
  262. return s.resps[0].(*grafeaspb.BatchCreateNotesResponse), nil
  263. }
  264. func (s *mockGrafeasV1Beta1Server) UpdateNote(ctx context.Context, req *grafeaspb.UpdateNoteRequest) (*grafeaspb.Note, error) {
  265. md, _ := metadata.FromIncomingContext(ctx)
  266. if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
  267. return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
  268. }
  269. s.reqs = append(s.reqs, req)
  270. if s.err != nil {
  271. return nil, s.err
  272. }
  273. return s.resps[0].(*grafeaspb.Note), nil
  274. }
  275. func (s *mockGrafeasV1Beta1Server) ListNoteOccurrences(ctx context.Context, req *grafeaspb.ListNoteOccurrencesRequest) (*grafeaspb.ListNoteOccurrencesResponse, error) {
  276. md, _ := metadata.FromIncomingContext(ctx)
  277. if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
  278. return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
  279. }
  280. s.reqs = append(s.reqs, req)
  281. if s.err != nil {
  282. return nil, s.err
  283. }
  284. return s.resps[0].(*grafeaspb.ListNoteOccurrencesResponse), nil
  285. }
  286. func (s *mockGrafeasV1Beta1Server) GetVulnerabilityOccurrencesSummary(ctx context.Context, req *grafeaspb.GetVulnerabilityOccurrencesSummaryRequest) (*grafeaspb.VulnerabilityOccurrencesSummary, error) {
  287. md, _ := metadata.FromIncomingContext(ctx)
  288. if xg := md["x-goog-api-client"]; len(xg) == 0 || !strings.Contains(xg[0], "gl-go/") {
  289. return nil, fmt.Errorf("x-goog-api-client = %v, expected gl-go key", xg)
  290. }
  291. s.reqs = append(s.reqs, req)
  292. if s.err != nil {
  293. return nil, s.err
  294. }
  295. return s.resps[0].(*grafeaspb.VulnerabilityOccurrencesSummary), nil
  296. }
  297. // clientOpt is the option tests should use to connect to the test server.
  298. // It is initialized by TestMain.
  299. var clientOpt option.ClientOption
  300. var (
  301. mockContainerAnalysisV1Beta1 mockContainerAnalysisV1Beta1Server
  302. mockGrafeasV1Beta1 mockGrafeasV1Beta1Server
  303. )
  304. func TestMain(m *testing.M) {
  305. flag.Parse()
  306. serv := grpc.NewServer()
  307. containeranalysispb.RegisterContainerAnalysisV1Beta1Server(serv, &mockContainerAnalysisV1Beta1)
  308. grafeaspb.RegisterGrafeasV1Beta1Server(serv, &mockGrafeasV1Beta1)
  309. lis, err := net.Listen("tcp", "localhost:0")
  310. if err != nil {
  311. log.Fatal(err)
  312. }
  313. go serv.Serve(lis)
  314. conn, err := grpc.Dial(lis.Addr().String(), grpc.WithInsecure())
  315. if err != nil {
  316. log.Fatal(err)
  317. }
  318. clientOpt = option.WithGRPCConn(conn)
  319. os.Exit(m.Run())
  320. }
  321. func TestContainerAnalysisV1Beta1SetIamPolicy(t *testing.T) {
  322. var version int32 = 351608024
  323. var etag []byte = []byte("21")
  324. var expectedResponse = &iampb.Policy{
  325. Version: version,
  326. Etag: etag,
  327. }
  328. mockContainerAnalysisV1Beta1.err = nil
  329. mockContainerAnalysisV1Beta1.reqs = nil
  330. mockContainerAnalysisV1Beta1.resps = append(mockContainerAnalysisV1Beta1.resps[:0], expectedResponse)
  331. var formattedResource string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
  332. var policy *iampb.Policy = &iampb.Policy{}
  333. var request = &iampb.SetIamPolicyRequest{
  334. Resource: formattedResource,
  335. Policy: policy,
  336. }
  337. c, err := NewContainerAnalysisV1Beta1Client(context.Background(), clientOpt)
  338. if err != nil {
  339. t.Fatal(err)
  340. }
  341. resp, err := c.SetIamPolicy(context.Background(), request)
  342. if err != nil {
  343. t.Fatal(err)
  344. }
  345. if want, got := request, mockContainerAnalysisV1Beta1.reqs[0]; !proto.Equal(want, got) {
  346. t.Errorf("wrong request %q, want %q", got, want)
  347. }
  348. if want, got := expectedResponse, resp; !proto.Equal(want, got) {
  349. t.Errorf("wrong response %q, want %q)", got, want)
  350. }
  351. }
  352. func TestContainerAnalysisV1Beta1SetIamPolicyError(t *testing.T) {
  353. errCode := codes.PermissionDenied
  354. mockContainerAnalysisV1Beta1.err = gstatus.Error(errCode, "test error")
  355. var formattedResource string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
  356. var policy *iampb.Policy = &iampb.Policy{}
  357. var request = &iampb.SetIamPolicyRequest{
  358. Resource: formattedResource,
  359. Policy: policy,
  360. }
  361. c, err := NewContainerAnalysisV1Beta1Client(context.Background(), clientOpt)
  362. if err != nil {
  363. t.Fatal(err)
  364. }
  365. resp, err := c.SetIamPolicy(context.Background(), request)
  366. if st, ok := gstatus.FromError(err); !ok {
  367. t.Errorf("got error %v, expected grpc error", err)
  368. } else if c := st.Code(); c != errCode {
  369. t.Errorf("got error code %q, want %q", c, errCode)
  370. }
  371. _ = resp
  372. }
  373. func TestContainerAnalysisV1Beta1GetIamPolicy(t *testing.T) {
  374. var version int32 = 351608024
  375. var etag []byte = []byte("21")
  376. var expectedResponse = &iampb.Policy{
  377. Version: version,
  378. Etag: etag,
  379. }
  380. mockContainerAnalysisV1Beta1.err = nil
  381. mockContainerAnalysisV1Beta1.reqs = nil
  382. mockContainerAnalysisV1Beta1.resps = append(mockContainerAnalysisV1Beta1.resps[:0], expectedResponse)
  383. var formattedResource string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
  384. var request = &iampb.GetIamPolicyRequest{
  385. Resource: formattedResource,
  386. }
  387. c, err := NewContainerAnalysisV1Beta1Client(context.Background(), clientOpt)
  388. if err != nil {
  389. t.Fatal(err)
  390. }
  391. resp, err := c.GetIamPolicy(context.Background(), request)
  392. if err != nil {
  393. t.Fatal(err)
  394. }
  395. if want, got := request, mockContainerAnalysisV1Beta1.reqs[0]; !proto.Equal(want, got) {
  396. t.Errorf("wrong request %q, want %q", got, want)
  397. }
  398. if want, got := expectedResponse, resp; !proto.Equal(want, got) {
  399. t.Errorf("wrong response %q, want %q)", got, want)
  400. }
  401. }
  402. func TestContainerAnalysisV1Beta1GetIamPolicyError(t *testing.T) {
  403. errCode := codes.PermissionDenied
  404. mockContainerAnalysisV1Beta1.err = gstatus.Error(errCode, "test error")
  405. var formattedResource string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
  406. var request = &iampb.GetIamPolicyRequest{
  407. Resource: formattedResource,
  408. }
  409. c, err := NewContainerAnalysisV1Beta1Client(context.Background(), clientOpt)
  410. if err != nil {
  411. t.Fatal(err)
  412. }
  413. resp, err := c.GetIamPolicy(context.Background(), request)
  414. if st, ok := gstatus.FromError(err); !ok {
  415. t.Errorf("got error %v, expected grpc error", err)
  416. } else if c := st.Code(); c != errCode {
  417. t.Errorf("got error code %q, want %q", c, errCode)
  418. }
  419. _ = resp
  420. }
  421. func TestContainerAnalysisV1Beta1TestIamPermissions(t *testing.T) {
  422. var expectedResponse *iampb.TestIamPermissionsResponse = &iampb.TestIamPermissionsResponse{}
  423. mockContainerAnalysisV1Beta1.err = nil
  424. mockContainerAnalysisV1Beta1.reqs = nil
  425. mockContainerAnalysisV1Beta1.resps = append(mockContainerAnalysisV1Beta1.resps[:0], expectedResponse)
  426. var formattedResource string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
  427. var permissions []string = nil
  428. var request = &iampb.TestIamPermissionsRequest{
  429. Resource: formattedResource,
  430. Permissions: permissions,
  431. }
  432. c, err := NewContainerAnalysisV1Beta1Client(context.Background(), clientOpt)
  433. if err != nil {
  434. t.Fatal(err)
  435. }
  436. resp, err := c.TestIamPermissions(context.Background(), request)
  437. if err != nil {
  438. t.Fatal(err)
  439. }
  440. if want, got := request, mockContainerAnalysisV1Beta1.reqs[0]; !proto.Equal(want, got) {
  441. t.Errorf("wrong request %q, want %q", got, want)
  442. }
  443. if want, got := expectedResponse, resp; !proto.Equal(want, got) {
  444. t.Errorf("wrong response %q, want %q)", got, want)
  445. }
  446. }
  447. func TestContainerAnalysisV1Beta1TestIamPermissionsError(t *testing.T) {
  448. errCode := codes.PermissionDenied
  449. mockContainerAnalysisV1Beta1.err = gstatus.Error(errCode, "test error")
  450. var formattedResource string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
  451. var permissions []string = nil
  452. var request = &iampb.TestIamPermissionsRequest{
  453. Resource: formattedResource,
  454. Permissions: permissions,
  455. }
  456. c, err := NewContainerAnalysisV1Beta1Client(context.Background(), clientOpt)
  457. if err != nil {
  458. t.Fatal(err)
  459. }
  460. resp, err := c.TestIamPermissions(context.Background(), request)
  461. if st, ok := gstatus.FromError(err); !ok {
  462. t.Errorf("got error %v, expected grpc error", err)
  463. } else if c := st.Code(); c != errCode {
  464. t.Errorf("got error code %q, want %q", c, errCode)
  465. }
  466. _ = resp
  467. }
  468. func TestContainerAnalysisV1Beta1GetScanConfig(t *testing.T) {
  469. var name2 string = "name2-1052831874"
  470. var description string = "description-1724546052"
  471. var enabled bool = false
  472. var expectedResponse = &containeranalysispb.ScanConfig{
  473. Name: name2,
  474. Description: description,
  475. Enabled: enabled,
  476. }
  477. mockContainerAnalysisV1Beta1.err = nil
  478. mockContainerAnalysisV1Beta1.reqs = nil
  479. mockContainerAnalysisV1Beta1.resps = append(mockContainerAnalysisV1Beta1.resps[:0], expectedResponse)
  480. var formattedName string = fmt.Sprintf("projects/%s/scanConfigs/%s", "[PROJECT]", "[SCAN_CONFIG]")
  481. var request = &containeranalysispb.GetScanConfigRequest{
  482. Name: formattedName,
  483. }
  484. c, err := NewContainerAnalysisV1Beta1Client(context.Background(), clientOpt)
  485. if err != nil {
  486. t.Fatal(err)
  487. }
  488. resp, err := c.GetScanConfig(context.Background(), request)
  489. if err != nil {
  490. t.Fatal(err)
  491. }
  492. if want, got := request, mockContainerAnalysisV1Beta1.reqs[0]; !proto.Equal(want, got) {
  493. t.Errorf("wrong request %q, want %q", got, want)
  494. }
  495. if want, got := expectedResponse, resp; !proto.Equal(want, got) {
  496. t.Errorf("wrong response %q, want %q)", got, want)
  497. }
  498. }
  499. func TestContainerAnalysisV1Beta1GetScanConfigError(t *testing.T) {
  500. errCode := codes.PermissionDenied
  501. mockContainerAnalysisV1Beta1.err = gstatus.Error(errCode, "test error")
  502. var formattedName string = fmt.Sprintf("projects/%s/scanConfigs/%s", "[PROJECT]", "[SCAN_CONFIG]")
  503. var request = &containeranalysispb.GetScanConfigRequest{
  504. Name: formattedName,
  505. }
  506. c, err := NewContainerAnalysisV1Beta1Client(context.Background(), clientOpt)
  507. if err != nil {
  508. t.Fatal(err)
  509. }
  510. resp, err := c.GetScanConfig(context.Background(), request)
  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. }
  518. func TestContainerAnalysisV1Beta1ListScanConfigs(t *testing.T) {
  519. var nextPageToken string = ""
  520. var scanConfigsElement *containeranalysispb.ScanConfig = &containeranalysispb.ScanConfig{}
  521. var scanConfigs = []*containeranalysispb.ScanConfig{scanConfigsElement}
  522. var expectedResponse = &containeranalysispb.ListScanConfigsResponse{
  523. NextPageToken: nextPageToken,
  524. ScanConfigs: scanConfigs,
  525. }
  526. mockContainerAnalysisV1Beta1.err = nil
  527. mockContainerAnalysisV1Beta1.reqs = nil
  528. mockContainerAnalysisV1Beta1.resps = append(mockContainerAnalysisV1Beta1.resps[:0], expectedResponse)
  529. var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
  530. var request = &containeranalysispb.ListScanConfigsRequest{
  531. Parent: formattedParent,
  532. }
  533. c, err := NewContainerAnalysisV1Beta1Client(context.Background(), clientOpt)
  534. if err != nil {
  535. t.Fatal(err)
  536. }
  537. resp, err := c.ListScanConfigs(context.Background(), request).Next()
  538. if err != nil {
  539. t.Fatal(err)
  540. }
  541. if want, got := request, mockContainerAnalysisV1Beta1.reqs[0]; !proto.Equal(want, got) {
  542. t.Errorf("wrong request %q, want %q", got, want)
  543. }
  544. want := (interface{})(expectedResponse.ScanConfigs[0])
  545. got := (interface{})(resp)
  546. var ok bool
  547. switch want := (want).(type) {
  548. case proto.Message:
  549. ok = proto.Equal(want, got.(proto.Message))
  550. default:
  551. ok = want == got
  552. }
  553. if !ok {
  554. t.Errorf("wrong response %q, want %q)", got, want)
  555. }
  556. }
  557. func TestContainerAnalysisV1Beta1ListScanConfigsError(t *testing.T) {
  558. errCode := codes.PermissionDenied
  559. mockContainerAnalysisV1Beta1.err = gstatus.Error(errCode, "test error")
  560. var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
  561. var request = &containeranalysispb.ListScanConfigsRequest{
  562. Parent: formattedParent,
  563. }
  564. c, err := NewContainerAnalysisV1Beta1Client(context.Background(), clientOpt)
  565. if err != nil {
  566. t.Fatal(err)
  567. }
  568. resp, err := c.ListScanConfigs(context.Background(), request).Next()
  569. if st, ok := gstatus.FromError(err); !ok {
  570. t.Errorf("got error %v, expected grpc error", err)
  571. } else if c := st.Code(); c != errCode {
  572. t.Errorf("got error code %q, want %q", c, errCode)
  573. }
  574. _ = resp
  575. }
  576. func TestContainerAnalysisV1Beta1UpdateScanConfig(t *testing.T) {
  577. var name2 string = "name2-1052831874"
  578. var description string = "description-1724546052"
  579. var enabled bool = false
  580. var expectedResponse = &containeranalysispb.ScanConfig{
  581. Name: name2,
  582. Description: description,
  583. Enabled: enabled,
  584. }
  585. mockContainerAnalysisV1Beta1.err = nil
  586. mockContainerAnalysisV1Beta1.reqs = nil
  587. mockContainerAnalysisV1Beta1.resps = append(mockContainerAnalysisV1Beta1.resps[:0], expectedResponse)
  588. var formattedName string = fmt.Sprintf("projects/%s/scanConfigs/%s", "[PROJECT]", "[SCAN_CONFIG]")
  589. var scanConfig *containeranalysispb.ScanConfig = &containeranalysispb.ScanConfig{}
  590. var request = &containeranalysispb.UpdateScanConfigRequest{
  591. Name: formattedName,
  592. ScanConfig: scanConfig,
  593. }
  594. c, err := NewContainerAnalysisV1Beta1Client(context.Background(), clientOpt)
  595. if err != nil {
  596. t.Fatal(err)
  597. }
  598. resp, err := c.UpdateScanConfig(context.Background(), request)
  599. if err != nil {
  600. t.Fatal(err)
  601. }
  602. if want, got := request, mockContainerAnalysisV1Beta1.reqs[0]; !proto.Equal(want, got) {
  603. t.Errorf("wrong request %q, want %q", got, want)
  604. }
  605. if want, got := expectedResponse, resp; !proto.Equal(want, got) {
  606. t.Errorf("wrong response %q, want %q)", got, want)
  607. }
  608. }
  609. func TestContainerAnalysisV1Beta1UpdateScanConfigError(t *testing.T) {
  610. errCode := codes.PermissionDenied
  611. mockContainerAnalysisV1Beta1.err = gstatus.Error(errCode, "test error")
  612. var formattedName string = fmt.Sprintf("projects/%s/scanConfigs/%s", "[PROJECT]", "[SCAN_CONFIG]")
  613. var scanConfig *containeranalysispb.ScanConfig = &containeranalysispb.ScanConfig{}
  614. var request = &containeranalysispb.UpdateScanConfigRequest{
  615. Name: formattedName,
  616. ScanConfig: scanConfig,
  617. }
  618. c, err := NewContainerAnalysisV1Beta1Client(context.Background(), clientOpt)
  619. if err != nil {
  620. t.Fatal(err)
  621. }
  622. resp, err := c.UpdateScanConfig(context.Background(), request)
  623. if st, ok := gstatus.FromError(err); !ok {
  624. t.Errorf("got error %v, expected grpc error", err)
  625. } else if c := st.Code(); c != errCode {
  626. t.Errorf("got error code %q, want %q", c, errCode)
  627. }
  628. _ = resp
  629. }
  630. func TestGrafeasV1Beta1GetOccurrence(t *testing.T) {
  631. var name2 string = "name2-1052831874"
  632. var noteName string = "noteName1780787896"
  633. var remediation string = "remediation779381797"
  634. var expectedResponse = &grafeaspb.Occurrence{
  635. Name: name2,
  636. NoteName: noteName,
  637. Remediation: remediation,
  638. }
  639. mockGrafeasV1Beta1.err = nil
  640. mockGrafeasV1Beta1.reqs = nil
  641. mockGrafeasV1Beta1.resps = append(mockGrafeasV1Beta1.resps[:0], expectedResponse)
  642. var formattedName string = fmt.Sprintf("projects/%s/occurrences/%s", "[PROJECT]", "[OCCURRENCE]")
  643. var request = &grafeaspb.GetOccurrenceRequest{
  644. Name: formattedName,
  645. }
  646. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  647. if err != nil {
  648. t.Fatal(err)
  649. }
  650. resp, err := c.GetOccurrence(context.Background(), request)
  651. if err != nil {
  652. t.Fatal(err)
  653. }
  654. if want, got := request, mockGrafeasV1Beta1.reqs[0]; !proto.Equal(want, got) {
  655. t.Errorf("wrong request %q, want %q", got, want)
  656. }
  657. if want, got := expectedResponse, resp; !proto.Equal(want, got) {
  658. t.Errorf("wrong response %q, want %q)", got, want)
  659. }
  660. }
  661. func TestGrafeasV1Beta1GetOccurrenceError(t *testing.T) {
  662. errCode := codes.PermissionDenied
  663. mockGrafeasV1Beta1.err = gstatus.Error(errCode, "test error")
  664. var formattedName string = fmt.Sprintf("projects/%s/occurrences/%s", "[PROJECT]", "[OCCURRENCE]")
  665. var request = &grafeaspb.GetOccurrenceRequest{
  666. Name: formattedName,
  667. }
  668. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  669. if err != nil {
  670. t.Fatal(err)
  671. }
  672. resp, err := c.GetOccurrence(context.Background(), request)
  673. if st, ok := gstatus.FromError(err); !ok {
  674. t.Errorf("got error %v, expected grpc error", err)
  675. } else if c := st.Code(); c != errCode {
  676. t.Errorf("got error code %q, want %q", c, errCode)
  677. }
  678. _ = resp
  679. }
  680. func TestGrafeasV1Beta1ListOccurrences(t *testing.T) {
  681. var nextPageToken string = ""
  682. var occurrencesElement *grafeaspb.Occurrence = &grafeaspb.Occurrence{}
  683. var occurrences = []*grafeaspb.Occurrence{occurrencesElement}
  684. var expectedResponse = &grafeaspb.ListOccurrencesResponse{
  685. NextPageToken: nextPageToken,
  686. Occurrences: occurrences,
  687. }
  688. mockGrafeasV1Beta1.err = nil
  689. mockGrafeasV1Beta1.reqs = nil
  690. mockGrafeasV1Beta1.resps = append(mockGrafeasV1Beta1.resps[:0], expectedResponse)
  691. var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
  692. var request = &grafeaspb.ListOccurrencesRequest{
  693. Parent: formattedParent,
  694. }
  695. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  696. if err != nil {
  697. t.Fatal(err)
  698. }
  699. resp, err := c.ListOccurrences(context.Background(), request).Next()
  700. if err != nil {
  701. t.Fatal(err)
  702. }
  703. if want, got := request, mockGrafeasV1Beta1.reqs[0]; !proto.Equal(want, got) {
  704. t.Errorf("wrong request %q, want %q", got, want)
  705. }
  706. want := (interface{})(expectedResponse.Occurrences[0])
  707. got := (interface{})(resp)
  708. var ok bool
  709. switch want := (want).(type) {
  710. case proto.Message:
  711. ok = proto.Equal(want, got.(proto.Message))
  712. default:
  713. ok = want == got
  714. }
  715. if !ok {
  716. t.Errorf("wrong response %q, want %q)", got, want)
  717. }
  718. }
  719. func TestGrafeasV1Beta1ListOccurrencesError(t *testing.T) {
  720. errCode := codes.PermissionDenied
  721. mockGrafeasV1Beta1.err = gstatus.Error(errCode, "test error")
  722. var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
  723. var request = &grafeaspb.ListOccurrencesRequest{
  724. Parent: formattedParent,
  725. }
  726. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  727. if err != nil {
  728. t.Fatal(err)
  729. }
  730. resp, err := c.ListOccurrences(context.Background(), request).Next()
  731. if st, ok := gstatus.FromError(err); !ok {
  732. t.Errorf("got error %v, expected grpc error", err)
  733. } else if c := st.Code(); c != errCode {
  734. t.Errorf("got error code %q, want %q", c, errCode)
  735. }
  736. _ = resp
  737. }
  738. func TestGrafeasV1Beta1DeleteOccurrence(t *testing.T) {
  739. var expectedResponse *emptypb.Empty = &emptypb.Empty{}
  740. mockGrafeasV1Beta1.err = nil
  741. mockGrafeasV1Beta1.reqs = nil
  742. mockGrafeasV1Beta1.resps = append(mockGrafeasV1Beta1.resps[:0], expectedResponse)
  743. var formattedName string = fmt.Sprintf("projects/%s/occurrences/%s", "[PROJECT]", "[OCCURRENCE]")
  744. var request = &grafeaspb.DeleteOccurrenceRequest{
  745. Name: formattedName,
  746. }
  747. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  748. if err != nil {
  749. t.Fatal(err)
  750. }
  751. err = c.DeleteOccurrence(context.Background(), request)
  752. if err != nil {
  753. t.Fatal(err)
  754. }
  755. if want, got := request, mockGrafeasV1Beta1.reqs[0]; !proto.Equal(want, got) {
  756. t.Errorf("wrong request %q, want %q", got, want)
  757. }
  758. }
  759. func TestGrafeasV1Beta1DeleteOccurrenceError(t *testing.T) {
  760. errCode := codes.PermissionDenied
  761. mockGrafeasV1Beta1.err = gstatus.Error(errCode, "test error")
  762. var formattedName string = fmt.Sprintf("projects/%s/occurrences/%s", "[PROJECT]", "[OCCURRENCE]")
  763. var request = &grafeaspb.DeleteOccurrenceRequest{
  764. Name: formattedName,
  765. }
  766. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  767. if err != nil {
  768. t.Fatal(err)
  769. }
  770. err = c.DeleteOccurrence(context.Background(), request)
  771. if st, ok := gstatus.FromError(err); !ok {
  772. t.Errorf("got error %v, expected grpc error", err)
  773. } else if c := st.Code(); c != errCode {
  774. t.Errorf("got error code %q, want %q", c, errCode)
  775. }
  776. }
  777. func TestGrafeasV1Beta1CreateOccurrence(t *testing.T) {
  778. var name string = "name3373707"
  779. var noteName string = "noteName1780787896"
  780. var remediation string = "remediation779381797"
  781. var expectedResponse = &grafeaspb.Occurrence{
  782. Name: name,
  783. NoteName: noteName,
  784. Remediation: remediation,
  785. }
  786. mockGrafeasV1Beta1.err = nil
  787. mockGrafeasV1Beta1.reqs = nil
  788. mockGrafeasV1Beta1.resps = append(mockGrafeasV1Beta1.resps[:0], expectedResponse)
  789. var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
  790. var occurrence *grafeaspb.Occurrence = &grafeaspb.Occurrence{}
  791. var request = &grafeaspb.CreateOccurrenceRequest{
  792. Parent: formattedParent,
  793. Occurrence: occurrence,
  794. }
  795. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  796. if err != nil {
  797. t.Fatal(err)
  798. }
  799. resp, err := c.CreateOccurrence(context.Background(), request)
  800. if err != nil {
  801. t.Fatal(err)
  802. }
  803. if want, got := request, mockGrafeasV1Beta1.reqs[0]; !proto.Equal(want, got) {
  804. t.Errorf("wrong request %q, want %q", got, want)
  805. }
  806. if want, got := expectedResponse, resp; !proto.Equal(want, got) {
  807. t.Errorf("wrong response %q, want %q)", got, want)
  808. }
  809. }
  810. func TestGrafeasV1Beta1CreateOccurrenceError(t *testing.T) {
  811. errCode := codes.PermissionDenied
  812. mockGrafeasV1Beta1.err = gstatus.Error(errCode, "test error")
  813. var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
  814. var occurrence *grafeaspb.Occurrence = &grafeaspb.Occurrence{}
  815. var request = &grafeaspb.CreateOccurrenceRequest{
  816. Parent: formattedParent,
  817. Occurrence: occurrence,
  818. }
  819. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  820. if err != nil {
  821. t.Fatal(err)
  822. }
  823. resp, err := c.CreateOccurrence(context.Background(), request)
  824. if st, ok := gstatus.FromError(err); !ok {
  825. t.Errorf("got error %v, expected grpc error", err)
  826. } else if c := st.Code(); c != errCode {
  827. t.Errorf("got error code %q, want %q", c, errCode)
  828. }
  829. _ = resp
  830. }
  831. func TestGrafeasV1Beta1BatchCreateOccurrences(t *testing.T) {
  832. var expectedResponse *grafeaspb.BatchCreateOccurrencesResponse = &grafeaspb.BatchCreateOccurrencesResponse{}
  833. mockGrafeasV1Beta1.err = nil
  834. mockGrafeasV1Beta1.reqs = nil
  835. mockGrafeasV1Beta1.resps = append(mockGrafeasV1Beta1.resps[:0], expectedResponse)
  836. var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
  837. var occurrences []*grafeaspb.Occurrence = nil
  838. var request = &grafeaspb.BatchCreateOccurrencesRequest{
  839. Parent: formattedParent,
  840. Occurrences: occurrences,
  841. }
  842. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  843. if err != nil {
  844. t.Fatal(err)
  845. }
  846. resp, err := c.BatchCreateOccurrences(context.Background(), request)
  847. if err != nil {
  848. t.Fatal(err)
  849. }
  850. if want, got := request, mockGrafeasV1Beta1.reqs[0]; !proto.Equal(want, got) {
  851. t.Errorf("wrong request %q, want %q", got, want)
  852. }
  853. if want, got := expectedResponse, resp; !proto.Equal(want, got) {
  854. t.Errorf("wrong response %q, want %q)", got, want)
  855. }
  856. }
  857. func TestGrafeasV1Beta1BatchCreateOccurrencesError(t *testing.T) {
  858. errCode := codes.PermissionDenied
  859. mockGrafeasV1Beta1.err = gstatus.Error(errCode, "test error")
  860. var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
  861. var occurrences []*grafeaspb.Occurrence = nil
  862. var request = &grafeaspb.BatchCreateOccurrencesRequest{
  863. Parent: formattedParent,
  864. Occurrences: occurrences,
  865. }
  866. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  867. if err != nil {
  868. t.Fatal(err)
  869. }
  870. resp, err := c.BatchCreateOccurrences(context.Background(), request)
  871. if st, ok := gstatus.FromError(err); !ok {
  872. t.Errorf("got error %v, expected grpc error", err)
  873. } else if c := st.Code(); c != errCode {
  874. t.Errorf("got error code %q, want %q", c, errCode)
  875. }
  876. _ = resp
  877. }
  878. func TestGrafeasV1Beta1UpdateOccurrence(t *testing.T) {
  879. var name2 string = "name2-1052831874"
  880. var noteName string = "noteName1780787896"
  881. var remediation string = "remediation779381797"
  882. var expectedResponse = &grafeaspb.Occurrence{
  883. Name: name2,
  884. NoteName: noteName,
  885. Remediation: remediation,
  886. }
  887. mockGrafeasV1Beta1.err = nil
  888. mockGrafeasV1Beta1.reqs = nil
  889. mockGrafeasV1Beta1.resps = append(mockGrafeasV1Beta1.resps[:0], expectedResponse)
  890. var formattedName string = fmt.Sprintf("projects/%s/occurrences/%s", "[PROJECT]", "[OCCURRENCE]")
  891. var occurrence *grafeaspb.Occurrence = &grafeaspb.Occurrence{}
  892. var request = &grafeaspb.UpdateOccurrenceRequest{
  893. Name: formattedName,
  894. Occurrence: occurrence,
  895. }
  896. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  897. if err != nil {
  898. t.Fatal(err)
  899. }
  900. resp, err := c.UpdateOccurrence(context.Background(), request)
  901. if err != nil {
  902. t.Fatal(err)
  903. }
  904. if want, got := request, mockGrafeasV1Beta1.reqs[0]; !proto.Equal(want, got) {
  905. t.Errorf("wrong request %q, want %q", got, want)
  906. }
  907. if want, got := expectedResponse, resp; !proto.Equal(want, got) {
  908. t.Errorf("wrong response %q, want %q)", got, want)
  909. }
  910. }
  911. func TestGrafeasV1Beta1UpdateOccurrenceError(t *testing.T) {
  912. errCode := codes.PermissionDenied
  913. mockGrafeasV1Beta1.err = gstatus.Error(errCode, "test error")
  914. var formattedName string = fmt.Sprintf("projects/%s/occurrences/%s", "[PROJECT]", "[OCCURRENCE]")
  915. var occurrence *grafeaspb.Occurrence = &grafeaspb.Occurrence{}
  916. var request = &grafeaspb.UpdateOccurrenceRequest{
  917. Name: formattedName,
  918. Occurrence: occurrence,
  919. }
  920. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  921. if err != nil {
  922. t.Fatal(err)
  923. }
  924. resp, err := c.UpdateOccurrence(context.Background(), request)
  925. if st, ok := gstatus.FromError(err); !ok {
  926. t.Errorf("got error %v, expected grpc error", err)
  927. } else if c := st.Code(); c != errCode {
  928. t.Errorf("got error code %q, want %q", c, errCode)
  929. }
  930. _ = resp
  931. }
  932. func TestGrafeasV1Beta1GetOccurrenceNote(t *testing.T) {
  933. var name2 string = "name2-1052831874"
  934. var shortDescription string = "shortDescription-235369287"
  935. var longDescription string = "longDescription-1747792199"
  936. var expectedResponse = &grafeaspb.Note{
  937. Name: name2,
  938. ShortDescription: shortDescription,
  939. LongDescription: longDescription,
  940. }
  941. mockGrafeasV1Beta1.err = nil
  942. mockGrafeasV1Beta1.reqs = nil
  943. mockGrafeasV1Beta1.resps = append(mockGrafeasV1Beta1.resps[:0], expectedResponse)
  944. var formattedName string = fmt.Sprintf("projects/%s/occurrences/%s", "[PROJECT]", "[OCCURRENCE]")
  945. var request = &grafeaspb.GetOccurrenceNoteRequest{
  946. Name: formattedName,
  947. }
  948. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  949. if err != nil {
  950. t.Fatal(err)
  951. }
  952. resp, err := c.GetOccurrenceNote(context.Background(), request)
  953. if err != nil {
  954. t.Fatal(err)
  955. }
  956. if want, got := request, mockGrafeasV1Beta1.reqs[0]; !proto.Equal(want, got) {
  957. t.Errorf("wrong request %q, want %q", got, want)
  958. }
  959. if want, got := expectedResponse, resp; !proto.Equal(want, got) {
  960. t.Errorf("wrong response %q, want %q)", got, want)
  961. }
  962. }
  963. func TestGrafeasV1Beta1GetOccurrenceNoteError(t *testing.T) {
  964. errCode := codes.PermissionDenied
  965. mockGrafeasV1Beta1.err = gstatus.Error(errCode, "test error")
  966. var formattedName string = fmt.Sprintf("projects/%s/occurrences/%s", "[PROJECT]", "[OCCURRENCE]")
  967. var request = &grafeaspb.GetOccurrenceNoteRequest{
  968. Name: formattedName,
  969. }
  970. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  971. if err != nil {
  972. t.Fatal(err)
  973. }
  974. resp, err := c.GetOccurrenceNote(context.Background(), request)
  975. if st, ok := gstatus.FromError(err); !ok {
  976. t.Errorf("got error %v, expected grpc error", err)
  977. } else if c := st.Code(); c != errCode {
  978. t.Errorf("got error code %q, want %q", c, errCode)
  979. }
  980. _ = resp
  981. }
  982. func TestGrafeasV1Beta1GetNote(t *testing.T) {
  983. var name2 string = "name2-1052831874"
  984. var shortDescription string = "shortDescription-235369287"
  985. var longDescription string = "longDescription-1747792199"
  986. var expectedResponse = &grafeaspb.Note{
  987. Name: name2,
  988. ShortDescription: shortDescription,
  989. LongDescription: longDescription,
  990. }
  991. mockGrafeasV1Beta1.err = nil
  992. mockGrafeasV1Beta1.reqs = nil
  993. mockGrafeasV1Beta1.resps = append(mockGrafeasV1Beta1.resps[:0], expectedResponse)
  994. var formattedName string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
  995. var request = &grafeaspb.GetNoteRequest{
  996. Name: formattedName,
  997. }
  998. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  999. if err != nil {
  1000. t.Fatal(err)
  1001. }
  1002. resp, err := c.GetNote(context.Background(), request)
  1003. if err != nil {
  1004. t.Fatal(err)
  1005. }
  1006. if want, got := request, mockGrafeasV1Beta1.reqs[0]; !proto.Equal(want, got) {
  1007. t.Errorf("wrong request %q, want %q", got, want)
  1008. }
  1009. if want, got := expectedResponse, resp; !proto.Equal(want, got) {
  1010. t.Errorf("wrong response %q, want %q)", got, want)
  1011. }
  1012. }
  1013. func TestGrafeasV1Beta1GetNoteError(t *testing.T) {
  1014. errCode := codes.PermissionDenied
  1015. mockGrafeasV1Beta1.err = gstatus.Error(errCode, "test error")
  1016. var formattedName string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
  1017. var request = &grafeaspb.GetNoteRequest{
  1018. Name: formattedName,
  1019. }
  1020. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  1021. if err != nil {
  1022. t.Fatal(err)
  1023. }
  1024. resp, err := c.GetNote(context.Background(), request)
  1025. if st, ok := gstatus.FromError(err); !ok {
  1026. t.Errorf("got error %v, expected grpc error", err)
  1027. } else if c := st.Code(); c != errCode {
  1028. t.Errorf("got error code %q, want %q", c, errCode)
  1029. }
  1030. _ = resp
  1031. }
  1032. func TestGrafeasV1Beta1ListNotes(t *testing.T) {
  1033. var nextPageToken string = ""
  1034. var notesElement *grafeaspb.Note = &grafeaspb.Note{}
  1035. var notes = []*grafeaspb.Note{notesElement}
  1036. var expectedResponse = &grafeaspb.ListNotesResponse{
  1037. NextPageToken: nextPageToken,
  1038. Notes: notes,
  1039. }
  1040. mockGrafeasV1Beta1.err = nil
  1041. mockGrafeasV1Beta1.reqs = nil
  1042. mockGrafeasV1Beta1.resps = append(mockGrafeasV1Beta1.resps[:0], expectedResponse)
  1043. var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
  1044. var request = &grafeaspb.ListNotesRequest{
  1045. Parent: formattedParent,
  1046. }
  1047. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  1048. if err != nil {
  1049. t.Fatal(err)
  1050. }
  1051. resp, err := c.ListNotes(context.Background(), request).Next()
  1052. if err != nil {
  1053. t.Fatal(err)
  1054. }
  1055. if want, got := request, mockGrafeasV1Beta1.reqs[0]; !proto.Equal(want, got) {
  1056. t.Errorf("wrong request %q, want %q", got, want)
  1057. }
  1058. want := (interface{})(expectedResponse.Notes[0])
  1059. got := (interface{})(resp)
  1060. var ok bool
  1061. switch want := (want).(type) {
  1062. case proto.Message:
  1063. ok = proto.Equal(want, got.(proto.Message))
  1064. default:
  1065. ok = want == got
  1066. }
  1067. if !ok {
  1068. t.Errorf("wrong response %q, want %q)", got, want)
  1069. }
  1070. }
  1071. func TestGrafeasV1Beta1ListNotesError(t *testing.T) {
  1072. errCode := codes.PermissionDenied
  1073. mockGrafeasV1Beta1.err = gstatus.Error(errCode, "test error")
  1074. var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
  1075. var request = &grafeaspb.ListNotesRequest{
  1076. Parent: formattedParent,
  1077. }
  1078. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  1079. if err != nil {
  1080. t.Fatal(err)
  1081. }
  1082. resp, err := c.ListNotes(context.Background(), request).Next()
  1083. if st, ok := gstatus.FromError(err); !ok {
  1084. t.Errorf("got error %v, expected grpc error", err)
  1085. } else if c := st.Code(); c != errCode {
  1086. t.Errorf("got error code %q, want %q", c, errCode)
  1087. }
  1088. _ = resp
  1089. }
  1090. func TestGrafeasV1Beta1DeleteNote(t *testing.T) {
  1091. var expectedResponse *emptypb.Empty = &emptypb.Empty{}
  1092. mockGrafeasV1Beta1.err = nil
  1093. mockGrafeasV1Beta1.reqs = nil
  1094. mockGrafeasV1Beta1.resps = append(mockGrafeasV1Beta1.resps[:0], expectedResponse)
  1095. var formattedName string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
  1096. var request = &grafeaspb.DeleteNoteRequest{
  1097. Name: formattedName,
  1098. }
  1099. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  1100. if err != nil {
  1101. t.Fatal(err)
  1102. }
  1103. err = c.DeleteNote(context.Background(), request)
  1104. if err != nil {
  1105. t.Fatal(err)
  1106. }
  1107. if want, got := request, mockGrafeasV1Beta1.reqs[0]; !proto.Equal(want, got) {
  1108. t.Errorf("wrong request %q, want %q", got, want)
  1109. }
  1110. }
  1111. func TestGrafeasV1Beta1DeleteNoteError(t *testing.T) {
  1112. errCode := codes.PermissionDenied
  1113. mockGrafeasV1Beta1.err = gstatus.Error(errCode, "test error")
  1114. var formattedName string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
  1115. var request = &grafeaspb.DeleteNoteRequest{
  1116. Name: formattedName,
  1117. }
  1118. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  1119. if err != nil {
  1120. t.Fatal(err)
  1121. }
  1122. err = c.DeleteNote(context.Background(), request)
  1123. if st, ok := gstatus.FromError(err); !ok {
  1124. t.Errorf("got error %v, expected grpc error", err)
  1125. } else if c := st.Code(); c != errCode {
  1126. t.Errorf("got error code %q, want %q", c, errCode)
  1127. }
  1128. }
  1129. func TestGrafeasV1Beta1CreateNote(t *testing.T) {
  1130. var name string = "name3373707"
  1131. var shortDescription string = "shortDescription-235369287"
  1132. var longDescription string = "longDescription-1747792199"
  1133. var expectedResponse = &grafeaspb.Note{
  1134. Name: name,
  1135. ShortDescription: shortDescription,
  1136. LongDescription: longDescription,
  1137. }
  1138. mockGrafeasV1Beta1.err = nil
  1139. mockGrafeasV1Beta1.reqs = nil
  1140. mockGrafeasV1Beta1.resps = append(mockGrafeasV1Beta1.resps[:0], expectedResponse)
  1141. var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
  1142. var noteId string = "noteId2129224840"
  1143. var note *grafeaspb.Note = &grafeaspb.Note{}
  1144. var request = &grafeaspb.CreateNoteRequest{
  1145. Parent: formattedParent,
  1146. NoteId: noteId,
  1147. Note: note,
  1148. }
  1149. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  1150. if err != nil {
  1151. t.Fatal(err)
  1152. }
  1153. resp, err := c.CreateNote(context.Background(), request)
  1154. if err != nil {
  1155. t.Fatal(err)
  1156. }
  1157. if want, got := request, mockGrafeasV1Beta1.reqs[0]; !proto.Equal(want, got) {
  1158. t.Errorf("wrong request %q, want %q", got, want)
  1159. }
  1160. if want, got := expectedResponse, resp; !proto.Equal(want, got) {
  1161. t.Errorf("wrong response %q, want %q)", got, want)
  1162. }
  1163. }
  1164. func TestGrafeasV1Beta1CreateNoteError(t *testing.T) {
  1165. errCode := codes.PermissionDenied
  1166. mockGrafeasV1Beta1.err = gstatus.Error(errCode, "test error")
  1167. var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
  1168. var noteId string = "noteId2129224840"
  1169. var note *grafeaspb.Note = &grafeaspb.Note{}
  1170. var request = &grafeaspb.CreateNoteRequest{
  1171. Parent: formattedParent,
  1172. NoteId: noteId,
  1173. Note: note,
  1174. }
  1175. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  1176. if err != nil {
  1177. t.Fatal(err)
  1178. }
  1179. resp, err := c.CreateNote(context.Background(), request)
  1180. if st, ok := gstatus.FromError(err); !ok {
  1181. t.Errorf("got error %v, expected grpc error", err)
  1182. } else if c := st.Code(); c != errCode {
  1183. t.Errorf("got error code %q, want %q", c, errCode)
  1184. }
  1185. _ = resp
  1186. }
  1187. func TestGrafeasV1Beta1BatchCreateNotes(t *testing.T) {
  1188. var expectedResponse *grafeaspb.BatchCreateNotesResponse = &grafeaspb.BatchCreateNotesResponse{}
  1189. mockGrafeasV1Beta1.err = nil
  1190. mockGrafeasV1Beta1.reqs = nil
  1191. mockGrafeasV1Beta1.resps = append(mockGrafeasV1Beta1.resps[:0], expectedResponse)
  1192. var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
  1193. var notes map[string]*grafeaspb.Note = nil
  1194. var request = &grafeaspb.BatchCreateNotesRequest{
  1195. Parent: formattedParent,
  1196. Notes: notes,
  1197. }
  1198. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  1199. if err != nil {
  1200. t.Fatal(err)
  1201. }
  1202. resp, err := c.BatchCreateNotes(context.Background(), request)
  1203. if err != nil {
  1204. t.Fatal(err)
  1205. }
  1206. if want, got := request, mockGrafeasV1Beta1.reqs[0]; !proto.Equal(want, got) {
  1207. t.Errorf("wrong request %q, want %q", got, want)
  1208. }
  1209. if want, got := expectedResponse, resp; !proto.Equal(want, got) {
  1210. t.Errorf("wrong response %q, want %q)", got, want)
  1211. }
  1212. }
  1213. func TestGrafeasV1Beta1BatchCreateNotesError(t *testing.T) {
  1214. errCode := codes.PermissionDenied
  1215. mockGrafeasV1Beta1.err = gstatus.Error(errCode, "test error")
  1216. var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
  1217. var notes map[string]*grafeaspb.Note = nil
  1218. var request = &grafeaspb.BatchCreateNotesRequest{
  1219. Parent: formattedParent,
  1220. Notes: notes,
  1221. }
  1222. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  1223. if err != nil {
  1224. t.Fatal(err)
  1225. }
  1226. resp, err := c.BatchCreateNotes(context.Background(), request)
  1227. if st, ok := gstatus.FromError(err); !ok {
  1228. t.Errorf("got error %v, expected grpc error", err)
  1229. } else if c := st.Code(); c != errCode {
  1230. t.Errorf("got error code %q, want %q", c, errCode)
  1231. }
  1232. _ = resp
  1233. }
  1234. func TestGrafeasV1Beta1UpdateNote(t *testing.T) {
  1235. var name2 string = "name2-1052831874"
  1236. var shortDescription string = "shortDescription-235369287"
  1237. var longDescription string = "longDescription-1747792199"
  1238. var expectedResponse = &grafeaspb.Note{
  1239. Name: name2,
  1240. ShortDescription: shortDescription,
  1241. LongDescription: longDescription,
  1242. }
  1243. mockGrafeasV1Beta1.err = nil
  1244. mockGrafeasV1Beta1.reqs = nil
  1245. mockGrafeasV1Beta1.resps = append(mockGrafeasV1Beta1.resps[:0], expectedResponse)
  1246. var formattedName string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
  1247. var note *grafeaspb.Note = &grafeaspb.Note{}
  1248. var request = &grafeaspb.UpdateNoteRequest{
  1249. Name: formattedName,
  1250. Note: note,
  1251. }
  1252. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  1253. if err != nil {
  1254. t.Fatal(err)
  1255. }
  1256. resp, err := c.UpdateNote(context.Background(), request)
  1257. if err != nil {
  1258. t.Fatal(err)
  1259. }
  1260. if want, got := request, mockGrafeasV1Beta1.reqs[0]; !proto.Equal(want, got) {
  1261. t.Errorf("wrong request %q, want %q", got, want)
  1262. }
  1263. if want, got := expectedResponse, resp; !proto.Equal(want, got) {
  1264. t.Errorf("wrong response %q, want %q)", got, want)
  1265. }
  1266. }
  1267. func TestGrafeasV1Beta1UpdateNoteError(t *testing.T) {
  1268. errCode := codes.PermissionDenied
  1269. mockGrafeasV1Beta1.err = gstatus.Error(errCode, "test error")
  1270. var formattedName string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
  1271. var note *grafeaspb.Note = &grafeaspb.Note{}
  1272. var request = &grafeaspb.UpdateNoteRequest{
  1273. Name: formattedName,
  1274. Note: note,
  1275. }
  1276. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  1277. if err != nil {
  1278. t.Fatal(err)
  1279. }
  1280. resp, err := c.UpdateNote(context.Background(), request)
  1281. if st, ok := gstatus.FromError(err); !ok {
  1282. t.Errorf("got error %v, expected grpc error", err)
  1283. } else if c := st.Code(); c != errCode {
  1284. t.Errorf("got error code %q, want %q", c, errCode)
  1285. }
  1286. _ = resp
  1287. }
  1288. func TestGrafeasV1Beta1ListNoteOccurrences(t *testing.T) {
  1289. var nextPageToken string = ""
  1290. var occurrencesElement *grafeaspb.Occurrence = &grafeaspb.Occurrence{}
  1291. var occurrences = []*grafeaspb.Occurrence{occurrencesElement}
  1292. var expectedResponse = &grafeaspb.ListNoteOccurrencesResponse{
  1293. NextPageToken: nextPageToken,
  1294. Occurrences: occurrences,
  1295. }
  1296. mockGrafeasV1Beta1.err = nil
  1297. mockGrafeasV1Beta1.reqs = nil
  1298. mockGrafeasV1Beta1.resps = append(mockGrafeasV1Beta1.resps[:0], expectedResponse)
  1299. var formattedName string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
  1300. var request = &grafeaspb.ListNoteOccurrencesRequest{
  1301. Name: formattedName,
  1302. }
  1303. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  1304. if err != nil {
  1305. t.Fatal(err)
  1306. }
  1307. resp, err := c.ListNoteOccurrences(context.Background(), request).Next()
  1308. if err != nil {
  1309. t.Fatal(err)
  1310. }
  1311. if want, got := request, mockGrafeasV1Beta1.reqs[0]; !proto.Equal(want, got) {
  1312. t.Errorf("wrong request %q, want %q", got, want)
  1313. }
  1314. want := (interface{})(expectedResponse.Occurrences[0])
  1315. got := (interface{})(resp)
  1316. var ok bool
  1317. switch want := (want).(type) {
  1318. case proto.Message:
  1319. ok = proto.Equal(want, got.(proto.Message))
  1320. default:
  1321. ok = want == got
  1322. }
  1323. if !ok {
  1324. t.Errorf("wrong response %q, want %q)", got, want)
  1325. }
  1326. }
  1327. func TestGrafeasV1Beta1ListNoteOccurrencesError(t *testing.T) {
  1328. errCode := codes.PermissionDenied
  1329. mockGrafeasV1Beta1.err = gstatus.Error(errCode, "test error")
  1330. var formattedName string = fmt.Sprintf("projects/%s/notes/%s", "[PROJECT]", "[NOTE]")
  1331. var request = &grafeaspb.ListNoteOccurrencesRequest{
  1332. Name: formattedName,
  1333. }
  1334. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  1335. if err != nil {
  1336. t.Fatal(err)
  1337. }
  1338. resp, err := c.ListNoteOccurrences(context.Background(), request).Next()
  1339. if st, ok := gstatus.FromError(err); !ok {
  1340. t.Errorf("got error %v, expected grpc error", err)
  1341. } else if c := st.Code(); c != errCode {
  1342. t.Errorf("got error code %q, want %q", c, errCode)
  1343. }
  1344. _ = resp
  1345. }
  1346. func TestGrafeasV1Beta1GetVulnerabilityOccurrencesSummary(t *testing.T) {
  1347. var expectedResponse *grafeaspb.VulnerabilityOccurrencesSummary = &grafeaspb.VulnerabilityOccurrencesSummary{}
  1348. mockGrafeasV1Beta1.err = nil
  1349. mockGrafeasV1Beta1.reqs = nil
  1350. mockGrafeasV1Beta1.resps = append(mockGrafeasV1Beta1.resps[:0], expectedResponse)
  1351. var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
  1352. var request = &grafeaspb.GetVulnerabilityOccurrencesSummaryRequest{
  1353. Parent: formattedParent,
  1354. }
  1355. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  1356. if err != nil {
  1357. t.Fatal(err)
  1358. }
  1359. resp, err := c.GetVulnerabilityOccurrencesSummary(context.Background(), request)
  1360. if err != nil {
  1361. t.Fatal(err)
  1362. }
  1363. if want, got := request, mockGrafeasV1Beta1.reqs[0]; !proto.Equal(want, got) {
  1364. t.Errorf("wrong request %q, want %q", got, want)
  1365. }
  1366. if want, got := expectedResponse, resp; !proto.Equal(want, got) {
  1367. t.Errorf("wrong response %q, want %q)", got, want)
  1368. }
  1369. }
  1370. func TestGrafeasV1Beta1GetVulnerabilityOccurrencesSummaryError(t *testing.T) {
  1371. errCode := codes.PermissionDenied
  1372. mockGrafeasV1Beta1.err = gstatus.Error(errCode, "test error")
  1373. var formattedParent string = fmt.Sprintf("projects/%s", "[PROJECT]")
  1374. var request = &grafeaspb.GetVulnerabilityOccurrencesSummaryRequest{
  1375. Parent: formattedParent,
  1376. }
  1377. c, err := NewGrafeasV1Beta1Client(context.Background(), clientOpt)
  1378. if err != nil {
  1379. t.Fatal(err)
  1380. }
  1381. resp, err := c.GetVulnerabilityOccurrencesSummary(context.Background(), request)
  1382. if st, ok := gstatus.FromError(err); !ok {
  1383. t.Errorf("got error %v, expected grpc error", err)
  1384. } else if c := st.Code(); c != errCode {
  1385. t.Errorf("got error code %q, want %q", c, errCode)
  1386. }
  1387. _ = resp
  1388. }