From 5c56572c672505fd4273305ceb0a286e3e1d0d40 Mon Sep 17 00:00:00 2001 From: Raghav Kaul Date: Wed, 17 May 2023 22:14:08 +0000 Subject: [PATCH 1/6] fix tests Signed-off-by: Raghav Kaul --- clients/gitlabrepo/checkruns.go | 2 +- clients/gitlabrepo/issues.go | 4 ++-- clients/gitlabrepo/project.go | 2 +- clients/gitlabrepo/statuses.go | 2 +- e2e/ci_tests_test.go | 4 ++-- e2e/code_review_test.go | 10 ++++++---- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/clients/gitlabrepo/checkruns.go b/clients/gitlabrepo/checkruns.go index 3fe06f4868a..7a153de0ad2 100644 --- a/clients/gitlabrepo/checkruns.go +++ b/clients/gitlabrepo/checkruns.go @@ -34,7 +34,7 @@ func (handler *checkrunsHandler) init(repourl *repoURL) { func (handler *checkrunsHandler) listCheckRunsForRef(ref string) ([]clients.CheckRun, error) { pipelines, _, err := handler.glClient.Pipelines.ListProjectPipelines( - handler.repourl.project, &gitlab.ListProjectPipelinesOptions{}) + handler.repourl.projectID, &gitlab.ListProjectPipelinesOptions{}) if err != nil { return nil, fmt.Errorf("request for pipelines returned error: %w", err) } diff --git a/clients/gitlabrepo/issues.go b/clients/gitlabrepo/issues.go index 36151ed4bff..83844f264e4 100644 --- a/clients/gitlabrepo/issues.go +++ b/clients/gitlabrepo/issues.go @@ -40,7 +40,7 @@ func (handler *issuesHandler) init(repourl *repoURL) { func (handler *issuesHandler) setup() error { handler.once.Do(func() { issues, _, err := handler.glClient.Issues.ListProjectIssues( - handler.repourl.project, &gitlab.ListProjectIssuesOptions{}) + handler.repourl.projectID, &gitlab.ListProjectIssuesOptions{}) if err != nil { handler.errSetup = fmt.Errorf("unable to find issues associated with the project id: %w", err) return @@ -49,7 +49,7 @@ func (handler *issuesHandler) setup() error { // There doesn't seem to be a good way to get user access_levels in gitlab so the following way may seem incredibly // barberic, however I couldn't find a better way in the docs. projMemberships, resp, err := handler.glClient.ProjectMembers.ListAllProjectMembers( - handler.repourl.project, &gitlab.ListProjectMembersOptions{}) + handler.repourl.projectID, &gitlab.ListProjectMembersOptions{}) if err != nil && resp.StatusCode != 401 { handler.errSetup = fmt.Errorf("unable to find access tokens associated with the project id: %w", err) return diff --git a/clients/gitlabrepo/project.go b/clients/gitlabrepo/project.go index a36256e7e7e..595f83a5224 100644 --- a/clients/gitlabrepo/project.go +++ b/clients/gitlabrepo/project.go @@ -39,7 +39,7 @@ func (handler *projectHandler) init(repourl *repoURL) { func (handler *projectHandler) setup() error { handler.once.Do(func() { - proj, _, err := handler.glClient.Projects.GetProject(handler.repourl.project, &gitlab.GetProjectOptions{}) + proj, _, err := handler.glClient.Projects.GetProject(handler.repourl.projectID, &gitlab.GetProjectOptions{}) if err != nil { handler.errSetup = fmt.Errorf("request for project failed with error %w", err) return diff --git a/clients/gitlabrepo/statuses.go b/clients/gitlabrepo/statuses.go index 1b1ede68755..f880cb2eae0 100644 --- a/clients/gitlabrepo/statuses.go +++ b/clients/gitlabrepo/statuses.go @@ -34,7 +34,7 @@ func (handler *statusesHandler) init(repourl *repoURL) { // for gitlab this only works if ref is SHA. func (handler *statusesHandler) listStatuses(ref string) ([]clients.Status, error) { commitStatuses, _, err := handler.glClient.Commits.GetCommitStatuses( - handler.repourl.project, ref, &gitlab.GetCommitStatusesOptions{}) + handler.repourl.projectID, ref, &gitlab.GetCommitStatusesOptions{}) if err != nil { return nil, fmt.Errorf("error getting commit statuses: %w", err) } diff --git a/e2e/ci_tests_test.go b/e2e/ci_tests_test.go index 58cb56ace61..58d37400c77 100644 --- a/e2e/ci_tests_test.go +++ b/e2e/ci_tests_test.go @@ -122,7 +122,7 @@ var _ = Describe("E2E TEST:"+checks.CheckCITests, func() { } expected := scut.TestReturn{ Error: nil, - Score: 0, + Score: 9, NumberOfWarn: 0, NumberOfInfo: 0, NumberOfDebug: 13, @@ -151,7 +151,7 @@ var _ = Describe("E2E TEST:"+checks.CheckCITests, func() { } expected := scut.TestReturn{ Error: nil, - Score: 3, + Score: 7, NumberOfWarn: 0, NumberOfInfo: 0, NumberOfDebug: 1, diff --git a/e2e/code_review_test.go b/e2e/code_review_test.go index 1278e1b94dc..ec367df7a2a 100644 --- a/e2e/code_review_test.go +++ b/e2e/code_review_test.go @@ -169,8 +169,9 @@ var _ = Describe("E2E TEST:"+checks.CheckCodeReview, func() { Dlogger: &dl, } expected := scut.TestReturn{ - Error: nil, - Score: 3, + Error: nil, + Score: 3, + NumberOfDebug: 1, } result := checks.CodeReview(&req) Expect(scut.ValidateTestReturn(nil, "use code reviews", &expected, &result, &dl)).Should(BeTrue()) @@ -197,8 +198,9 @@ var _ = Describe("E2E TEST:"+checks.CheckCodeReview, func() { Dlogger: &dl, } expected := scut.TestReturn{ - Error: nil, - Score: checker.MinResultScore, + Error: nil, + Score: checker.MinResultScore, + NumberOfDebug: 1, } result := checks.CodeReview(&req) Expect(scut.ValidateTestReturn(nil, "use code reviews", &expected, &result, &dl)).Should(BeTrue()) From 8bf35328be1d4f9d1d9ab58cf11891529a37764d Mon Sep 17 00:00:00 2001 From: Raghav Kaul Date: Thu, 18 May 2023 19:41:08 +0000 Subject: [PATCH 2/6] use projectID instead of project where applicable Signed-off-by: Raghav Kaul --- clients/gitlabrepo/branches.go | 18 +++++++++--------- clients/gitlabrepo/contributors.go | 2 +- clients/gitlabrepo/languages.go | 2 +- clients/gitlabrepo/releases.go | 2 +- clients/gitlabrepo/search.go | 2 +- clients/gitlabrepo/searchCommits.go | 2 +- clients/gitlabrepo/webhook.go | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/clients/gitlabrepo/branches.go b/clients/gitlabrepo/branches.go index 50949f14474..df832cde7ad 100644 --- a/clients/gitlabrepo/branches.go +++ b/clients/gitlabrepo/branches.go @@ -46,13 +46,13 @@ func (handler *branchesHandler) setup() error { return } - proj, _, err := handler.glClient.Projects.GetProject(handler.repourl.project, &gitlab.GetProjectOptions{}) + proj, _, err := handler.glClient.Projects.GetProject(handler.repourl.projectID, &gitlab.GetProjectOptions{}) if err != nil { handler.errSetup = fmt.Errorf("requirest for project failed with error %w", err) return } - branch, _, err := handler.glClient.Branches.GetBranch(handler.repourl.project, proj.DefaultBranch) + branch, _, err := handler.glClient.Branches.GetBranch(handler.repourl.projectID, proj.DefaultBranch) if err != nil { handler.errSetup = fmt.Errorf("request for default branch failed with error %w", err) return @@ -60,7 +60,7 @@ func (handler *branchesHandler) setup() error { if branch.Protected { protectedBranch, resp, err := handler.glClient.ProtectedBranches.GetProtectedBranch( - handler.repourl.project, branch.Name) + handler.repourl.projectID, branch.Name) if err != nil && resp.StatusCode != 403 { handler.errSetup = fmt.Errorf("request for protected branch failed with error %w", err) return @@ -70,14 +70,14 @@ func (handler *branchesHandler) setup() error { } projectStatusChecks, resp, err := handler.glClient.ExternalStatusChecks.ListProjectStatusChecks( - handler.repourl.project, &gitlab.ListOptions{}) + handler.repourl.projectID, &gitlab.ListOptions{}) if (err != nil || resp.StatusCode != 404) && resp.StatusCode != 401 { // 401: permissions. pass token authorization issues silently handler.errSetup = fmt.Errorf("request for external status checks failed with error %w", err) return } - projectApprovalRule, resp, err := handler.glClient.Projects.GetApprovalConfiguration(handler.repourl.project) + projectApprovalRule, resp, err := handler.glClient.Projects.GetApprovalConfiguration(handler.repourl.projectID) if err != nil && resp.StatusCode != 404 { handler.errSetup = fmt.Errorf("request for project approval rule failed with %w", err) return @@ -106,24 +106,24 @@ func (handler *branchesHandler) getDefaultBranch() (*clients.BranchRef, error) { } func (handler *branchesHandler) getBranch(branch string) (*clients.BranchRef, error) { - bran, _, err := handler.glClient.Branches.GetBranch(handler.repourl.project, branch) + bran, _, err := handler.glClient.Branches.GetBranch(handler.repourl.projectID, branch) if err != nil { return nil, fmt.Errorf("error getting branch in branchsHandler.getBranch: %w", err) } if bran.Protected { - protectedBranch, _, err := handler.glClient.ProtectedBranches.GetProtectedBranch(handler.repourl.project, bran.Name) + protectedBranch, _, err := handler.glClient.ProtectedBranches.GetProtectedBranch(handler.repourl.projectID, bran.Name) if err != nil { return nil, fmt.Errorf("request for protected branch failed with error %w", err) } projectStatusChecks, resp, err := handler.glClient.ExternalStatusChecks.ListProjectStatusChecks( - handler.repourl.project, &gitlab.ListOptions{}) + handler.repourl.projectID, &gitlab.ListOptions{}) if err != nil && resp.StatusCode != 404 { return nil, fmt.Errorf("request for external status checks failed with error %w", err) } - projectApprovalRule, resp, err := handler.glClient.Projects.GetApprovalConfiguration(handler.repourl.project) + projectApprovalRule, resp, err := handler.glClient.Projects.GetApprovalConfiguration(handler.repourl.projectID) if err != nil && resp.StatusCode != 404 { return nil, fmt.Errorf("request for project approval rule failed with %w", err) } diff --git a/clients/gitlabrepo/contributors.go b/clients/gitlabrepo/contributors.go index f52afd4d7c9..0b36594790c 100644 --- a/clients/gitlabrepo/contributors.go +++ b/clients/gitlabrepo/contributors.go @@ -46,7 +46,7 @@ func (handler *contributorsHandler) setup() error { return } contribs, _, err := handler.glClient.Repositories.Contributors( - handler.repourl.project, &gitlab.ListContributorsOptions{}) + handler.repourl.projectID, &gitlab.ListContributorsOptions{}) if err != nil { handler.errSetup = fmt.Errorf("error during ListContributors: %w", err) return diff --git a/clients/gitlabrepo/languages.go b/clients/gitlabrepo/languages.go index 57b9a652ca8..1346fabe012 100644 --- a/clients/gitlabrepo/languages.go +++ b/clients/gitlabrepo/languages.go @@ -40,7 +40,7 @@ func (handler *languagesHandler) init(repourl *repoURL) { func (handler *languagesHandler) setup() error { handler.once.Do(func() { client := handler.glClient - languageMap, _, err := client.Projects.GetProjectLanguages(handler.repourl.project) + languageMap, _, err := client.Projects.GetProjectLanguages(handler.repourl.projectID) if err != nil || languageMap == nil { handler.errSetup = fmt.Errorf("request for repo languages failed with %w", err) return diff --git a/clients/gitlabrepo/releases.go b/clients/gitlabrepo/releases.go index 140aa701e38..3b74b799ac8 100644 --- a/clients/gitlabrepo/releases.go +++ b/clients/gitlabrepo/releases.go @@ -44,7 +44,7 @@ func (handler *releasesHandler) setup() error { handler.errSetup = fmt.Errorf("%w: ListReleases only supported for HEAD queries", clients.ErrUnsupportedFeature) return } - releases, _, err := handler.glClient.Releases.ListReleases(handler.repourl.project, &gitlab.ListReleasesOptions{}) + releases, _, err := handler.glClient.Releases.ListReleases(handler.repourl.projectID, &gitlab.ListReleasesOptions{}) if err != nil { handler.errSetup = fmt.Errorf("%w: ListReleases failed", err) return diff --git a/clients/gitlabrepo/search.go b/clients/gitlabrepo/search.go index 2c4d94245b1..2b0ade52964 100644 --- a/clients/gitlabrepo/search.go +++ b/clients/gitlabrepo/search.go @@ -45,7 +45,7 @@ func (handler *searchHandler) search(request clients.SearchRequest) (clients.Sea return clients.SearchResponse{}, fmt.Errorf("handler.buildQuery: %w", err) } - blobs, _, err := handler.glClient.Search.BlobsByProject(handler.repourl.project, query, &gitlab.SearchOptions{}) + blobs, _, err := handler.glClient.Search.BlobsByProject(handler.repourl.projectID, query, &gitlab.SearchOptions{}) if err != nil { return clients.SearchResponse{}, fmt.Errorf("Search.BlobsByProject: %w", err) } diff --git a/clients/gitlabrepo/searchCommits.go b/clients/gitlabrepo/searchCommits.go index 6de69701d0e..6f29e2a3c38 100644 --- a/clients/gitlabrepo/searchCommits.go +++ b/clients/gitlabrepo/searchCommits.go @@ -41,7 +41,7 @@ func (handler *searchCommitsHandler) search(request clients.SearchCommitsOptions return nil, fmt.Errorf("handler.buildQuiery: %w", err) } - commits, _, err := handler.glClient.Search.CommitsByProject(handler.repourl.project, query, &gitlab.SearchOptions{}) + commits, _, err := handler.glClient.Search.CommitsByProject(handler.repourl.projectID, query, &gitlab.SearchOptions{}) if err != nil { return nil, fmt.Errorf("Search.Commits: %w", err) } diff --git a/clients/gitlabrepo/webhook.go b/clients/gitlabrepo/webhook.go index 9c9d6c49277..2d2970fd678 100644 --- a/clients/gitlabrepo/webhook.go +++ b/clients/gitlabrepo/webhook.go @@ -40,7 +40,7 @@ func (handler *webhookHandler) init(repourl *repoURL) { func (handler *webhookHandler) setup() error { handler.once.Do(func() { projectHooks, _, err := handler.glClient.Projects.ListProjectHooks( - handler.repourl.project, &gitlab.ListProjectHooksOptions{}) + handler.repourl.projectID, &gitlab.ListProjectHooksOptions{}) if err != nil { handler.errSetup = fmt.Errorf("request for project hooks failed with %w", err) return From 459870d2710f9e45549cb3d127e3c13aeec2119c Mon Sep 17 00:00:00 2001 From: Raghav Kaul Date: Thu, 18 May 2023 19:41:26 +0000 Subject: [PATCH 3/6] pass ref as listcommitoption Signed-off-by: Raghav Kaul --- clients/gitlabrepo/commits.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clients/gitlabrepo/commits.go b/clients/gitlabrepo/commits.go index 5029801d8c7..425bca9e306 100644 --- a/clients/gitlabrepo/commits.go +++ b/clients/gitlabrepo/commits.go @@ -41,7 +41,12 @@ func (handler *commitsHandler) init(repourl *repoURL) { func (handler *commitsHandler) setup() error { handler.once.Do(func() { - commits, _, err := handler.glClient.Commits.ListCommits(handler.repourl.projectID, &gitlab.ListCommitsOptions{}) + commits, _, err := handler.glClient.Commits.ListCommits( + handler.repourl.projectID, + &gitlab.ListCommitsOptions{ + RefName: &handler.repourl.commitSHA, + }, + ) if err != nil { handler.errSetup = fmt.Errorf("request for commits failed with %w", err) return From 0783bad1ca747e2b1bce0cedca72f803ddebafdc Mon Sep 17 00:00:00 2001 From: Raghav Kaul Date: Thu, 18 May 2023 19:50:36 +0000 Subject: [PATCH 4/6] update tests * CI-Tests: check if score > 0. pull request client is limited and can't go back to arbitrary pull requests. CI-Tests don't run on forks, so this can't be pinned either. But, for active repositories, we typically expect *some* tests to be run Signed-off-by: Raghav Kaul --- e2e/ci_tests_test.go | 10 ++++------ e2e/code_review_test.go | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/e2e/ci_tests_test.go b/e2e/ci_tests_test.go index 58d37400c77..5f361b9af01 100644 --- a/e2e/ci_tests_test.go +++ b/e2e/ci_tests_test.go @@ -112,7 +112,7 @@ var _ = Describe("E2E TEST:"+checks.CheckCITests, func() { repoClient, err := gitlabrepo.CreateGitlabClientWithToken(context.Background(), os.Getenv("GITLAB_AUTH_TOKEN"), repo) Expect(err).Should(BeNil()) // url to commit is https://gitlab.com/gitlab-org/gitlab/-/commit/8ae23fa220d73fa07501aabd94214c9e83fe61a0 - err = repoClient.InitRepo(repo, "8ae23fa220d73fa07501aabd94214c9e83fe61a0", 0) + err = repoClient.InitRepo(repo, "HEAD", 0) Expect(err).Should(BeNil()) req := checker.CheckRequest{ Ctx: context.Background(), @@ -122,13 +122,12 @@ var _ = Describe("E2E TEST:"+checks.CheckCITests, func() { } expected := scut.TestReturn{ Error: nil, - Score: 9, NumberOfWarn: 0, NumberOfInfo: 0, NumberOfDebug: 13, } result := checks.CITests(&req) - Expect(result.Score).Should(BeNumerically("==", expected.Score)) + Expect(result.Score).Should(BeNumerically(">", expected.Score)) Expect(result.Error).Should(BeNil()) Expect(repoClient.Close()).Should(BeNil()) }) @@ -141,7 +140,7 @@ var _ = Describe("E2E TEST:"+checks.CheckCITests, func() { repoClient, err := gitlabrepo.CreateGitlabClientWithToken(context.Background(), os.Getenv("GITLAB_AUTH_TOKEN"), repo) Expect(err).Should(BeNil()) // url to commit is https://gitlab.com/fdroid/fdroidclient/-/commit/a1d33881902cee33586a4fd4ee1538042a7bdedf - err = repoClient.InitRepo(repo, "a1d33881902cee33586a4fd4ee1538042a7bdedf", 0) + err = repoClient.InitRepo(repo, "HEAD", 0) Expect(err).Should(BeNil()) req := checker.CheckRequest{ Ctx: context.Background(), @@ -151,13 +150,12 @@ var _ = Describe("E2E TEST:"+checks.CheckCITests, func() { } expected := scut.TestReturn{ Error: nil, - Score: 7, NumberOfWarn: 0, NumberOfInfo: 0, NumberOfDebug: 1, } result := checks.CITests(&req) - Expect(result.Score).Should(BeNumerically("==", expected.Score)) + Expect(result.Score).Should(BeNumerically(">", expected.Score)) Expect(result.Error).Should(BeNil()) Expect(repoClient.Close()).Should(BeNil()) }) diff --git a/e2e/code_review_test.go b/e2e/code_review_test.go index ec367df7a2a..66332268601 100644 --- a/e2e/code_review_test.go +++ b/e2e/code_review_test.go @@ -159,7 +159,7 @@ var _ = Describe("E2E TEST:"+checks.CheckCodeReview, func() { Expect(err).Should(BeNil()) repoClient, err := gitlabrepo.CreateGitlabClientWithToken(context.Background(), os.Getenv("GITLAB_AUTH_TOKEN"), repo) Expect(err).Should(BeNil()) - err = repoClient.InitRepo(repo, "1f7ed43c120047102862d9d1d644f5b2de7a47f2", 0) + err = repoClient.InitRepo(repo, "680a1154cf3806390c2e4a9e95a7c6d6107b470f", 0) Expect(err).Should(BeNil()) req := checker.CheckRequest{ From 1e08b5527858d592098930a82cec509448a3c428 Mon Sep 17 00:00:00 2001 From: Raghav Kaul Date: Tue, 23 May 2023 23:04:03 +0000 Subject: [PATCH 5/6] fix commitshandler commitSHA tests Signed-off-by: Raghav Kaul --- clients/gitlabrepo/client.go | 3 ++- clients/gitlabrepo/graphql.go | 7 ++++--- clients/gitlabrepo/graphql_test.go | 7 +++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/clients/gitlabrepo/client.go b/clients/gitlabrepo/client.go index 4294a8a9912..5b16a0fc8c9 100644 --- a/clients/gitlabrepo/client.go +++ b/clients/gitlabrepo/client.go @@ -164,11 +164,12 @@ func (client *Client) ListCommits() ([]clients.Commit, error) { return []clients.Commit{}, err } + before := commitsRaw[0].CommittedDate // Get merge request details from GraphQL // GitLab REST API doesn't provide a way to link Merge Requests and Commits that // are within them without making a REST call for each commit (~30 by default) // Making 1 GraphQL query to combine the results of 2 REST calls, we avoid this - mrDetails, err := client.graphql.getMergeRequestsDetail() + mrDetails, err := client.graphql.getMergeRequestsDetail(before) if err != nil { return []clients.Commit{}, err } diff --git a/clients/gitlabrepo/graphql.go b/clients/gitlabrepo/graphql.go index 2d5e76541f4..4b3b38695d8 100644 --- a/clients/gitlabrepo/graphql.go +++ b/clients/gitlabrepo/graphql.go @@ -54,7 +54,7 @@ type graphqlData struct { Project struct { MergeRequests struct { Nodes []graphqlMergeRequestNode `graphql:"nodes"` - } `graphql:"mergeRequests(sort: MERGED_AT_DESC, state: merged)"` + } `graphql:"mergeRequests(sort: MERGED_AT_DESC, state: merged, mergedBefore: $mergedBefore)"` } `graphql:"project(fullPath: $fullPath)"` QueryComplexity struct { Limit int `graphql:"limit"` @@ -127,11 +127,12 @@ func (g *GitlabGID) UnmarshalJSON(data []byte) error { return nil } -func (handler *graphqlHandler) getMergeRequestsDetail() (graphqlData, error) { +func (handler *graphqlHandler) getMergeRequestsDetail(before *time.Time) (graphqlData, error) { data := graphqlData{} path := fmt.Sprintf("%s/%s", handler.repourl.owner, handler.repourl.project) params := map[string]interface{}{ - "fullPath": path, + "fullPath": path, + "mergedBefore": before, } err := handler.graphClient.Query(context.Background(), &data, params) if err != nil { diff --git a/clients/gitlabrepo/graphql_test.go b/clients/gitlabrepo/graphql_test.go index 37e54dd4eef..dcb2276e6ea 100644 --- a/clients/gitlabrepo/graphql_test.go +++ b/clients/gitlabrepo/graphql_test.go @@ -19,6 +19,7 @@ import ( "fmt" "os" "testing" + "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -46,7 +47,8 @@ var _ = Describe("E2E TEST: gitlabrepo.graphqlHandler", func() { path := fmt.Sprintf("%s/%s", graphqlhandler.repourl.owner, graphqlhandler.repourl.project) params := map[string]interface{}{ - "fullPath": path, + "fullPath": path, + "mergedBefore": time.Now(), } err = graphqlhandler.graphClient.Query(context.Background(), &data, params) Expect(err).Should(BeNil()) @@ -65,7 +67,8 @@ var _ = Describe("E2E TEST: gitlabrepo.graphqlHandler", func() { path := fmt.Sprintf("%s/%s", graphqlhandler.repourl.owner, graphqlhandler.repourl.project) params := map[string]interface{}{ - "fullPath": path, + "fullPath": path, + "mergedBefore": time.Now(), } err = graphqlhandler.graphClient.Query(context.Background(), &data, params) Expect(err).Should(BeNil()) From a313680a886abd19d6a24e49fa1dc32ce49af4eb Mon Sep 17 00:00:00 2001 From: Raghav Kaul Date: Tue, 23 May 2023 23:04:30 +0000 Subject: [PATCH 6/6] update tests Signed-off-by: Raghav Kaul --- clients/gitlabrepo/commits.go | 2 +- clients/gitlabrepo/graphql_test.go | 4 ++-- e2e/ci_tests_test.go | 10 ++++++---- e2e/code_review_test.go | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/clients/gitlabrepo/commits.go b/clients/gitlabrepo/commits.go index 84f83e50bdc..1303a203672 100644 --- a/clients/gitlabrepo/commits.go +++ b/clients/gitlabrepo/commits.go @@ -65,7 +65,7 @@ func (handler *commitsHandler) listRawCommits() ([]*gitlab.Commit, error) { return handler.commitsRaw, nil } -// zip combines Commit and MergeRequest information from the GitLab REST API with +// zip combines Commit information from the GitLab REST API with MergeRequests // information from the GitLab GraphQL API. The REST API doesn't provide any way to // get from Commits -> MRs that they were part of or vice-versa (MRs -> commits they // contain), except through a separate API call. Instead of calling the REST API diff --git a/clients/gitlabrepo/graphql_test.go b/clients/gitlabrepo/graphql_test.go index dcb2276e6ea..ce3e8ec4054 100644 --- a/clients/gitlabrepo/graphql_test.go +++ b/clients/gitlabrepo/graphql_test.go @@ -31,13 +31,13 @@ func TestGitlabRepoE2E(t *testing.T) { } t.Parallel() RegisterFailHandler(Fail) - RunSpecs(t, "Githubrepo Suite") + RunSpecs(t, "GitLab Repo Suite") } var _ = Describe("E2E TEST: gitlabrepo.graphqlHandler", func() { var graphqlhandler graphqlHandler - Context("E2E TEST: Confirm query result", func() { + Context("E2E TEST: Confirm query result - GitLab", func() { It("Should have sufficient number of merge requests", func() { repo, err := MakeGitlabRepo("gitlab.com/gitlab-org/gitlab") Expect(err).Should(BeNil()) diff --git a/e2e/ci_tests_test.go b/e2e/ci_tests_test.go index 5f361b9af01..945f078294d 100644 --- a/e2e/ci_tests_test.go +++ b/e2e/ci_tests_test.go @@ -112,7 +112,7 @@ var _ = Describe("E2E TEST:"+checks.CheckCITests, func() { repoClient, err := gitlabrepo.CreateGitlabClientWithToken(context.Background(), os.Getenv("GITLAB_AUTH_TOKEN"), repo) Expect(err).Should(BeNil()) // url to commit is https://gitlab.com/gitlab-org/gitlab/-/commit/8ae23fa220d73fa07501aabd94214c9e83fe61a0 - err = repoClient.InitRepo(repo, "HEAD", 0) + err = repoClient.InitRepo(repo, "8ae23fa220d73fa07501aabd94214c9e83fe61a0", 0) Expect(err).Should(BeNil()) req := checker.CheckRequest{ Ctx: context.Background(), @@ -122,12 +122,13 @@ var _ = Describe("E2E TEST:"+checks.CheckCITests, func() { } expected := scut.TestReturn{ Error: nil, + Score: 8, NumberOfWarn: 0, NumberOfInfo: 0, NumberOfDebug: 13, } result := checks.CITests(&req) - Expect(result.Score).Should(BeNumerically(">", expected.Score)) + Expect(result.Score).Should(BeNumerically("==", expected.Score)) Expect(result.Error).Should(BeNil()) Expect(repoClient.Close()).Should(BeNil()) }) @@ -140,7 +141,7 @@ var _ = Describe("E2E TEST:"+checks.CheckCITests, func() { repoClient, err := gitlabrepo.CreateGitlabClientWithToken(context.Background(), os.Getenv("GITLAB_AUTH_TOKEN"), repo) Expect(err).Should(BeNil()) // url to commit is https://gitlab.com/fdroid/fdroidclient/-/commit/a1d33881902cee33586a4fd4ee1538042a7bdedf - err = repoClient.InitRepo(repo, "HEAD", 0) + err = repoClient.InitRepo(repo, "a1d33881902cee33586a4fd4ee1538042a7bdedf", 0) Expect(err).Should(BeNil()) req := checker.CheckRequest{ Ctx: context.Background(), @@ -150,12 +151,13 @@ var _ = Describe("E2E TEST:"+checks.CheckCITests, func() { } expected := scut.TestReturn{ Error: nil, + Score: 10, NumberOfWarn: 0, NumberOfInfo: 0, NumberOfDebug: 1, } result := checks.CITests(&req) - Expect(result.Score).Should(BeNumerically(">", expected.Score)) + Expect(result.Score).Should(BeNumerically("==", expected.Score)) Expect(result.Error).Should(BeNil()) Expect(repoClient.Close()).Should(BeNil()) }) diff --git a/e2e/code_review_test.go b/e2e/code_review_test.go index 66332268601..69e5e1748cb 100644 --- a/e2e/code_review_test.go +++ b/e2e/code_review_test.go @@ -159,7 +159,7 @@ var _ = Describe("E2E TEST:"+checks.CheckCodeReview, func() { Expect(err).Should(BeNil()) repoClient, err := gitlabrepo.CreateGitlabClientWithToken(context.Background(), os.Getenv("GITLAB_AUTH_TOKEN"), repo) Expect(err).Should(BeNil()) - err = repoClient.InitRepo(repo, "680a1154cf3806390c2e4a9e95a7c6d6107b470f", 0) + err = repoClient.InitRepo(repo, "1f7ed43c120047102862d9d1d644f5b2de7a47f2", 0) Expect(err).Should(BeNil()) req := checker.CheckRequest{ @@ -170,7 +170,7 @@ var _ = Describe("E2E TEST:"+checks.CheckCodeReview, func() { } expected := scut.TestReturn{ Error: nil, - Score: 3, + Score: 0, NumberOfDebug: 1, } result := checks.CodeReview(&req)