github.com/macb/etcd@v0.3.1-0.20140227003422-a60481c6b1a0/tests/functional/internal_version_test.go (about) 1 package test 2 3 import ( 4 "fmt" 5 "net/http" 6 "net/http/httptest" 7 "net/url" 8 "os" 9 "testing" 10 "time" 11 ) 12 13 // Ensure that etcd does not come up if the internal raft versions do not match. 14 func TestInternalVersion(t *testing.T) { 15 checkedVersion := false 16 testMux := http.NewServeMux() 17 18 testMux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) { 19 fmt.Fprintln(w, "This is not a version number") 20 checkedVersion = true 21 }) 22 23 testMux.HandleFunc("/join", func(w http.ResponseWriter, r *http.Request) { 24 t.Fatal("should not attempt to join!") 25 }) 26 27 ts := httptest.NewServer(testMux) 28 defer ts.Close() 29 30 fakeURL, _ := url.Parse(ts.URL) 31 32 procAttr := new(os.ProcAttr) 33 procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr} 34 args := []string{"etcd", "-name=node1", "-f", "-data-dir=/tmp/node1", "-peers=" + fakeURL.Host} 35 36 process, err := os.StartProcess(EtcdBinPath, args, procAttr) 37 if err != nil { 38 t.Fatal("start process failed:" + err.Error()) 39 return 40 } 41 42 time.Sleep(time.Second) 43 process.Kill() 44 45 _, err = http.Get("http://127.0.0.1:4001") 46 if err == nil { 47 t.Fatal("etcd node should not be up") 48 return 49 } 50 51 if checkedVersion == false { 52 t.Fatal("etcd did not check the version") 53 return 54 } 55 }