Add e2e tests using dedicated repo for pinned-dependencies check (#766)

* fix

* e2e

* add e2e test from dedicated repo

* e2e update

* linter

* merge
This commit is contained in:
laurentsimon 2021-07-29 11:55:25 -07:00 committed by GitHub
parent 578c71b03e
commit 8432a82bc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 45 deletions

View File

@ -25,7 +25,7 @@ if an error is returned from an API you call, use the function.
* If you need more flexibility and need to set a specific score, use `checker.CreateResultWithScore()` with one of the constants declared, such as `checker.HalfResultScore`.
6. Dealing with errors: see [../errors/errors.md](errors/errors/md).
7. Create unit tests for both low, high and inconclusive score. Put them in a file `checks/mycheck_test.go`.
8. Create e2e tests in `e2e/mycheck_test.go`. Use a dedicated repo that will not change over time, so that it's reliable for the tests.
8. Create e2e tests in `e2e/mycheck_test.go`. Use a dedicated repo under [ossf-tests org](https://github.com/ossf-tests/) that will not change over time, so that it's reliable for the tests. Name your repo `scorecard-*`.
9. Update the `checks/checks.yaml` with the description of your check.
10. Gerenate the `checks/check.md` using `go build && cd checks/main && ./main`. Verify `checks/check.md` was updated.
10. Update the [README.md](https://github.com/ossf/scorecard#scorecard-checks) with a short description of your check.

View File

@ -11,7 +11,7 @@
// 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.
//nolint:dupl
package e2e
import (
@ -29,11 +29,11 @@ import (
// TODO: use dedicated repo that don't change.
// TODO: need negative results.
var _ = Describe("E2E TEST:"+checks.CheckPinnedDependencies, func() {
Context("E2E TEST:Validating dependencies are pinned", func() {
It("Should return dependencies are not pinned", func() {
Context("E2E TEST:Validating dependencies check is working", func() {
It("Should return dependencies check is working", func() {
dl := scut.TestDetailLogger{}
repoClient := githubrepo.CreateGithubRepoClient(context.Background(), ghClient, graphClient)
err := repoClient.InitRepo("tensorflow", "tensorflow")
err := repoClient.InitRepo("ossf-tests", "scorecard-check-pinned-dependencies-e2e")
Expect(err).Should(BeNil())
req := checker.CheckRequest{
@ -41,17 +41,17 @@ var _ = Describe("E2E TEST:"+checks.CheckPinnedDependencies, func() {
Client: ghClient,
HTTPClient: httpClient,
RepoClient: repoClient,
Owner: "tensorflow",
Repo: "tensorflow",
Owner: "ossf-tests",
Repo: "scorecard-check-pinned-dependencies-e2e",
GraphClient: graphClient,
Dlogger: &dl,
}
expected := scut.TestReturn{
Errors: nil,
Score: checker.MinResultScore,
NumberOfWarn: 374,
NumberOfInfo: 0,
NumberOfDebug: 4,
Score: 3,
NumberOfWarn: 149,
NumberOfInfo: 2,
NumberOfDebug: 0,
}
result := checks.FrozenDeps(&req)
// UPGRADEv2: to remove.
@ -59,38 +59,7 @@ var _ = Describe("E2E TEST:"+checks.CheckPinnedDependencies, func() {
Expect(result.Error).Should(BeNil())
Expect(result.Pass).Should(BeFalse())
// New version.
Expect(scut.ValidateTestReturn(nil, "dependencies not pinned", &expected, &result, &dl)).Should(BeTrue())
})
It("Should return dependencies are pinned", func() {
dl := scut.TestDetailLogger{}
repoClient := githubrepo.CreateGithubRepoClient(context.Background(), ghClient, graphClient)
err := repoClient.InitRepo("ossf", "scorecard")
Expect(err).Should(BeNil())
req := checker.CheckRequest{
Ctx: context.Background(),
Client: ghClient,
HTTPClient: httpClient,
RepoClient: repoClient,
Owner: "ossf",
Repo: "scorecard",
GraphClient: graphClient,
Dlogger: &dl,
}
expected := scut.TestReturn{
Errors: nil,
Score: checker.MaxResultScore,
NumberOfWarn: 0,
NumberOfInfo: 6,
NumberOfDebug: 0,
}
result := checks.FrozenDeps(&req)
// UPGRADEv2: to remove.
// Old version.
Expect(result.Error).Should(BeNil())
Expect(result.Pass).Should(BeTrue())
// New version.
Expect(scut.ValidateTestReturn(nil, "dependencies pinned", &expected, &result, &dl)).Should(BeTrue())
Expect(scut.ValidateTestReturn(nil, "dependencies check", &expected, &result, &dl)).Should(BeTrue())
})
})
})

View File

@ -38,7 +38,6 @@ func validateDetailTypes(messages []checker.CheckDetail, nw, ni, nd int) bool {
enw++
}
}
return enw == nw &&
eni == ni &&
end == nd
@ -85,7 +84,6 @@ func ValidateTestValues(t *testing.T, name string, te *TestReturn,
return false
}
}
// UPGRADEv2: update name.
if score != te.Score ||
!validateDetailTypes(dl.messages, te.NumberOfWarn,