argument_defaults_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package executor
  2. import (
  3. "testing"
  4. config "github.com/OliveTin/OliveTin/internal/config"
  5. "github.com/OliveTin/OliveTin/internal/configissues"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/stretchr/testify/require"
  8. )
  9. func TestValidateArgumentDefaultSkipsTemplates(t *testing.T) {
  10. action := &config.Action{Title: "Deploy", ID: "deploy"}
  11. arg := &config.ActionArgument{
  12. Name: "host",
  13. Type: "ascii_identifier",
  14. Default: `{{ host.name }}`,
  15. }
  16. assert.Nil(t, validateArgumentDefault(action, arg))
  17. }
  18. func TestValidateArgumentDefaultLiteralInvalid(t *testing.T) {
  19. action := &config.Action{Title: "Deploy", ID: "deploy"}
  20. arg := &config.ActionArgument{
  21. Name: "host",
  22. Type: "ascii_identifier",
  23. Default: "not a valid id!!",
  24. }
  25. issue := validateArgumentDefault(action, arg)
  26. require.NotNil(t, issue)
  27. assert.Equal(t, configissues.CodeArgDefaultInvalid, issue.Code)
  28. }
  29. func TestValidateArgumentDefaultLiteralValid(t *testing.T) {
  30. action := &config.Action{Title: "Deploy", ID: "deploy"}
  31. arg := &config.ActionArgument{
  32. Name: "host",
  33. Type: "ascii_identifier",
  34. Default: "example.com",
  35. }
  36. assert.Nil(t, validateArgumentDefault(action, arg))
  37. }