(t *testing.T)
| 26 | ) |
| 27 | |
| 28 | func TestSearchV1(t *testing.T) { |
| 29 | indexName := "TestSearchV1.index_1" |
| 30 | type args struct { |
| 31 | code int |
| 32 | data string |
| 33 | params map[string]string |
| 34 | result string |
| 35 | } |
| 36 | tests := []struct { |
| 37 | name string |
| 38 | args args |
| 39 | }{ |
| 40 | { |
| 41 | name: "normal", |
| 42 | args: args{ |
| 43 | code: http.StatusOK, |
| 44 | data: `{"query_type":"match_all","max_results":10}`, |
| 45 | params: map[string]string{"target": indexName}, |
| 46 | result: "{\"total\":", |
| 47 | }, |
| 48 | }, |
| 49 | { |
| 50 | name: "index not found", |
| 51 | args: args{ |
| 52 | code: http.StatusBadRequest, |
| 53 | data: `{"query_type":"match_all","max_results":10}`, |
| 54 | params: map[string]string{"target": "NotExist" + indexName}, |
| 55 | result: "does not exists", |
| 56 | }, |
| 57 | }, |
| 58 | { |
| 59 | name: "query jsone error", |
| 60 | args: args{ |
| 61 | code: http.StatusBadRequest, |
| 62 | data: `{"query_type":"match_all","max_results":10,{x}}`, |
| 63 | params: map[string]string{"target": indexName}, |
| 64 | result: "invalid character", |
| 65 | }, |
| 66 | }, |
| 67 | } |
| 68 | |
| 69 | t.Run("prepare", func(t *testing.T) { |
| 70 | index, err := core.NewIndex(indexName, "disk", 2) |
| 71 | assert.NoError(t, err) |
| 72 | assert.NotNil(t, index) |
| 73 | err = core.StoreIndex(index) |
| 74 | assert.NoError(t, err) |
| 75 | }) |
| 76 | |
| 77 | for _, tt := range tests { |
| 78 | t.Run(tt.name, func(t *testing.T) { |
| 79 | c, w := utils.NewGinContext() |
| 80 | utils.SetGinRequestData(c, tt.args.data) |
| 81 | utils.SetGinRequestParams(c, tt.args.params) |
| 82 | SearchV1(c) |
| 83 | assert.Equal(t, tt.args.code, w.Code) |
| 84 | assert.Contains(t, w.Body.String(), tt.args.result) |
| 85 | }) |
nothing calls this directly
no test coverage detected