github.com/ghodss/etcd@v0.3.1-0.20140417172404-cc329bfa55cb/tests/functional/version_check_test.go (about)

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