etcd_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2015 CoreOS, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package system
  15. import (
  16. "reflect"
  17. "testing"
  18. "github.com/rancher/os/config/cloudinit/config"
  19. )
  20. func TestEtcdUnits(t *testing.T) {
  21. for _, tt := range []struct {
  22. config config.Etcd
  23. units []Unit
  24. }{
  25. {
  26. config.Etcd{},
  27. []Unit{{config.Unit{
  28. Name: "etcd.service",
  29. Runtime: true,
  30. DropIns: []config.UnitDropIn{{Name: "20-cloudinit.conf"}},
  31. }}},
  32. },
  33. {
  34. config.Etcd{
  35. Discovery: "http://disco.example.com/foobar",
  36. PeerBindAddr: "127.0.0.1:7002",
  37. },
  38. []Unit{{config.Unit{
  39. Name: "etcd.service",
  40. Runtime: true,
  41. DropIns: []config.UnitDropIn{{
  42. Name: "20-cloudinit.conf",
  43. Content: `[Service]
  44. Environment="ETCD_DISCOVERY=http://disco.example.com/foobar"
  45. Environment="ETCD_PEER_BIND_ADDR=127.0.0.1:7002"
  46. `,
  47. }},
  48. }}},
  49. },
  50. {
  51. config.Etcd{
  52. Name: "node001",
  53. Discovery: "http://disco.example.com/foobar",
  54. PeerBindAddr: "127.0.0.1:7002",
  55. },
  56. []Unit{{config.Unit{
  57. Name: "etcd.service",
  58. Runtime: true,
  59. DropIns: []config.UnitDropIn{{
  60. Name: "20-cloudinit.conf",
  61. Content: `[Service]
  62. Environment="ETCD_DISCOVERY=http://disco.example.com/foobar"
  63. Environment="ETCD_NAME=node001"
  64. Environment="ETCD_PEER_BIND_ADDR=127.0.0.1:7002"
  65. `,
  66. }},
  67. }}},
  68. },
  69. } {
  70. units := Etcd{tt.config}.Units()
  71. if !reflect.DeepEqual(tt.units, units) {
  72. t.Errorf("bad units (%+v): want %#v, got %#v", tt.config, tt.units, units)
  73. }
  74. }
  75. }