debian_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 network
  15. import (
  16. "testing"
  17. )
  18. func TestFormatConfigs(t *testing.T) {
  19. for in, n := range map[string]int{
  20. "": 0,
  21. "line1\\\nis long": 1,
  22. "#comment": 0,
  23. "#comment\\\ncomment": 0,
  24. " #comment \\\n comment\nline 1\nline 2\\\n is long": 2,
  25. } {
  26. lines := formatConfig(in)
  27. if len(lines) != n {
  28. t.Fatalf("bad number of lines for config %q: got %d, want %d", in, len(lines), n)
  29. }
  30. }
  31. }
  32. func TestProcessDebianNetconf(t *testing.T) {
  33. for _, tt := range []struct {
  34. in string
  35. fail bool
  36. n int
  37. }{
  38. {"", false, 0},
  39. {"iface", true, -1},
  40. {"auto eth1\nauto eth2", false, 0},
  41. {"iface eth1 inet manual", false, 1},
  42. } {
  43. interfaces, err := ProcessDebianNetconf([]byte(tt.in))
  44. failed := err != nil
  45. if tt.fail != failed {
  46. t.Fatalf("bad failure state for %q: got %t, want %t", tt.in, failed, tt.fail)
  47. }
  48. if tt.n != -1 && tt.n != len(interfaces) {
  49. t.Fatalf("bad number of interfaces for %q: got %d, want %q", tt.in, len(interfaces), tt.n)
  50. }
  51. }
  52. }