info_test.go 570 B

123456789101112131415161718192021222324252627282930313233343536
  1. package lxc
  2. import (
  3. "testing"
  4. )
  5. func TestParseRunningInfo(t *testing.T) {
  6. raw := `
  7. state: RUNNING
  8. pid: 50`
  9. info, err := parseLxcInfo(raw)
  10. if err != nil {
  11. t.Fatal(err)
  12. }
  13. if !info.Running {
  14. t.Fatal("info should return a running state")
  15. }
  16. if info.Pid != 50 {
  17. t.Fatalf("info should have pid 50 got %d", info.Pid)
  18. }
  19. }
  20. func TestEmptyInfo(t *testing.T) {
  21. _, err := parseLxcInfo("")
  22. if err == nil {
  23. t.Fatal("error should not be nil")
  24. }
  25. }
  26. func TestBadInfo(t *testing.T) {
  27. _, err := parseLxcInfo("state")
  28. if err != nil {
  29. t.Fatal(err)
  30. }
  31. }