flannel_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 TestFlannelEnvVars(t *testing.T) {
  21. for _, tt := range []struct {
  22. config config.Flannel
  23. contents string
  24. }{
  25. {
  26. config.Flannel{},
  27. "",
  28. },
  29. {
  30. config.Flannel{
  31. EtcdEndpoints: "http://12.34.56.78:4001",
  32. EtcdPrefix: "/coreos.com/network/tenant1",
  33. },
  34. `FLANNELD_ETCD_ENDPOINTS=http://12.34.56.78:4001
  35. FLANNELD_ETCD_PREFIX=/coreos.com/network/tenant1`,
  36. },
  37. } {
  38. out := Flannel{tt.config}.envVars()
  39. if out != tt.contents {
  40. t.Errorf("bad contents (%+v): want %q, got %q", tt, tt.contents, out)
  41. }
  42. }
  43. }
  44. func TestFlannelFile(t *testing.T) {
  45. for _, tt := range []struct {
  46. config config.Flannel
  47. file *File
  48. }{
  49. {
  50. config.Flannel{},
  51. nil,
  52. },
  53. {
  54. config.Flannel{
  55. EtcdEndpoints: "http://12.34.56.78:4001",
  56. EtcdPrefix: "/coreos.com/network/tenant1",
  57. },
  58. &File{config.File{
  59. Path: "run/flannel/options.env",
  60. RawFilePermissions: "0644",
  61. Content: `FLANNELD_ETCD_ENDPOINTS=http://12.34.56.78:4001
  62. FLANNELD_ETCD_PREFIX=/coreos.com/network/tenant1`,
  63. }},
  64. },
  65. } {
  66. file, _ := Flannel{tt.config}.File()
  67. if !reflect.DeepEqual(tt.file, file) {
  68. t.Errorf("bad units (%q): want %#v, got %#v", tt.config, tt.file, file)
  69. }
  70. }
  71. }