Files
atlantis/server/events/command/name_test.go
Ken Kaizu f09a9d4c01 feat: --allow-commands restricts available atlantis commands (#2877)
* feat: --allow-command configuration restricts available atlantis commands

* add version and approve_policies into allow commands defaults

* allow-commands accept all keyword which allows all commands

* remove redundant nest

* more detail abount allow-commands all keyword

* Update server/events/comment_parser.go
2022-12-27 22:52:39 -06:00

97 lines
2.2 KiB
Go

package command_test
import (
"testing"
"github.com/runatlantis/atlantis/server/events/command"
"github.com/stretchr/testify/assert"
)
func TestName_TitleString(t *testing.T) {
tests := []struct {
c command.Name
want string
}{
{command.Apply, "Apply"},
{command.PolicyCheck, "Policy Check"},
}
for _, tt := range tests {
t.Run(tt.want, func(t *testing.T) {
if got := tt.c.TitleString(); got != tt.want {
t.Errorf("TitleString() = %v, want %v", got, tt.want)
}
})
}
}
func TestName_String(t *testing.T) {
tests := []struct {
c command.Name
want string
}{
{command.Apply, "apply"},
{command.Plan, "plan"},
{command.Unlock, "unlock"},
{command.PolicyCheck, "policy_check"},
{command.ApprovePolicies, "approve_policies"},
{command.Version, "version"},
{command.Import, "import"},
}
for _, tt := range tests {
t.Run(tt.want, func(t *testing.T) {
if got := tt.c.String(); got != tt.want {
t.Errorf("String() = %v, want %v", got, tt.want)
}
})
}
}
func TestName_DefaultUsage(t *testing.T) {
tests := []struct {
c command.Name
want string
}{
{command.Apply, "apply"},
{command.Plan, "plan"},
{command.Unlock, "unlock"},
{command.PolicyCheck, "policy_check"},
{command.ApprovePolicies, "approve_policies"},
{command.Version, "version"},
{command.Import, "import ADDRESS ID"},
}
for _, tt := range tests {
t.Run(tt.c.String(), func(t *testing.T) {
if got := tt.c.DefaultUsage(); got != tt.want {
t.Errorf("DefaultUsage() = %v, want %v", got, tt.want)
}
})
}
}
func TestParseCommandName(t *testing.T) {
tests := []struct {
exp command.Name
name string
}{
{command.Apply, "apply"},
{command.Plan, "plan"},
{command.Unlock, "unlock"},
{command.PolicyCheck, "policy_check"},
{command.ApprovePolicies, "approve_policies"},
{command.Version, "version"},
{command.Import, "import"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := command.ParseCommandName(tt.name)
assert.NoError(t, err)
assert.Equal(t, tt.exp, got)
})
}
t.Run("unknown command", func(t *testing.T) {
_, err := command.ParseCommandName("unknown")
assert.ErrorContains(t, err, "unknown command name: unknown")
})
}