config_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package discov
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestConfig(t *testing.T) {
  7. tests := []struct {
  8. EtcdConf
  9. pass bool
  10. }{
  11. {
  12. EtcdConf: EtcdConf{},
  13. pass: false,
  14. },
  15. {
  16. EtcdConf: EtcdConf{
  17. Key: "any",
  18. },
  19. pass: false,
  20. },
  21. {
  22. EtcdConf: EtcdConf{
  23. Hosts: []string{"any"},
  24. },
  25. pass: false,
  26. },
  27. {
  28. EtcdConf: EtcdConf{
  29. Hosts: []string{"any"},
  30. Key: "key",
  31. },
  32. pass: true,
  33. },
  34. }
  35. for _, test := range tests {
  36. if test.pass {
  37. assert.Nil(t, test.EtcdConf.Validate())
  38. } else {
  39. assert.NotNil(t, test.EtcdConf.Validate())
  40. }
  41. }
  42. }
  43. func TestEtcdConf_HasAccount(t *testing.T) {
  44. tests := []struct {
  45. EtcdConf
  46. hasAccount bool
  47. }{
  48. {
  49. EtcdConf: EtcdConf{
  50. Hosts: []string{"any"},
  51. Key: "key",
  52. },
  53. hasAccount: false,
  54. },
  55. {
  56. EtcdConf: EtcdConf{
  57. Hosts: []string{"any"},
  58. Key: "key",
  59. User: "foo",
  60. },
  61. hasAccount: false,
  62. },
  63. {
  64. EtcdConf: EtcdConf{
  65. Hosts: []string{"any"},
  66. Key: "key",
  67. User: "foo",
  68. Pass: "bar",
  69. },
  70. hasAccount: true,
  71. },
  72. }
  73. for _, test := range tests {
  74. assert.Equal(t, test.hasAccount, test.EtcdConf.HasAccount())
  75. }
  76. }