config_helpers_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package config
  2. import (
  3. "github.com/stretchr/testify/assert"
  4. "testing"
  5. )
  6. func TestFindAction(t *testing.T) {
  7. c := DefaultConfig()
  8. a1 := &Action{}
  9. a1.Title = "a1"
  10. c.Actions = append(c.Actions, a1)
  11. a2 := &Action{
  12. Title: "a2",
  13. Arguments: []ActionArgument{
  14. {
  15. Name: "Blat",
  16. },
  17. },
  18. }
  19. c.Actions = append(c.Actions, a2)
  20. assert.NotNil(t, c.FindAction("a1"), "Find action a1")
  21. assert.NotNil(t, c.FindAction("a2"), "Find action a2")
  22. assert.NotNil(t, c.FindAction("a2").FindArg("Blat"), "Find action argument")
  23. assert.Nil(t, c.FindAction("a2").FindArg("Blatey Cake"), "Find non-existent action argument")
  24. assert.Nil(t, c.FindAction("waffles"), "Find non-existent action")
  25. }
  26. func TestFindAcl(t *testing.T) {
  27. c := DefaultConfig()
  28. acl1 := &AccessControlList{
  29. Name: "Testing ACL",
  30. }
  31. c.AccessControlLists = append(c.AccessControlLists, acl1)
  32. assert.NotNil(t, c.FindAcl("Testing ACL"), "Find a ACL that should exist")
  33. assert.Nil(t, c.FindAcl("Chocolate Cake"), "Find a ACL that does not exist")
  34. }
  35. func TestSetDir(t *testing.T) {
  36. c := DefaultConfig()
  37. c.SetDir("test")
  38. assert.Equal(t, "test", c.GetDir(), "SetDir")
  39. }