version_check_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package test
  2. import (
  3. "net/http"
  4. "os"
  5. "testing"
  6. "time"
  7. )
  8. // Ensure that a node can reply to a version check appropriately.
  9. func TestVersionCheck(t *testing.T) {
  10. procAttr := new(os.ProcAttr)
  11. procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
  12. args := []string{"etcd", "-name=node1", "-f", "-data-dir=/tmp/version_check"}
  13. process, err := os.StartProcess(EtcdBinPath, args, procAttr)
  14. if err != nil {
  15. t.Fatal("start process failed:" + err.Error())
  16. return
  17. }
  18. defer process.Kill()
  19. time.Sleep(time.Second)
  20. // Check a version too small.
  21. resp, _ := http.Get("http://localhost:7001/version/1/check")
  22. resp.Body.Close()
  23. if resp.StatusCode != http.StatusForbidden {
  24. t.Fatal("Invalid version check: ", resp.StatusCode)
  25. }
  26. // Check a version too large.
  27. resp, _ = http.Get("http://localhost:7001/version/3/check")
  28. resp.Body.Close()
  29. if resp.StatusCode != http.StatusForbidden {
  30. t.Fatal("Invalid version check: ", resp.StatusCode)
  31. }
  32. // Check a version that's just right.
  33. resp, _ = http.Get("http://localhost:7001/version/2/check")
  34. resp.Body.Close()
  35. if resp.StatusCode != http.StatusOK {
  36. t.Fatal("Invalid version check: ", resp.StatusCode)
  37. }
  38. }