From 049db386a5e2c8e88073669151530998e7970174 Mon Sep 17 00:00:00 2001 From: naveen <172697+naveensrinivasan@users.noreply.github.com> Date: Fri, 4 Feb 2022 01:51:04 +0000 Subject: [PATCH] :seedling: Unit tests for dependency_update_tool Unit tests for dependency_update_tool https://github.com/ossf/scorecard/issues/986 Signed-off-by: naveen <172697+naveensrinivasan@users.noreply.github.com> --- checks/dependency_update_tool_test.go | 90 +++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 checks/dependency_update_tool_test.go diff --git a/checks/dependency_update_tool_test.go b/checks/dependency_update_tool_test.go new file mode 100644 index 00000000..7dbdefdf --- /dev/null +++ b/checks/dependency_update_tool_test.go @@ -0,0 +1,90 @@ +// Copyright 2020 Security Scorecard Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package checks + +import ( + "testing" + + "github.com/golang/mock/gomock" + + "github.com/ossf/scorecard/v4/checker" + mockrepo "github.com/ossf/scorecard/v4/clients/mockclients" + scut "github.com/ossf/scorecard/v4/utests" +) + +// TestDependencyUpdateTool tests the DependencyUpdateTool checker. +func TestDependencyUpdateTool(t *testing.T) { + t.Parallel() + //nolint + tests := []struct { + name string + wantErr bool + files []string + want checker.CheckResult + expected scut.TestReturn + }{ + { + name: "dependency yml", + wantErr: false, + files: []string{ + ".github/dependabot.yml", + }, + expected: scut.TestReturn{ + NumberOfInfo: 1, + Score: 10, + }, + }, + { + name: "dependency yaml ", + wantErr: false, + files: []string{ + ".github/dependabot.yaml", + }, + expected: scut.TestReturn{ + NumberOfInfo: 1, + Score: 10, + }, + }, + { + name: "foo bar", + wantErr: false, + files: []string{ + ".github/foobar.yml", + }, + expected: scut.TestReturn{ + NumberOfWarn: 2, + }, + }, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + ctrl := gomock.NewController(t) + mockRepo := mockrepo.NewMockRepoClient(ctrl) + mockRepo.EXPECT().ListFiles(gomock.Any()).Return(tt.files, nil) + dl := scut.TestDetailLogger{} + c := &checker.CheckRequest{ + RepoClient: mockRepo, + Dlogger: &dl, + } + res := DependencyUpdateTool(c) + + if !scut.ValidateTestReturn(t, tt.name, &tt.expected, &res, &dl) { + t.Fail() + } + }) + } +}