Skip to content

Commit

Permalink
test: add 1 test for project.gp
Browse files Browse the repository at this point in the history
  • Loading branch information
kperreau committed Apr 18, 2024
1 parent 87f6f35 commit 2d01a6f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ type Options struct {
PrintStdout bool
}

var RootPath = "."

func NewProjectsList(opt *Options) (IList, error) {
projects, err := getProjects(opt)
if err != nil {
Expand Down Expand Up @@ -136,13 +138,13 @@ type processProjectOptions struct {
}

func getProjects(opt *Options) (projects []*Project, err error) {
projectsFiles, err := find(".", configFileName)
projectsFiles, err := find(RootPath, configFileName)
if err != nil {
return nil, err
}

// preload go mod file dependencies
gomod, err := loadGOModFile(".")
gomod, err := loadGOModFile(RootPath)
if err != nil {
return nil, err
}
Expand Down
46 changes: 46 additions & 0 deletions pkg/project/project_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package project

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestNewProjectsList_ValidOptions(t *testing.T) {
opt := &Options{
Target: "goac",
DryRun: false,
MaxConcurrency: 2,
BinaryCheck: true,
Force: false,
DockerIgnore: true,
ProjectsName: []string{"project1", "project2"},
Debug: []string{"debug1", "debug2"},
PrintStdout: true,
}

RootPath = "./../.."
list, err := NewProjectsList(opt)

assert.NoError(t, err)
assert.NotNil(t, list)
}

func TestNewProjectsList_InvalidPath(t *testing.T) {
opt := &Options{
Target: "goac",
DryRun: false,
MaxConcurrency: 2,
BinaryCheck: true,
Force: false,
DockerIgnore: true,
ProjectsName: []string{"project1", "project2"},
Debug: []string{"debug1", "debug2"},
PrintStdout: true,
}

RootPath = "invalid-path"
list, err := NewProjectsList(opt)

assert.Error(t, err)
assert.Nil(t, list)
}

0 comments on commit 2d01a6f

Please sign in to comment.