v1_migration_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package test
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "os"
  6. "os/exec"
  7. "path/filepath"
  8. "testing"
  9. "time"
  10. "github.com/coreos/etcd/tests"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. // Ensure that we can start a v2 node from the log of a v1 node.
  14. func TestV1Migration(t *testing.T) {
  15. path, _ := ioutil.TempDir("", "etcd-")
  16. os.RemoveAll(path)
  17. defer os.RemoveAll(path)
  18. nodes := []string{"node0", "node1"}
  19. for i, node := range nodes {
  20. nodepath := filepath.Join(path, node)
  21. // Copy over fixture files.
  22. if err := exec.Command("cp", "-r", "../fixtures/v1/" + node, nodepath).Run(); err != nil {
  23. panic("Fixture initialization error")
  24. }
  25. procAttr := new(os.ProcAttr)
  26. procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
  27. args := []string{"etcd", fmt.Sprintf("-d=%s", nodepath)}
  28. args = append(args, "-c", fmt.Sprintf("127.0.0.1:%d", 4001 + i))
  29. args = append(args, "-s", fmt.Sprintf("127.0.0.1:%d", 7001 + i))
  30. process, err := os.StartProcess(EtcdBinPath, args, procAttr)
  31. if err != nil {
  32. t.Fatal("start process failed:" + err.Error())
  33. return
  34. }
  35. defer process.Kill()
  36. time.Sleep(time.Second)
  37. }
  38. // Ensure deleted message is removed.
  39. resp, err := tests.Get("http://localhost:4001/v2/keys/message")
  40. tests.ReadBody(resp)
  41. assert.Nil(t, err, "")
  42. assert.Equal(t, resp.StatusCode, 404, "")
  43. // Ensure TTL'd message is removed.
  44. resp, err = tests.Get("http://localhost:4001/v2/keys/foo")
  45. tests.ReadBody(resp)
  46. assert.Nil(t, err, "")
  47. assert.Equal(t, resp.StatusCode, 404, "")
  48. }