handler_test.go 818 B

1234567891011121314151617181920212223242526272829303132
  1. package webhooks
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. config "github.com/OliveTin/OliveTin/internal/config"
  6. )
  7. func TestFilterToDefinedArguments(t *testing.T) {
  8. action := &config.Action{
  9. Arguments: []config.ActionArgument{
  10. {Name: "repo", Type: "ascii_identifier"},
  11. {Name: "branch", Type: "ascii_identifier"},
  12. },
  13. }
  14. args := map[string]string{
  15. "repo": "my-repo",
  16. "branch": "main",
  17. "webhook_path": "/deploy/prod",
  18. "webhook_header_x_custom": "malicious",
  19. }
  20. filtered := filterToDefinedArguments(args, action)
  21. assert.Equal(t, "my-repo", filtered["repo"])
  22. assert.Equal(t, "main", filtered["branch"])
  23. assert.Empty(t, filtered["webhook_path"])
  24. assert.Empty(t, filtered["webhook_header_x_custom"])
  25. assert.Len(t, filtered, 2)
  26. }