Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemassa committed Feb 8, 2024
1 parent 7b2fd4e commit 6cec24c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 11 deletions.
12 changes: 12 additions & 0 deletions server/core/db/boltdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,18 @@ func TestLockingExistingLock(t *testing.T) {
Equals(t, true, acquired)
Equals(t, newLock, currLock)
}
// TODO: How should we handle different name?
/*
t.Log("...succeed if the new project has a different name")
{
newLock := lock
newLock.Project = models.NewProject(project.RepoFullName, project.Path, "different-name")
acquired, currLock, err := b.TryLock(newLock)
Ok(t, err)
Equals(t, true, acquired)
Equals(t, newLock, currLock)
}
*/

t.Log("...not succeed if the new project only has a different pullNum")
{
Expand Down
13 changes: 13 additions & 0 deletions server/core/redis/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,19 @@ func TestLockingExistingLock(t *testing.T) {
Equals(t, newLock, currLock)
}

// TODO: How should we handle different name?
/*
t.Log("...succeed if the new project has a different name")
{
newLock := lock
newLock.Project = models.NewProject(project.RepoFullName, project.Path, "different-name")
acquired, currLock, err := rdb.TryLock(newLock)
Ok(t, err)
Equals(t, true, acquired)
Equals(t, newLock, currLock)
}
*/

t.Log("...not succeed if the new project only has a different pullNum")
{
newLock := lock
Expand Down
1 change: 1 addition & 0 deletions server/events/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ type Project struct {
}

func (p Project) String() string {
// TODO: Incorporate ProjectName?
return fmt.Sprintf("repofullname=%s path=%s", p.RepoFullName, p.Path)
}

Expand Down
42 changes: 31 additions & 11 deletions server/events/models/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,27 +168,47 @@ func TestProject_String(t *testing.T) {

func TestNewProject(t *testing.T) {
cases := []struct {
path string
expPath string
repo string
path string
name string
expProject models.Project
}{
{
"/",
".",
repo: "foo/bar",
path: "/",
name: "",
expProject: models.Project{
ProjectName: "",
RepoFullName: "foo/bar",
Path: ".",
},
},
{
"./another/path",
"another/path",
repo: "baz/foo",
path: "./another/path",
name: "somename",
expProject: models.Project{
ProjectName: "somename",
RepoFullName: "baz/foo",
Path: "another/path",
},
},
{
".",
".",
repo: "baz/foo",
path: ".",
name: "somename",
expProject: models.Project{
ProjectName: "somename",
RepoFullName: "baz/foo",
Path: ".",
},
},
}

for _, c := range cases {
t.Run(c.path, func(t *testing.T) {
p := models.NewProject("repo/owner", c.path, "")
Equals(t, c.expPath, p.Path)
t.Run(fmt.Sprintf("%s_%s", c.name, c.path), func(t *testing.T) {
p := models.NewProject(c.repo, c.path, c.name)
Equals(t, c.expProject, p)
})
}
}
Expand Down
11 changes: 11 additions & 0 deletions server/events/pull_closed_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ func TestCleanUpPullComments(t *testing.T) {
},
"- dir: `.` workspace: `default`",
},
{
"single lock, named project",
[]models.ProjectLock{
{
Project: models.NewProject("owner/repo", "", "projectname"),
Workspace: "default",
},
},
// TODO: Should project name be included in output?
"- dir: `.` workspace: `default`",
},
{
"single lock, non-empty path",
[]models.ProjectLock{
Expand Down

0 comments on commit 6cec24c

Please sign in to comment.