You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
788 B

  1. package topology
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. func TestLoadConfiguration(t *testing.T) {
  7. confContent := `
  8. <?xml version="1.0" encoding="UTF-8" ?>
  9. <Configuration>
  10. <Topology>
  11. <DataCenter name="dc1">
  12. <Rack name="rack1">
  13. <Ip>192.168.1.1</Ip>
  14. </Rack>
  15. </DataCenter>
  16. <DataCenter name="dc2">
  17. <Rack name="rack1">
  18. <Ip>192.168.1.2</Ip>
  19. </Rack>
  20. <Rack name="rack2">
  21. <Ip>192.168.1.3</Ip>
  22. <Ip>192.168.1.4</Ip>
  23. </Rack>
  24. </DataCenter>
  25. </Topology>
  26. </Configuration>
  27. `
  28. c, err := NewConfiguration([]byte(confContent))
  29. fmt.Printf("%s\n", c)
  30. if err != nil {
  31. t.Fatalf("unmarshal error:%v", err)
  32. }
  33. if len(c.Topo.DataCenters) <= 0 || c.Topo.DataCenters[0].Name != "dc1" {
  34. t.Fatalf("unmarshal error:%s", c)
  35. }
  36. }