config_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2015 flannel authors
  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 subnet
  15. import (
  16. "testing"
  17. )
  18. func TestConfigDefaults(t *testing.T) {
  19. s := `{ "network": "10.3.0.0/16" }`
  20. cfg, err := ParseConfig(s)
  21. if err != nil {
  22. t.Fatalf("ParseConfig failed: %s", err)
  23. }
  24. expectedNet := "10.3.0.0/16"
  25. if cfg.Network.String() != expectedNet {
  26. t.Errorf("Network mismatch: expected %s, got %s", expectedNet, cfg.Network)
  27. }
  28. if cfg.SubnetMin.String() != "10.3.1.0" {
  29. t.Errorf("SubnetMin mismatch, expected 10.3.1.0, got %s", cfg.SubnetMin)
  30. }
  31. if cfg.SubnetMax.String() != "10.3.255.0" {
  32. t.Errorf("SubnetMax mismatch, expected 10.3.255.0, got %s", cfg.SubnetMax)
  33. }
  34. if cfg.SubnetLen != 24 {
  35. t.Errorf("SubnetLen mismatch: expected 24, got %d", cfg.SubnetLen)
  36. }
  37. }
  38. func TestConfigOverrides(t *testing.T) {
  39. s := `{ "Network": "10.3.0.0/16", "SubnetMin": "10.3.5.0", "SubnetMax": "10.3.8.0", "SubnetLen": 28 }`
  40. cfg, err := ParseConfig(s)
  41. if err != nil {
  42. t.Fatalf("ParseConfig failed: %s", err)
  43. }
  44. expectedNet := "10.3.0.0/16"
  45. if cfg.Network.String() != expectedNet {
  46. t.Errorf("Network mismatch: expected %s, got %s", expectedNet, cfg.Network)
  47. }
  48. if cfg.SubnetMin.String() != "10.3.5.0" {
  49. t.Errorf("SubnetMin mismatch: expected 10.3.5.0, got %s", cfg.SubnetMin)
  50. }
  51. if cfg.SubnetMax.String() != "10.3.8.0" {
  52. t.Errorf("SubnetMax mismatch: expected 10.3.8.0, got %s", cfg.SubnetMax)
  53. }
  54. if cfg.SubnetLen != 28 {
  55. t.Errorf("SubnetLen mismatch: expected 28, got %d", cfg.SubnetLen)
  56. }
  57. }