config_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package client_test
  2. import (
  3. "github.com/stretchr/testify/require"
  4. "heckel.io/ntfy/client"
  5. "os"
  6. "path/filepath"
  7. "testing"
  8. )
  9. func TestConfig_Load(t *testing.T) {
  10. filename := filepath.Join(t.TempDir(), "client.yml")
  11. require.Nil(t, os.WriteFile(filename, []byte(`
  12. default-host: http://localhost
  13. subscribe:
  14. - topic: no-command-with-auth
  15. user: phil
  16. password: mypass
  17. - topic: echo-this
  18. command: 'echo "Message received: $message"'
  19. - topic: alerts
  20. command: notify-send -i /usr/share/ntfy/logo.png "Important" "$m"
  21. if:
  22. priority: high,urgent
  23. `), 0600))
  24. conf, err := client.LoadConfig(filename)
  25. require.Nil(t, err)
  26. require.Equal(t, "http://localhost", conf.DefaultHost)
  27. require.Equal(t, 3, len(conf.Subscribe))
  28. require.Equal(t, "no-command-with-auth", conf.Subscribe[0].Topic)
  29. require.Equal(t, "", conf.Subscribe[0].Command)
  30. require.Equal(t, "phil", conf.Subscribe[0].User)
  31. require.Equal(t, "mypass", conf.Subscribe[0].Password)
  32. require.Equal(t, "echo-this", conf.Subscribe[1].Topic)
  33. require.Equal(t, `echo "Message received: $message"`, conf.Subscribe[1].Command)
  34. require.Equal(t, "alerts", conf.Subscribe[2].Topic)
  35. require.Equal(t, `notify-send -i /usr/share/ntfy/logo.png "Important" "$m"`, conf.Subscribe[2].Command)
  36. require.Equal(t, "high,urgent", conf.Subscribe[2].If["priority"])
  37. }