A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/github/vulcanizer/commit/102f5bf0223f1a9de18f44d06a51c8d49f2ff96c below:

Merge pull request #97 from github/hugodorea/add-cluster-allocation-e… · github/vulcanizer@102f5bf · GitHub

@@ -20,6 +20,7 @@ import (

20 20

type ServerSetup struct {

21 21

Method, Path, Body, Response string

22 22

HTTPStatus int

23 +

extraChecksFn func(t *testing.T, r *http.Request)

23 24

}

24 25 25 26

func buildTestServer(t *testing.T, setups []*ServerSetup, tls bool) *httptest.Server {

@@ -29,10 +30,14 @@ func buildTestServer(t *testing.T, setups []*ServerSetup, tls bool) *httptest.Se

29 30 30 31

matched := false

31 32

for _, setup := range setups {

33 +

if setup.extraChecksFn != nil {

34 +

setup.extraChecksFn(t, r)

35 +

}

32 36

// Extra piece of debug incase there's a typo in your test's response, like a rogue space somewhere

33 37

if r.Method == setup.Method && r.URL.EscapedPath() == setup.Path && requestBody != setup.Body {

34 -

t.Errorf("request body not matching: %s != %s", requestBody, setup.Body)

38 +

t.Fatalf("request body not matching: %s != %s", requestBody, setup.Body)

35 39

}

40 + 36 41

if r.Method == setup.Method && r.URL.EscapedPath() == setup.Path && requestBody == setup.Body {

37 42

matched = true

38 43

if setup.HTTPStatus == 0 {

@@ -2096,3 +2101,80 @@ func TestGetNodesHotThreads(t *testing.T) {

2096 2101

t.Errorf("Unexpected response. got %v want %v", hotThreads, testSetup.Response)

2097 2102

}

2098 2103

}

2104 + 2105 +

func TestClusterAllocationExplain(t *testing.T) {

2106 +

tests := []struct {

2107 +

name string

2108 +

request *ClusterAllocationExplainRequest

2109 +

prettyOutput bool

2110 +

expectedBody string

2111 +

}{

2112 +

{

2113 +

name: "with nil request",

2114 +

request: nil,

2115 +

expectedBody: "",

2116 +

},

2117 +

{

2118 +

name: "with current_node set",

2119 +

request: &ClusterAllocationExplainRequest{

2120 +

CurrentNode: "test-node",

2121 +

},

2122 +

expectedBody: `{"current_node":"test-node"}`,

2123 +

},

2124 +

{

2125 +

name: "with index set",

2126 +

request: &ClusterAllocationExplainRequest{

2127 +

Index: "test-index",

2128 +

},

2129 +

expectedBody: `{"index":"test-index"}`,

2130 +

},

2131 +

{

2132 +

name: "with primary set",

2133 +

request: &ClusterAllocationExplainRequest{

2134 +

Primary: true,

2135 +

},

2136 +

expectedBody: `{"primary":true}`,

2137 +

},

2138 +

{

2139 +

name: "with shard set",

2140 +

request: &ClusterAllocationExplainRequest{

2141 +

Shard: "test-shard",

2142 +

},

2143 +

expectedBody: `{"shard":"test-shard"}`,

2144 +

},

2145 +

{

2146 +

name: "with pretty output",

2147 +

request: nil,

2148 +

prettyOutput: true,

2149 +

},

2150 +

}

2151 + 2152 +

for _, tt := range tests {

2153 +

tc := tt

2154 +

t.Run(tc.name, func(t *testing.T) {

2155 +

testSetup := &ServerSetup{

2156 +

Method: "GET",

2157 +

Path: "/_cluster/allocation/explain",

2158 +

Body: tc.expectedBody,

2159 +

}

2160 + 2161 +

if tc.prettyOutput {

2162 +

testSetup.extraChecksFn = func(t *testing.T, r *http.Request) {

2163 +

expectedURL := "/_cluster/allocation/explain?pretty="

2164 +

if r.URL.String() != expectedURL {

2165 +

t.Errorf("Unexpected url query. Want %s, got %s", expectedURL, r.URL.String())

2166 +

}

2167 +

}

2168 +

}

2169 + 2170 +

host, port, ts := setupTestServers(t, []*ServerSetup{testSetup})

2171 +

defer ts.Close()

2172 +

client := NewClient(host, port)

2173 + 2174 +

_, err := client.ClusterAllocationExplain(tc.request, tc.prettyOutput)

2175 +

if err != nil {

2176 +

t.Fatalf("Unexpected error. expected nil, got %s", err)

2177 +

}

2178 +

})

2179 +

}

2180 +

}


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4