Skip to content

Commit ae2fbab

Browse files
committed
Update backend tests to gitbase 0.18
Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
1 parent 516389a commit ae2fbab

4 files changed

Lines changed: 193 additions & 10 deletions

File tree

server/handler/query_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import (
1010
"testing"
1111
"time"
1212

13-
"github.com/src-d/gitbase-web/server/service"
1413
common "github.com/src-d/gitbase-web/server/testing"
1514

1615
"github.com/pressly/lg"
1716
"github.com/stretchr/testify/assert"
1817
"github.com/stretchr/testify/suite"
1918
"gopkg.in/DATA-DOG/go-sqlmock.v1"
19+
"gopkg.in/bblfsh/sdk.v2/uast/nodes"
2020
)
2121

2222
type QuerySuite struct {
@@ -190,7 +190,7 @@ func (suite *QuerySuite) TestUASTType() {
190190
suite.EqualValues("", colData["uast_a"])
191191
suite.Nil(colData["__uast_a-protobufs"])
192192

193-
var nodeArr []*service.Node
193+
var nodeArr nodes.Array
194194
suite.IsType(nodeArr, colData["uast_b"])
195195
suite.EqualValues(common.UASTMarshaled, colData["__uast_b-protobufs"])
196196
}

server/handler/query_uast_integration_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func (suite *QueryUast) TestUastFunctions() {
5151
var jsonObj map[string]interface{}
5252
suite.IsType(jsonObj, uasts[0])
5353

54-
// check that roles were converted correctly
54+
// check that root node roles were converted correctly
5555
uast := uasts[0].(map[string]interface{})
56-
roles := uast["Roles"].([]interface{})
57-
suite.Equal("File", roles[1].(string))
56+
roles := uast["@role"].([]interface{})
57+
suite.Equal("File", roles[0].(string))
5858
}

server/handler/uast_integration_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (suite *UASTParseSuite) TestSuccess() {
4949
}
5050

5151
func (suite *UASTParseSuite) TestError() {
52-
jsonRequest := `{ "content": "function() { not_python = 1 }", "language": "python" }`
52+
jsonRequest := `{ "content": "function(} ][", "language": "javascript" }`
5353
req, _ := http.NewRequest("POST", "/parse", strings.NewReader(jsonRequest))
5454

5555
res := httptest.NewRecorder()
@@ -109,4 +109,5 @@ func (suite *UASTFilterSuite) TestFilterError() {
109109

110110
// JSON: [<UAST(console.log("test"))>]
111111
// Easy to obtain in the frontend with SELECT UAST('console.log("test")', 'JavaScript') AS uast
112-
const uastProtoMsgBase64List = "AAACFgoERmlsZRr8AwoHUHJvZ3JhbRIXCgxpbnRlcm5hbFJvbGUSB3Byb2dyYW0SFAoKc291cmNlVHlwZRIGbW9kdWxlGrADChNFeHByZXNzaW9uU3RhdGVtZW50EhQKDGludGVybmFsUm9sZRIEYm9keRrxAgoOQ2FsbEV4cHJlc3Npb24SGgoMaW50ZXJuYWxSb2xlEgpleHByZXNzaW9uGtwBChBNZW1iZXJFeHByZXNzaW9uEhYKDGludGVybmFsUm9sZRIGY2FsbGVlEhEKCGNvbXB1dGVkEgVmYWxzZRpDCgpJZGVudGlmaWVyEg8KBE5hbWUSB2NvbnNvbGUSFgoMaW50ZXJuYWxSb2xlEgZvYmplY3QqBBABGAEyBggHEAEYCBpDCgpJZGVudGlmaWVyEhgKDGludGVybmFsUm9sZRIIcHJvcGVydHkSCwoETmFtZRIDbG9nKgYICBABGAkyBggLEAEYDCoEEAEYATIGCAsQARgMOgUCEgFUVRpSCgZTdHJpbmcSGQoMaW50ZXJuYWxSb2xlEglhcmd1bWVudHMSCgoGRm9ybWF0EgASDQoFVmFsdWUSBHRlc3QqBggMEAEYDTIGCBIQARgTOgJUMSoEEAEYATIGCBMQARgUOgISVCoEEAEYATIGCBMQARgUOgETKgQQARgBMgYIExABGBQ6ATkqBBABGAEyBggTEAEYFDoBIg=="
112+
// Gitbase v0.18.0-beta.1, Bblfsh v2.9.2-drivers
113+
const uastProtoMsgBase64List = "AGJncgEAAAAECFcQAQNCAQIOOgUDBAUGB0IFCBYXGBkGEgRAcG9zBxIFQHJvbGUHEgVAdHlwZQoSCGNvbW1lbnRzCRIHcHJvZ3JhbQo6AwUJCkIDCwwUBRIDZW5kBxIFc3RhcnQQEg51YXN0OlBvc2l0aW9ucww6BAUNDg9CBBAREhMFEgNjb2wGEgRsaW5lCBIGb2Zmc2V0DxINdWFzdDpQb3NpdGlvbgIgFAIgAQIgEwhCBBASEhVQDAIgAANCARcGEgRGaWxlABA6BgMEBRobHEIGCB0fIBhWBhIEYm9keQwSCmRpcmVjdGl2ZXMMEgpzb3VyY2VUeXBlA0IBHggSBk1vZHVsZQkSB1Byb2dyYW0DQgEhDDoEAwQFIkIECCMlJgwSCmV4cHJlc3Npb24DQgEkCxIJU3RhdGVtZW50FRITRXhwcmVzc2lvblN0YXRlbWVudA46BQMEBScoQgUIKSwtPAsSCWFyZ3VtZW50cwgSBmNhbGxlZQRCAiorDBIKRXhwcmVzc2lvbgYSBENhbGwQEg5DYWxsRXhwcmVzc2lvbgNCAS4OOgUDBAUvMEIFMTc5OjsIEgZGb3JtYXQHEgVWYWx1ZQdCAwsyNFAICEIEEBMSM1AMAiASCEIEEDUSNlAMAiANAiAMBEICKzgKEghBcmd1bWVudA0SC3Vhc3Q6U3RyaW5nAhIABhIEdGVzdBA6BgMEBT0+P0IGQENHSElRChIIY29tcHV0ZWQIEgZvYmplY3QKEghwcm9wZXJ0eQdCAwtBFFAICEIEEDYSQlAMAiALB0IFRCpFK0YLEglRdWFsaWZpZWQMEgpJZGVudGlmaWVyCBIGQ2FsbGVlEhIQTWVtYmVyRXhwcmVzc2lvbgIwAAo6AwMFSkIDS09QBhIETmFtZQdCAwtMFFAICEIEEE0STlAMAiAIAiAHERIPdWFzdDpJZGVudGlmaWVyCRIHY29uc29sZQdCA1JPVVBJB0IDC0FTUAgIQgQQVBJNUAwCIAkFEgNsb2cIEgZtb2R1bGU="

server/testing/common.go

Lines changed: 185 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,190 @@ func (db *MockDB) Exec(query string, args ...interface{}) (sql.Result, error) {
3838
return nil, nil
3939
}
4040

41-
// As returned by gitbase v0.17.0-rc.4, SELECT UAST('console.log("test")', 'JavaScript') AS uast
41+
// As returned by gitbase v0.18.0-beta.1, Bblfsh v2.9.2-drivers
42+
// SELECT UAST('console.log("test")', 'JavaScript') AS uast
4243
const (
43-
UASTMarshaled = "\x00\x00\x02\x16\n\x04File\x1a\xfc\x03\n\aProgram\x12\x17\n\finternalRole\x12\aprogram\x12\x14\n\nsourceType\x12\x06module\x1a\xb0\x03\n\x13ExpressionStatement\x12\x14\n\finternalRole\x12\x04body\x1a\xf1\x02\n\x0eCallExpression\x12\x1a\n\finternalRole\x12\nexpression\x1a\xdc\x01\n\x10MemberExpression\x12\x16\n\finternalRole\x12\x06callee\x12\x11\n\bcomputed\x12\x05false\x1aC\n\nIdentifier\x12\x16\n\finternalRole\x12\x06object\x12\x0f\n\x04Name\x12\aconsole*\x04\x10\x01\x18\x012\x06\b\a\x10\x01\x18\b\x1aC\n\nIdentifier\x12\v\n\x04Name\x12\x03log\x12\x18\n\finternalRole\x12\bproperty*\x06\b\b\x10\x01\x18\t2\x06\b\v\x10\x01\x18\f*\x04\x10\x01\x18\x012\x06\b\v\x10\x01\x18\f:\x05\x02\x12\x01TU\x1aR\n\x06String\x12\r\n\x05Value\x12\x04test\x12\n\n\x06Format\x12\x00\x12\x19\n\finternalRole\x12\targuments*\x06\b\f\x10\x01\x18\r2\x06\b\x12\x10\x01\x18\x13:\x02T1*\x04\x10\x01\x18\x012\x06\b\x13\x10\x01\x18\x14:\x02\x12T*\x04\x10\x01\x18\x012\x06\b\x13\x10\x01\x18\x14:\x01\x13*\x04\x10\x01\x18\x012\x06\b\x13\x10\x01\x18\x14:\x019*\x04\x10\x01\x18\x012\x06\b\x13\x10\x01\x18\x14:\x01\""
44-
UASTMarshaledJSON = "[{\"InternalType\":\"File\",\"StartPosition\":{\"Offset\":0,\"Line\":1,\"Col\":1},\"EndPosition\":{\"Offset\":19,\"Line\":1,\"Col\":20},\"Roles\":[\"Unannotated\",\"File\"],\"Children\":[{\"InternalType\":\"Program\",\"Properties\":{\"internalRole\":\"program\",\"sourceType\":\"module\"},\"StartPosition\":{\"Offset\":0,\"Line\":1,\"Col\":1},\"EndPosition\":{\"Offset\":19,\"Line\":1,\"Col\":20},\"Roles\":[\"Module\"],\"Children\":[{\"InternalType\":\"ExpressionStatement\",\"Properties\":{\"internalRole\":\"body\"},\"StartPosition\":{\"Offset\":0,\"Line\":1,\"Col\":1},\"EndPosition\":{\"Offset\":19,\"Line\":1,\"Col\":20},\"Roles\":[\"Statement\"],\"Children\":[{\"InternalType\":\"CallExpression\",\"Properties\":{\"internalRole\":\"expression\"},\"StartPosition\":{\"Offset\":0,\"Line\":1,\"Col\":1},\"EndPosition\":{\"Offset\":19,\"Line\":1,\"Col\":20},\"Roles\":[\"Expression\",\"Call\"],\"Children\":[{\"InternalType\":\"MemberExpression\",\"Properties\":{\"computed\":\"false\",\"internalRole\":\"callee\"},\"StartPosition\":{\"Offset\":0,\"Line\":1,\"Col\":1},\"EndPosition\":{\"Offset\":11,\"Line\":1,\"Col\":12},\"Roles\":[\"Qualified\",\"Expression\",\"Identifier\",\"Call\",\"Callee\"],\"Children\":[{\"InternalType\":\"Identifier\",\"Properties\":{\"Name\":\"console\",\"internalRole\":\"object\"},\"StartPosition\":{\"Offset\":0,\"Line\":1,\"Col\":1},\"EndPosition\":{\"Offset\":7,\"Line\":1,\"Col\":8},\"Roles\":[],\"Children\":[]},{\"InternalType\":\"Identifier\",\"Properties\":{\"Name\":\"log\",\"internalRole\":\"property\"},\"StartPosition\":{\"Offset\":8,\"Line\":1,\"Col\":9},\"EndPosition\":{\"Offset\":11,\"Line\":1,\"Col\":12},\"Roles\":[],\"Children\":[]}]},{\"InternalType\":\"String\",\"Properties\":{\"Format\":\"\",\"Value\":\"test\",\"internalRole\":\"arguments\"},\"StartPosition\":{\"Offset\":12,\"Line\":1,\"Col\":13},\"EndPosition\":{\"Offset\":18,\"Line\":1,\"Col\":19},\"Roles\":[\"Call\",\"Argument\"],\"Children\":[]}]}]}]}]}]"
44+
UASTMarshaled = "\x00bgr\x01\x00\x00\x00\x04\bW\x10\x01\x03B\x01\x02\x0e:\x05\x03\x04\x05\x06\aB\x05\b\x16\x17\x18\x19\x06\x12\x04@pos\a\x12\x05@role\a\x12\x05@type\n\x12\bcomments\t\x12\aprogram\n:\x03\x05\t\nB\x03\v\f\x14\x05\x12\x03end\a\x12\x05start\x10\x12\x0euast:Positions\f:\x04\x05\r\x0e\x0fB\x04\x10\x11\x12\x13\x05\x12\x03col\x06\x12\x04line\b\x12\x06offset\x0f\x12\ruast:Position\x02 \x14\x02 \x01\x02 \x13\bB\x04\x10\x12\x12\x15P\f\x02 \x00\x03B\x01\x17\x06\x12\x04File\x00\x10:\x06\x03\x04\x05\x1a\x1b\x1cB\x06\b\x1d\x1f \x18V\x06\x12\x04body\f\x12\ndirectives\f\x12\nsourceType\x03B\x01\x1e\b\x12\x06Module\t\x12\aProgram\x03B\x01!\f:\x04\x03\x04\x05\"B\x04\b#%&\f\x12\nexpression\x03B\x01$\v\x12\tStatement\x15\x12\x13ExpressionStatement\x0e:\x05\x03\x04\x05'(B\x05\b),-<\v\x12\targuments\b\x12\x06callee\x04B\x02*+\f\x12\nExpression\x06\x12\x04Call\x10\x12\x0eCallExpression\x03B\x01.\x0e:\x05\x03\x04\x05/0B\x05179:;\b\x12\x06Format\a\x12\x05Value\aB\x03\v24P\b\bB\x04\x10\x13\x123P\f\x02 \x12\bB\x04\x105\x126P\f\x02 \r\x02 \f\x04B\x02+8\n\x12\bArgument\r\x12\vuast:String\x02\x12\x00\x06\x12\x04test\x10:\x06\x03\x04\x05=>?B\x06@CGHIQ\n\x12\bcomputed\b\x12\x06object\n\x12\bproperty\aB\x03\vA\x14P\b\bB\x04\x106\x12BP\f\x02 \v\aB\x05D*E+F\v\x12\tQualified\f\x12\nIdentifier\b\x12\x06Callee\x12\x12\x10MemberExpression\x020\x00\n:\x03\x03\x05JB\x03KOP\x06\x12\x04Name\aB\x03\vL\x14P\b\bB\x04\x10M\x12NP\f\x02 \b\x02 \a\x11\x12\x0fuast:Identifier\t\x12\aconsole\aB\x03ROUPI\aB\x03\vASP\b\bB\x04\x10T\x12MP\f\x02 \t\x05\x12\x03log\b\x12\x06module"
45+
UASTMarshaledJSON = `[
46+
{
47+
"@pos": {
48+
"@type": "uast:Positions",
49+
"end": {
50+
"@type": "uast:Position",
51+
"col": 20,
52+
"line": 1,
53+
"offset": 19
54+
},
55+
"start": {
56+
"@type": "uast:Position",
57+
"col": 1,
58+
"line": 1,
59+
"offset": 0
60+
}
61+
},
62+
"@role": [
63+
"File"
64+
],
65+
"@type": "File",
66+
"comments": [],
67+
"program": {
68+
"@pos": {
69+
"@type": "uast:Positions",
70+
"end": {
71+
"@type": "uast:Position",
72+
"col": 20,
73+
"line": 1,
74+
"offset": 19
75+
},
76+
"start": {
77+
"@type": "uast:Position",
78+
"col": 1,
79+
"line": 1,
80+
"offset": 0
81+
}
82+
},
83+
"@role": [
84+
"Module"
85+
],
86+
"@type": "Program",
87+
"body": [
88+
{
89+
"@pos": {
90+
"@type": "uast:Positions",
91+
"end": {
92+
"@type": "uast:Position",
93+
"col": 20,
94+
"line": 1,
95+
"offset": 19
96+
},
97+
"start": {
98+
"@type": "uast:Position",
99+
"col": 1,
100+
"line": 1,
101+
"offset": 0
102+
}
103+
},
104+
"@role": [
105+
"Statement"
106+
],
107+
"@type": "ExpressionStatement",
108+
"expression": {
109+
"@pos": {
110+
"@type": "uast:Positions",
111+
"end": {
112+
"@type": "uast:Position",
113+
"col": 20,
114+
"line": 1,
115+
"offset": 19
116+
},
117+
"start": {
118+
"@type": "uast:Position",
119+
"col": 1,
120+
"line": 1,
121+
"offset": 0
122+
}
123+
},
124+
"@role": [
125+
"Expression",
126+
"Call"
127+
],
128+
"@type": "CallExpression",
129+
"arguments": [
130+
{
131+
"@pos": {
132+
"@type": "uast:Positions",
133+
"end": {
134+
"@type": "uast:Position",
135+
"col": 19,
136+
"line": 1,
137+
"offset": 18
138+
},
139+
"start": {
140+
"@type": "uast:Position",
141+
"col": 13,
142+
"line": 1,
143+
"offset": 12
144+
}
145+
},
146+
"@role": [
147+
"Call",
148+
"Argument"
149+
],
150+
"@type": "uast:String",
151+
"Format": "",
152+
"Value": "test"
153+
}
154+
],
155+
"callee": {
156+
"@pos": {
157+
"@type": "uast:Positions",
158+
"end": {
159+
"@type": "uast:Position",
160+
"col": 12,
161+
"line": 1,
162+
"offset": 11
163+
},
164+
"start": {
165+
"@type": "uast:Position",
166+
"col": 1,
167+
"line": 1,
168+
"offset": 0
169+
}
170+
},
171+
"@role": [
172+
"Qualified",
173+
"Expression",
174+
"Identifier",
175+
"Call",
176+
"Callee"
177+
],
178+
"@type": "MemberExpression",
179+
"computed": false,
180+
"object": {
181+
"@pos": {
182+
"@type": "uast:Positions",
183+
"end": {
184+
"@type": "uast:Position",
185+
"col": 8,
186+
"line": 1,
187+
"offset": 7
188+
},
189+
"start": {
190+
"@type": "uast:Position",
191+
"col": 1,
192+
"line": 1,
193+
"offset": 0
194+
}
195+
},
196+
"@type": "uast:Identifier",
197+
"Name": "console"
198+
},
199+
"property": {
200+
"@pos": {
201+
"@type": "uast:Positions",
202+
"end": {
203+
"@type": "uast:Position",
204+
"col": 12,
205+
"line": 1,
206+
"offset": 11
207+
},
208+
"start": {
209+
"@type": "uast:Position",
210+
"col": 9,
211+
"line": 1,
212+
"offset": 8
213+
}
214+
},
215+
"@type": "uast:Identifier",
216+
"Name": "log"
217+
}
218+
}
219+
}
220+
}
221+
],
222+
"directives": [],
223+
"sourceType": "module"
224+
}
225+
}
226+
]`
45227
)

0 commit comments

Comments
 (0)