-
Notifications
You must be signed in to change notification settings - Fork 509
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Azeem Shaikh <[email protected]>
- Loading branch information
1 parent
de5224b
commit cda7a1b
Showing
7 changed files
with
188 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2021 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 githubrepo | ||
|
||
import ( | ||
"context" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/ossf/scorecard/v4/clients" | ||
) | ||
|
||
var _ = Describe("E2E TEST: githubrepo.branchesHandler", func() { | ||
var brancheshandler *branchesHandler | ||
|
||
BeforeEach(func() { | ||
brancheshandler = &branchesHandler{ | ||
graphClient: graphClient, | ||
} | ||
}) | ||
|
||
Context("E2E TEST: Validate query cost", func() { | ||
It("Should not have increased for HEAD query", func() { | ||
repourl := &repoURL{ | ||
owner: "ossf", | ||
repo: "scorecard", | ||
commitSHA: clients.HeadSHA, | ||
} | ||
brancheshandler.init(context.Background(), repourl) | ||
Expect(brancheshandler.setup()).Should(BeNil()) | ||
Expect(brancheshandler.data).ShouldNot(BeNil()) | ||
Expect(brancheshandler.data.RateLimit.Cost).ShouldNot(BeNil()) | ||
Expect(*brancheshandler.data.RateLimit.Cost).Should(BeNumerically("<=", 1)) | ||
}) | ||
It("Should fail for non-HEAD query", func() { | ||
repourl := &repoURL{ | ||
owner: "ossf", | ||
repo: "scorecard", | ||
commitSHA: "de5224bbc56eceb7a25aece55d2d53bbc561ed2d", | ||
} | ||
brancheshandler.init(context.Background(), repourl) | ||
Expect(brancheshandler.setup()).ShouldNot(BeNil()) | ||
Expect(brancheshandler.data).Should(BeNil()) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2021 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 githubrepo | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"os" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/shurcooL/githubv4" | ||
|
||
"github.com/ossf/scorecard/v4/clients/githubrepo/roundtripper" | ||
"github.com/ossf/scorecard/v4/log" | ||
) | ||
|
||
func TestGithubrepo(t *testing.T) { | ||
if val, exists := os.LookupEnv("SKIP_GINKGO"); exists && val == "1" { | ||
t.Skip() | ||
} | ||
t.Parallel() | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Githubrepo Suite") | ||
} | ||
|
||
var graphClient *githubv4.Client | ||
|
||
var _ = BeforeSuite(func() { | ||
ctx := context.Background() | ||
logger := log.NewLogger(log.DebugLevel) | ||
rt := roundtripper.NewTransport(ctx, logger) | ||
httpClient := &http.Client{ | ||
Transport: rt, | ||
} | ||
graphClient = githubv4.NewClient(httpClient) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2021 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 githubrepo | ||
|
||
import ( | ||
"context" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/ossf/scorecard/v4/clients" | ||
) | ||
|
||
var _ = Describe("E2E TEST: githubrepo.graphqlHandler", func() { | ||
var graphqlhandler *graphqlHandler | ||
|
||
BeforeEach(func() { | ||
graphqlhandler = &graphqlHandler{ | ||
client: graphClient, | ||
} | ||
}) | ||
|
||
Context("E2E TEST: Validate query cost", func() { | ||
It("Should not have increased for HEAD query", func() { | ||
repourl := &repoURL{ | ||
owner: "ossf", | ||
repo: "scorecard", | ||
commitSHA: clients.HeadSHA, | ||
} | ||
graphqlhandler.init(context.Background(), repourl) | ||
Expect(graphqlhandler.setup()).Should(BeNil()) | ||
Expect(graphqlhandler.data).ShouldNot(BeNil()) | ||
Expect(graphqlhandler.data.RateLimit.Cost).ShouldNot(BeNil()) | ||
Expect(*graphqlhandler.data.RateLimit.Cost).Should(BeNumerically("<=", 1)) | ||
}) | ||
It("Should not have increased for commit query", func() { | ||
repourl := &repoURL{ | ||
owner: "ossf", | ||
repo: "scorecard", | ||
commitSHA: "de5224bbc56eceb7a25aece55d2d53bbc561ed2d", | ||
} | ||
graphqlhandler.init(context.Background(), repourl) | ||
Expect(graphqlhandler.setup()).Should(BeNil()) | ||
Expect(graphqlhandler.data).ShouldNot(BeNil()) | ||
Expect(graphqlhandler.data.RateLimit.Cost).ShouldNot(BeNil()) | ||
Expect(*graphqlhandler.data.RateLimit.Cost).Should(BeNumerically("<=", 1)) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters