Files
atlantis/server/events/command/result_test.go
Sarvar Muminov 90e92e3a13 chore: move CommandContext and CommandResult to models (#193) (#2093)
* Moved CommandContext and CommandResult to models (#193)

* Moved CommandContext and CommandResult to models

* move from models to command

rename CommandContext -> Context
rename CommandResult -> Result

* moved command related helpers into command package

* move ProjectCommandContext and ProjectResult to command/project package

* move project command context and project result

* revert unrelated code

* move tests

* fix left over

* fix linting

* fix tests

* remove unused import

* fix project context dependencies

* fix depenedecies

* fix typo
2022-03-21 10:36:13 -07:00

109 lines
1.9 KiB
Go

package command_test
import (
"errors"
"testing"
"github.com/runatlantis/atlantis/server/events/command"
"github.com/runatlantis/atlantis/server/events/models"
. "github.com/runatlantis/atlantis/testing"
)
func TestCommandResult_HasErrors(t *testing.T) {
cases := map[string]struct {
cr command.Result
exp bool
}{
"error": {
cr: command.Result{
Error: errors.New("err"),
},
exp: true,
},
"failure": {
cr: command.Result{
Failure: "failure",
},
exp: true,
},
"empty results list": {
cr: command.Result{
ProjectResults: []command.ProjectResult{},
},
exp: false,
},
"successful plan": {
cr: command.Result{
ProjectResults: []command.ProjectResult{
{
PlanSuccess: &models.PlanSuccess{},
},
},
},
exp: false,
},
"successful apply": {
cr: command.Result{
ProjectResults: []command.ProjectResult{
{
ApplySuccess: "success",
},
},
},
exp: false,
},
"single errored project": {
cr: command.Result{
ProjectResults: []command.ProjectResult{
{
Error: errors.New("err"),
},
},
},
exp: true,
},
"single failed project": {
cr: command.Result{
ProjectResults: []command.ProjectResult{
{
Failure: "failure",
},
},
},
exp: true,
},
"two successful projects": {
cr: command.Result{
ProjectResults: []command.ProjectResult{
{
PlanSuccess: &models.PlanSuccess{},
},
{
ApplySuccess: "success",
},
},
},
exp: false,
},
"one successful, one failed project": {
cr: command.Result{
ProjectResults: []command.ProjectResult{
{
PlanSuccess: &models.PlanSuccess{},
},
{
Failure: "failed",
},
},
},
exp: true,
},
}
for descrip, c := range cases {
t.Run(descrip, func(t *testing.T) {
Equals(t, c.exp, c.cr.HasErrors())
})
}
}