@@ -50,19 +50,20 @@ func Test_sendResourceResponse(t *testing.T) {
5050}
5151
5252type fakeCompletable struct {
53- tables []string
5453 schemas []string
54+ tables map [string ][]string
5555 columns map [string ][]string
5656 err error
5757}
5858
59- func (f * fakeCompletable ) Tables (ctx context.Context ) ([]string , error ) {
60- return f .tables , f .err
61- }
6259func (f * fakeCompletable ) Schemas (ctx context.Context ) ([]string , error ) {
6360 return f .schemas , f .err
61+ }
6462
63+ func (f * fakeCompletable ) Tables (ctx context.Context , schema string ) ([]string , error ) {
64+ return f .tables [schema ], f .err
6565}
66+
6667func (f * fakeCompletable ) Columns (ctx context.Context , table string ) ([]string , error ) {
6768 return f .columns [table ], f .err
6869}
@@ -75,20 +76,20 @@ func TestCompletable(t *testing.T) {
7576 reqBody string
7677 expectedRes string
7778 }{
78- {
79- "it should return tables" ,
80- "tables" ,
81- & fakeCompletable {tables : []string {"foo" , "bar" }},
82- "" ,
83- `["foo","bar"]` + "\n " ,
84- },
8579 {
8680 "it should return schemas" ,
8781 "schemas" ,
8882 & fakeCompletable {schemas : []string {"foo" , "bar" }},
8983 "" ,
9084 `["foo","bar"]` + "\n " ,
9185 },
86+ {
87+ "it should return tables of a schema" ,
88+ "tables" ,
89+ & fakeCompletable {tables : map [string ][]string {"foobar" : {"foo" , "bar" }}},
90+ `{"schema":"foobar"}` ,
91+ `["foo","bar"]` + "\n " ,
92+ },
9293 {
9394 "it should return columns of a table" ,
9495 "columns" ,
@@ -104,13 +105,15 @@ func TestCompletable(t *testing.T) {
104105 sqlds := & sqldatasource {}
105106 sqlds .Completable = test .fakeImpl
106107
108+ b := ioutil .NopCloser (bytes .NewReader ([]byte (test .reqBody )))
107109 switch test .method {
108- case "tables" :
109- sqlds .getTables (w , & http.Request {})
110110 case "schemas" :
111111 sqlds .getSchemas (w , & http.Request {})
112+ case "tables" :
113+ sqlds .getTables (w , & http.Request {
114+ Body : b ,
115+ })
112116 case "columns" :
113- b := ioutil .NopCloser (bytes .NewReader ([]byte (test .reqBody )))
114117 sqlds .getColumns (w , & http.Request {
115118 Body : b ,
116119 })
0 commit comments