From d72deff4091596871037a0d5f618d573bfc62283 Mon Sep 17 00:00:00 2001 From: Naveen <172697+naveensrinivasan@users.noreply.github.com> Date: Thu, 15 Jun 2023 07:54:23 -0500 Subject: [PATCH] :seedling: Improve Githubrepo Releases handler E2E tests (#3164) - Add e2e test for githubrepo releases handler Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com> --- clients/githubrepo/releases_e2e_test.go | 60 +++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 clients/githubrepo/releases_e2e_test.go diff --git a/clients/githubrepo/releases_e2e_test.go b/clients/githubrepo/releases_e2e_test.go new file mode 100644 index 00000000000..0a611c6945d --- /dev/null +++ b/clients/githubrepo/releases_e2e_test.go @@ -0,0 +1,60 @@ +// Copyright 2023 OpenSSF 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 githubrepo + +import ( + "context" + "net/http" + + "github.com/google/go-github/v38/github" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "github.com/ossf/scorecard/v4/clients" + "github.com/ossf/scorecard/v4/clients/githubrepo/roundtripper" + "github.com/ossf/scorecard/v4/log" +) + +var _ = Describe("E2E TEST: githubrepo.releasesHandler", func() { + var releaseHandler *releasesHandler + + BeforeEach(func() { + ctx := context.Background() + rt := roundtripper.NewTransport(context.Background(), &log.Logger{}) + httpClient := &http.Client{ + Transport: rt, + } + client := github.NewClient(httpClient) + releaseHandler = &releasesHandler{ + client: client, + ctx: ctx, + } + }) + Context("getReleases()", func() { + It("returns releases", func() { + repoURL := repoURL{ + owner: "ossf", + repo: "scorecard", + commitSHA: clients.HeadSHA, + } + + releaseHandler.init(context.Background(), &repoURL) + resp, err := releaseHandler.getReleases() + Expect(err).NotTo(HaveOccurred()) + Expect(len(resp)).ShouldNot(Equal(0)) + Expect(releaseHandler.errSetup).Should(BeNil()) + }) + }) +})