server_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. Copyright 2019 The Kubernetes Authors.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package app
  14. import (
  15. "testing"
  16. )
  17. func TestGetServiceIPAndRanges(t *testing.T) {
  18. tests := []struct {
  19. body string
  20. apiServerServiceIP string
  21. primaryServiceIPRange string
  22. secondaryServiceIPRange string
  23. expectedError bool
  24. }{
  25. {"", "10.0.0.1", "10.0.0.0/24", "<nil>", false},
  26. {"192.0.2.1/24", "192.0.2.1", "192.0.2.0/24", "<nil>", false},
  27. {"192.0.2.1/24,192.168.128.0/17", "192.0.2.1", "192.0.2.0/24", "192.168.128.0/17", false},
  28. {"192.0.2.1/30,192.168.128.0/17", "<nil>", "<nil>", "<nil>", true},
  29. }
  30. for _, test := range tests {
  31. apiServerServiceIP, primaryServiceIPRange, secondaryServiceIPRange, err := getServiceIPAndRanges(test.body)
  32. if apiServerServiceIP.String() != test.apiServerServiceIP {
  33. t.Errorf("expected apiServerServiceIP: %s, got: %s", test.apiServerServiceIP, apiServerServiceIP.String())
  34. }
  35. if primaryServiceIPRange.String() != test.primaryServiceIPRange {
  36. t.Errorf("expected primaryServiceIPRange: %s, got: %s", test.primaryServiceIPRange, primaryServiceIPRange.String())
  37. }
  38. if secondaryServiceIPRange.String() != test.secondaryServiceIPRange {
  39. t.Errorf("expected secondaryServiceIPRange: %s, got: %s", test.secondaryServiceIPRange, secondaryServiceIPRange.String())
  40. }
  41. if (err == nil) == test.expectedError {
  42. t.Errorf("expected err to be: %t, but it was %t", test.expectedError, !test.expectedError)
  43. }
  44. }
  45. }