Skip to content

Commit

Permalink
fix: add test case for forked scenario
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Ulmer <25484774+Ulminator@users.noreply.github.com>
  • Loading branch information
Ulminator committed Nov 9, 2024
1 parent f871462 commit 4f2fa3d
Show file tree
Hide file tree
Showing 3 changed files with 520 additions and 385 deletions.
2 changes: 1 addition & 1 deletion server/events/project_command_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func (p *DefaultProjectCommandBuilder) buildAllCommandsByCfg(ctx *command.Contex
var hasRepoCfg bool
var repoCfgData []byte
var err error
ctx.Log.Debug("Getting file content for pull request %d", ctx.Pull)
ctx.Log.Debug("Getting file content for pull request %+v", ctx.Pull)
if ctx.HeadRepo.Owner != ctx.Pull.BaseRepo.Owner {
hasRepoCfg, repoCfgData, err = p.VCSClient.GetFileContent(ctx.Log, ctx.HeadRepo, ctx.Pull.HeadBranch, repoCfgFile)
} else {
Expand Down
33 changes: 28 additions & 5 deletions server/events/project_command_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,7 @@ projects:
func TestDefaultProjectCommandBuilder_SkipCloneNoChanges(t *testing.T) {
cases := []struct {
AtlantisYAML string
IsFork bool
ExpectedCtxs int
ExpectedClones InvocationCountMatcher
ModifiedFiles []string
Expand All @@ -1640,6 +1641,16 @@ projects:
{
AtlantisYAML: `
version: 3
projects:
- dir: dir1`,
IsFork: true,
ExpectedCtxs: 0,
ExpectedClones: Never(),
ModifiedFiles: []string{"dir2/main.tf"},
},
{
AtlantisYAML: `
version: 3
parallel_plan: true`,
ExpectedCtxs: 0,
ExpectedClones: Once(),
Expand Down Expand Up @@ -1706,20 +1717,32 @@ projects:

var actCtxs []command.ProjectContext
var err error

headRepo := models.Repo{Owner: "owner"}
baseRepo := headRepo
if c.IsFork {
baseRepo.Owner = "forkedOwner"
}

actCtxs, err = builder.BuildAutoplanCommands(&command.Context{
HeadRepo: models.Repo{},
Pull: models.PullRequest{},
User: models.User{},
Log: logger,
Scope: scope,
HeadRepo: headRepo,
Pull: models.PullRequest{
BaseRepo: baseRepo,
},
User: models.User{},
Log: logger,
Scope: scope,
PullRequestStatus: models.PullReqStatus{
Mergeable: true,
},
})

Ok(t, err)
Equals(t, c.ExpectedCtxs, len(actCtxs))
workingDir.VerifyWasCalled(c.ExpectedClones).Clone(Any[logging.SimpleLogging](), Any[models.Repo](),
Any[models.PullRequest](), Any[string]())
_, actRepo, _, _ := vcsClient.VerifyWasCalled(Once()).GetFileContent(Any[logging.SimpleLogging](), Any[models.Repo](), Any[string](), Any[string]()).GetCapturedArguments()
Equals(t, headRepo, actRepo)
}
}

Expand Down
Loading

0 comments on commit 4f2fa3d

Please sign in to comment.