|
| 1 | +// Copyright 2023 OpenSSF Scorecard Authors |
| 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 | +// http://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 | + |
| 15 | +package githubrepo |
| 16 | + |
| 17 | +import ( |
| 18 | + "context" |
| 19 | + "net/http" |
| 20 | + |
| 21 | + "github.com/google/go-github/v38/github" |
| 22 | + . "github.com/onsi/ginkgo/v2" |
| 23 | + . "github.com/onsi/gomega" |
| 24 | + |
| 25 | + "github.com/ossf/scorecard/v4/clients" |
| 26 | + "github.com/ossf/scorecard/v4/clients/githubrepo/roundtripper" |
| 27 | + "github.com/ossf/scorecard/v4/log" |
| 28 | +) |
| 29 | + |
| 30 | +var _ = Describe("E2E TEST: githubrepo.licensesHandler", func() { |
| 31 | + var lh *licensesHandler |
| 32 | + |
| 33 | + BeforeEach(func() { |
| 34 | + ctx := context.Background() |
| 35 | + rt := roundtripper.NewTransport(context.Background(), &log.Logger{}) |
| 36 | + httpClient := &http.Client{ |
| 37 | + Transport: rt, |
| 38 | + } |
| 39 | + client := github.NewClient(httpClient) |
| 40 | + lh = &licensesHandler{ |
| 41 | + ghclient: client, |
| 42 | + ctx: ctx, |
| 43 | + } |
| 44 | + }) |
| 45 | + Context("listLicenses()", func() { |
| 46 | + It("returns licenses", func() { |
| 47 | + repoURL := repoURL{ |
| 48 | + owner: "ossf", |
| 49 | + repo: "scorecard", |
| 50 | + commitSHA: clients.HeadSHA, |
| 51 | + } |
| 52 | + |
| 53 | + lh.init(context.Background(), &repoURL) |
| 54 | + licenses, err := lh.listLicenses() |
| 55 | + Expect(err).NotTo(HaveOccurred()) |
| 56 | + Expect(lh.errSetup).Should(BeNil()) |
| 57 | + Expect(len(licenses)).Should(Equal(1)) |
| 58 | + Expect(licenses[0].Name).Should(Equal("Apache License 2.0")) |
| 59 | + Expect(licenses[0].Path).Should(Equal("LICENSE")) |
| 60 | + }) |
| 61 | + }) |
| 62 | +}) |
0 commit comments