From 29aea90de548628cc8451343d3b7e08974779c41 Mon Sep 17 00:00:00 2001 From: Luke Massa Date: Mon, 5 Feb 2024 23:59:40 -0500 Subject: [PATCH] Fix tests --- server/core/db/boltdb_test.go | 8 ++++---- server/core/locking/locking_test.go | 2 +- server/core/redis/redis_test.go | 8 ++++---- server/events/delete_lock_command_test.go | 3 ++- server/events/models/models_test.go | 2 +- server/events/project_finder.go | 6 +++++- server/events/pull_closed_executor_test.go | 18 +++++++++--------- 7 files changed, 26 insertions(+), 21 deletions(-) diff --git a/server/core/db/boltdb_test.go b/server/core/db/boltdb_test.go index 9ef5568467..239cb6a470 100644 --- a/server/core/db/boltdb_test.go +++ b/server/core/db/boltdb_test.go @@ -29,7 +29,7 @@ import ( var lockBucket = "bucket" var configBucket = "configBucket" -var project = models.NewProject("owner/repo", "parent/child") +var project = models.NewProject("owner/repo", "parent/child", "") var workspace = "default" var pullNum = 1 var lock = models.ProjectLock{ @@ -155,7 +155,7 @@ func TestListMultipleLocks(t *testing.T) { for _, r := range repos { newLock := lock - newLock.Project = models.NewProject(r, "path") + newLock.Project = models.NewProject(r, "path", "") _, _, err := b.TryLock(newLock) Ok(t, err) } @@ -207,7 +207,7 @@ func TestLockingExistingLock(t *testing.T) { t.Log("...succeed if the new project has a different path") { newLock := lock - newLock.Project = models.NewProject(project.RepoFullName, "different/path") + newLock.Project = models.NewProject(project.RepoFullName, "different/path", "") acquired, currLock, err := b.TryLock(newLock) Ok(t, err) Equals(t, true, acquired) @@ -227,7 +227,7 @@ func TestLockingExistingLock(t *testing.T) { t.Log("...succeed if the new project has a different repoName") { newLock := lock - newLock.Project = models.NewProject("different/repo", project.Path) + newLock.Project = models.NewProject("different/repo", project.Path, "") acquired, currLock, err := b.TryLock(newLock) Ok(t, err) Equals(t, true, acquired) diff --git a/server/core/locking/locking_test.go b/server/core/locking/locking_test.go index 57a6701455..68d79d8580 100644 --- a/server/core/locking/locking_test.go +++ b/server/core/locking/locking_test.go @@ -28,7 +28,7 @@ import ( . "github.com/runatlantis/atlantis/testing" ) -var project = models.NewProject("owner/repo", "path") +var project = models.NewProject("owner/repo", "path", "") var workspace = "workspace" var pull = models.PullRequest{} var user = models.User{} diff --git a/server/core/redis/redis_test.go b/server/core/redis/redis_test.go index aeb203fd30..68a58c66e4 100644 --- a/server/core/redis/redis_test.go +++ b/server/core/redis/redis_test.go @@ -23,7 +23,7 @@ import ( . "github.com/runatlantis/atlantis/testing" ) -var project = models.NewProject("owner/repo", "parent/child") +var project = models.NewProject("owner/repo", "parent/child", "") var workspace = "default" var pullNum = 1 var lock = models.ProjectLock{ @@ -191,7 +191,7 @@ func TestListMultipleLocks(t *testing.T) { for _, r := range repos { newLock := lock - newLock.Project = models.NewProject(r, "path") + newLock.Project = models.NewProject(r, "path", "") _, _, err := rdb.TryLock(newLock) Ok(t, err) } @@ -243,7 +243,7 @@ func TestLockingExistingLock(t *testing.T) { t.Log("...succeed if the new project has a different path") { newLock := lock - newLock.Project = models.NewProject(project.RepoFullName, "different/path") + newLock.Project = models.NewProject(project.RepoFullName, "different/path", "") acquired, currLock, err := rdb.TryLock(newLock) Ok(t, err) Equals(t, true, acquired) @@ -263,7 +263,7 @@ func TestLockingExistingLock(t *testing.T) { t.Log("...succeed if the new project has a different repoName") { newLock := lock - newLock.Project = models.NewProject("different/repo", project.Path) + newLock.Project = models.NewProject("different/repo", project.Path, "") acquired, currLock, err := rdb.TryLock(newLock) Ok(t, err) Equals(t, true, acquired) diff --git a/server/events/delete_lock_command_test.go b/server/events/delete_lock_command_test.go index 87d8478337..75ffe0488b 100644 --- a/server/events/delete_lock_command_test.go +++ b/server/events/delete_lock_command_test.go @@ -119,7 +119,7 @@ func TestDeleteLocksByPull_SingleSuccess(t *testing.T) { pullNum := 2 path := "." workspace := "default" - projectName := "" + projectName := "projectname" RegisterMockTestingT(t) l := lockmocks.NewMockLocker() @@ -135,6 +135,7 @@ func TestDeleteLocksByPull_SingleSuccess(t *testing.T) { Project: models.Project{ Path: path, RepoFullName: pull.BaseRepo.FullName, + ProjectName: projectName, }, }, }, nil, diff --git a/server/events/models/models_test.go b/server/events/models/models_test.go index c05016d2af..36cd4ee5a8 100644 --- a/server/events/models/models_test.go +++ b/server/events/models/models_test.go @@ -187,7 +187,7 @@ func TestNewProject(t *testing.T) { for _, c := range cases { t.Run(c.path, func(t *testing.T) { - p := models.NewProject("repo/owner", c.path) + p := models.NewProject("repo/owner", c.path, "") Equals(t, c.expPath, p.Path) }) } diff --git a/server/events/project_finder.go b/server/events/project_finder.go index 3238e553d8..79c4a567f2 100644 --- a/server/events/project_finder.go +++ b/server/events/project_finder.go @@ -167,7 +167,11 @@ func (p *DefaultProjectFinder) DetermineProjects(log logging.SimpleLogging, modi exists := p.removeNonExistingDirs(uniqueDirs, absRepoDir) for _, p := range exists { - projects = append(projects, models.NewProject(repoFullName, p, "???????????")) + // It's unclear how we are supposed to determine the project name at this point + // For now, we'll just add the default projectName + // TODO: Add support for non-default projectName + projectName := "" + projects = append(projects, models.NewProject(repoFullName, p, projectName)) } log.Info("there are %d modified project(s) at path(s): %v", len(projects), strings.Join(exists, ", ")) diff --git a/server/events/pull_closed_executor_test.go b/server/events/pull_closed_executor_test.go index 77c1544be7..73a3b1e56e 100644 --- a/server/events/pull_closed_executor_test.go +++ b/server/events/pull_closed_executor_test.go @@ -107,7 +107,7 @@ func TestCleanUpPullComments(t *testing.T) { "single lock, empty path", []models.ProjectLock{ { - Project: models.NewProject("owner/repo", ""), + Project: models.NewProject("owner/repo", "", ""), Workspace: "default", }, }, @@ -117,7 +117,7 @@ func TestCleanUpPullComments(t *testing.T) { "single lock, non-empty path", []models.ProjectLock{ { - Project: models.NewProject("owner/repo", "path"), + Project: models.NewProject("owner/repo", "path", ""), Workspace: "default", }, }, @@ -127,11 +127,11 @@ func TestCleanUpPullComments(t *testing.T) { "single path, multiple workspaces", []models.ProjectLock{ { - Project: models.NewProject("owner/repo", "path"), + Project: models.NewProject("owner/repo", "path", ""), Workspace: "workspace1", }, { - Project: models.NewProject("owner/repo", "path"), + Project: models.NewProject("owner/repo", "path", ""), Workspace: "workspace2", }, }, @@ -141,19 +141,19 @@ func TestCleanUpPullComments(t *testing.T) { "multiple paths, multiple workspaces", []models.ProjectLock{ { - Project: models.NewProject("owner/repo", "path"), + Project: models.NewProject("owner/repo", "path", ""), Workspace: "workspace1", }, { - Project: models.NewProject("owner/repo", "path"), + Project: models.NewProject("owner/repo", "path", ""), Workspace: "workspace2", }, { - Project: models.NewProject("owner/repo", "path2"), + Project: models.NewProject("owner/repo", "path2", ""), Workspace: "workspace1", }, { - Project: models.NewProject("owner/repo", "path2"), + Project: models.NewProject("owner/repo", "path2", ""), Workspace: "workspace2", }, }, @@ -260,7 +260,7 @@ func TestCleanUpLogStreaming(t *testing.T) { locks := []models.ProjectLock{ { - Project: models.NewProject(testdata.GithubRepo.FullName, ""), + Project: models.NewProject(testdata.GithubRepo.FullName, "", ""), Workspace: "default", }, }