(t *testing.T)
| 100 | } |
| 101 | |
| 102 | func TestMultipleSearch(t *testing.T) { |
| 103 | indexName := "TestMultipleSearch.index_1" |
| 104 | type args struct { |
| 105 | code int |
| 106 | data string |
| 107 | params map[string]string |
| 108 | result string |
| 109 | } |
| 110 | tests := []struct { |
| 111 | name string |
| 112 | args args |
| 113 | }{ |
| 114 | { |
| 115 | name: "normal", |
| 116 | args: args{ |
| 117 | code: http.StatusOK, |
| 118 | data: `{"index":"` + indexName + `"} |
| 119 | {"query":{"match_all":{}},"size":10}`, |
| 120 | params: map[string]string{"target": indexName}, |
| 121 | result: "successful", |
| 122 | }, |
| 123 | }, |
| 124 | { |
| 125 | name: "multiple index", |
| 126 | args: args{ |
| 127 | code: http.StatusOK, |
| 128 | data: `{"index":["` + indexName + `"]} |
| 129 | {"query":{"match_all":{}},"size":10}`, |
| 130 | result: "successful", |
| 131 | }, |
| 132 | }, |
| 133 | { |
| 134 | name: "not exists", |
| 135 | args: args{ |
| 136 | code: http.StatusOK, |
| 137 | data: `{"index":"TestMultipleSearch.notExists"} |
| 138 | {"query":{"match_all":{}},"size":10}`, |
| 139 | result: "does not exists", |
| 140 | }, |
| 141 | }, |
| 142 | } |
| 143 | |
| 144 | t.Run("prepare", func(t *testing.T) { |
| 145 | index, err := core.NewIndex(indexName, "disk", 2) |
| 146 | assert.NoError(t, err) |
| 147 | assert.NotNil(t, index) |
| 148 | err = core.StoreIndex(index) |
| 149 | assert.NoError(t, err) |
| 150 | }) |
| 151 | |
| 152 | for _, tt := range tests { |
| 153 | t.Run(tt.name, func(t *testing.T) { |
| 154 | c, w := utils.NewGinContext() |
| 155 | utils.SetGinRequestData(c, tt.args.data) |
| 156 | utils.SetGinRequestParams(c, tt.args.params) |
| 157 | MultipleSearch(c) |
| 158 | assert.Equal(t, tt.args.code, w.Code) |
| 159 | assert.Contains(t, w.Body.String(), tt.args.result) |
nothing calls this directly
no test coverage detected