MCPcopy
hub / github.com/ossf/scorecard / TestVulnerabilities

Function TestVulnerabilities

checks/vulnerabilities_test.go:28–81  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26)
27
28func TestVulnerabilities(t *testing.T) {
29 t.Parallel()
30 tests := []struct {
31 err error
32 name string
33 expected clients.VulnerabilitiesResponse
34 isError bool
35 }{
36 {
37 name: "Valid response",
38 isError: false,
39 expected: clients.VulnerabilitiesResponse{},
40 },
41 }
42
43 for _, tt := range tests {
44 t.Run(tt.name, func(t *testing.T) {
45 t.Parallel()
46
47 ctrl := gomock.NewController(t)
48 mockRepo := mockrepo.NewMockRepoClient(ctrl)
49
50 mockRepo.EXPECT().ListCommits().DoAndReturn(func() ([]clients.Commit, error) {
51 if tt.err != nil {
52 return nil, tt.err
53 }
54 return []clients.Commit{{SHA: "test"}}, nil
55 }).MinTimes(1)
56
57 mockRepo.EXPECT().LocalPath().DoAndReturn(func() (string, error) {
58 return "test_path", nil
59 }).AnyTimes()
60
61 mockVulnClient := mockrepo.NewMockVulnerabilitiesClient(ctrl)
62 mockVulnClient.EXPECT().ListUnfixedVulnerabilities(t.Context(), gomock.Any(), gomock.Any()).DoAndReturn(
63 func(ctx context.Context, commit string, localPath string) (clients.VulnerabilitiesResponse, error) {
64 return tt.expected, tt.err
65 }).MinTimes(1)
66
67 req := checker.CheckRequest{
68 RepoClient: mockRepo,
69 Ctx: t.Context(),
70 VulnerabilitiesClient: mockVulnClient,
71 }
72 res := Vulnerabilities(&req)
73 if !tt.isError && res.Error != nil {
74 t.Fail()
75 } else if tt.isError && res.Error == nil {
76 t.Fail()
77 }
78 ctrl.Finish()
79 })
80 }
81}

Callers

nothing calls this directly

Calls 7

EXPECTMethod · 0.95
EXPECTMethod · 0.95
VulnerabilitiesFunction · 0.70
RunMethod · 0.65
ListCommitsMethod · 0.65
LocalPathMethod · 0.65

Tested by

no test coverage detected