@@ -26,13 +26,13 @@ func TestRun_All(t *testing.T) {
2626 cases := []Case {
2727 {
2828 query : "SELECT all FROM ./testdata WHERE name = foo" ,
29- expected : fmt .Sprintf ("drwxr-xr-x \t %s\t -------\t foo\n " ,
30- strings .Join (GetAttrs ("foo" , "size" , "time" ), "\t " )),
29+ expected : fmt .Sprintf ("%s\t -------\t foo\n " ,
30+ strings .Join (GetAttrs ("foo" , "mode" , " size" , "time" ), "\t " )),
3131 },
3232 {
3333 query : "SELECT all FROM ./testdata WHERE name LIKE waldo" ,
34- expected : fmt .Sprintf ("-rw-r--r-- \t %s\t waldo\n " ,
35- strings .Join (GetAttrs ("foo/quuz/waldo" , "size" , "time" , "hash" ), "\t " )),
34+ expected : fmt .Sprintf ("%s\t waldo\n " ,
35+ strings .Join (GetAttrs ("foo/quuz/waldo" , "mode" , " size" , "time" , "hash" ), "\t " )),
3636 },
3737 {
3838 query : "SELECT all FROM ./testdata WHERE FORMAT(time, 'Jan 02 2006 15:04') > 'Jan 01 2999 00:00'" ,
@@ -43,43 +43,43 @@ func TestRun_All(t *testing.T) {
4343 expected : fmt .Sprintf (
4444 strings .Repeat ("%s\n " , 8 ),
4545 fmt .Sprintf (
46- "drwxr-xr-x \t %s\t -------\t %-8s" ,
47- strings .Join (GetAttrs ("." , "size" , "time" ), "\t " ),
46+ "%s\t -------\t %-8s" ,
47+ strings .Join (GetAttrs ("." , "mode" , " size" , "time" ), "\t " ),
4848 "testdata" ,
4949 ),
5050 fmt .Sprintf (
51- "drwxr-xr-x \t %s\t -------\t %-8s" ,
52- strings .Join (GetAttrs ("bar" , "size" , "time" ), "\t " ),
51+ "%s\t -------\t %-8s" ,
52+ strings .Join (GetAttrs ("bar" , "mode" , " size" , "time" ), "\t " ),
5353 "bar" ,
5454 ),
5555 fmt .Sprintf (
56- "drwxr-xr-x \t %s\t -------\t %-8s" ,
57- strings .Join (GetAttrs ("bar/garply" , "size" , "time" ), "\t " ),
56+ "%s\t -------\t %-8s" ,
57+ strings .Join (GetAttrs ("bar/garply" , "mode" , " size" , "time" ), "\t " ),
5858 "garply" ,
5959 ),
6060 fmt .Sprintf (
61- "drwxr-xr-x \t %s\t -------\t %-8s" ,
62- strings .Join (GetAttrs ("bar/garply/xyzzy" , "size" , "time" ), "\t " ),
61+ "%s\t -------\t %-8s" ,
62+ strings .Join (GetAttrs ("bar/garply/xyzzy" , "mode" , " size" , "time" ), "\t " ),
6363 "xyzzy" ,
6464 ),
6565 fmt .Sprintf (
66- "drwxr-xr-x \t %s\t -------\t %-8s" ,
67- strings .Join (GetAttrs ("bar/garply/xyzzy/thud" , "size" , "time" ), "\t " ),
66+ "%s\t -------\t %-8s" ,
67+ strings .Join (GetAttrs ("bar/garply/xyzzy/thud" , "mode" , " size" , "time" ), "\t " ),
6868 "thud" ,
6969 ),
7070 fmt .Sprintf (
71- "drwxr-xr-x \t %s\t -------\t %-8s" ,
72- strings .Join (GetAttrs ("foo" , "size" , "time" ), "\t " ),
71+ "%s\t -------\t %-8s" ,
72+ strings .Join (GetAttrs ("foo" , "mode" , " size" , "time" ), "\t " ),
7373 "foo" ,
7474 ),
7575 fmt .Sprintf (
76- "drwxr-xr-x \t %s\t -------\t %-8s" ,
77- strings .Join (GetAttrs ("foo/quuz" , "size" , "time" ), "\t " ),
76+ "%s\t -------\t %-8s" ,
77+ strings .Join (GetAttrs ("foo/quuz" , "mode" , " size" , "time" ), "\t " ),
7878 "quuz" ,
7979 ),
8080 fmt .Sprintf (
81- "drwxr-xr-x \t %s\t -------\t %-8s" ,
82- strings .Join (GetAttrs ("foo/quuz/fred" , "size" , "time" ), "\t " ),
81+ "%s\t -------\t %-8s" ,
82+ strings .Join (GetAttrs ("foo/quuz/fred" , "mode" , " size" , "time" ), "\t " ),
8383 "fred" ,
8484 ),
8585 ),
@@ -89,7 +89,7 @@ func TestRun_All(t *testing.T) {
8989 for _ , c := range cases {
9090 actual := DoRun (c .query )
9191 if ! reflect .DeepEqual (c .expected , actual ) {
92- t .Fatalf ("\n Expected:\n %v\n Got:\n %v" , c .expected , actual )
92+ t .Fatalf ("%s \n Expected:\n %v\n Got:\n %v" , c . query , c .expected , actual )
9393 }
9494 }
9595}
@@ -155,7 +155,7 @@ func TestRun_Multiple(t *testing.T) {
155155 for _ , c := range cases {
156156 actual := DoRun (c .query )
157157 if ! reflect .DeepEqual (c .expected , actual ) {
158- t .Fatalf ("\n Expected:\n %v\n Got:\n %v" , c .expected , actual )
158+ t .Fatalf ("%s \n Expected:\n %v\n Got:\n %v" , c . query , c .expected , actual )
159159 }
160160 }
161161}
@@ -194,7 +194,7 @@ func TestRun_Name(t *testing.T) {
194194 for _ , c := range cases {
195195 actual := DoRun (c .query )
196196 if ! reflect .DeepEqual (c .expected , actual ) {
197- t .Fatalf ("\n Expected:\n %v\n Got:\n %v" , c .expected , actual )
197+ t .Fatalf ("%s \n Expected:\n %v\n Got:\n %v" , c . query , c .expected , actual )
198198 }
199199 }
200200}
@@ -236,7 +236,7 @@ func TestRun_Size(t *testing.T) {
236236 for _ , c := range cases {
237237 actual := DoRun (c .query )
238238 if ! reflect .DeepEqual (c .expected , actual ) {
239- t .Fatalf ("\n Expected:\n %v\n Got:\n %v" , c .expected , actual )
239+ t .Fatalf ("%s \n Expected:\n %v\n Got:\n %v" , c . query , c .expected , actual )
240240 }
241241 }
242242}
@@ -275,7 +275,7 @@ func TestRun_Time(t *testing.T) {
275275 for _ , c := range cases {
276276 actual := DoRun (c .query )
277277 if ! reflect .DeepEqual (c .expected , actual ) {
278- t .Fatalf ("\n Expected:\n %v\n Got:\n %v" , c .expected , actual )
278+ t .Fatalf ("%s \n Expected:\n %v\n Got:\n %v" , c . query , c .expected , actual )
279279 }
280280 }
281281}
@@ -289,22 +289,31 @@ func TestRun_Mode(t *testing.T) {
289289 cases := []Case {
290290 {
291291 query : "SELECT mode FROM ./testdata WHERE name = foo" ,
292- expected : "drwxr-xr-x \n " ,
292+ expected : fmt . Sprintf ( "%s \n ", GetAttrs ( "foo" , "mode" )[ 0 ]) ,
293293 },
294294 {
295295 query : "SELECT mode FROM ./testdata WHERE name = baz" ,
296- expected : "-rwxr-xr-x \n " ,
296+ expected : fmt . Sprintf ( "%s \n ", GetAttrs ( "baz" , "mode" )[ 0 ]) ,
297297 },
298298 {
299- query : "SELECT mode FROM ./testdata WHERE mode IS DIR" ,
300- expected : strings .Repeat ("drwxr-xr-x\n " , 8 ),
299+ query : "SELECT mode FROM ./testdata WHERE mode IS DIR" ,
300+ expected : fmt .Sprintf (strings .Repeat ("%s\n " , 8 ),
301+ GetAttrs ("" , "mode" )[0 ],
302+ GetAttrs ("foo" , "mode" )[0 ],
303+ GetAttrs ("foo/quuz" , "mode" )[0 ],
304+ GetAttrs ("foo/quuz/fred" , "mode" )[0 ],
305+ GetAttrs ("bar" , "mode" )[0 ],
306+ GetAttrs ("bar/garply" , "mode" )[0 ],
307+ GetAttrs ("bar/garply/xyzzy" , "mode" )[0 ],
308+ GetAttrs ("bar/garply/xyzzy/thud" , "mode" )[0 ],
309+ ),
301310 },
302311 }
303312
304313 for _ , c := range cases {
305314 actual := DoRun (c .query )
306315 if ! reflect .DeepEqual (c .expected , actual ) {
307- t .Fatalf ("\n Expected:\n %v\n Got:\n %v" , c .expected , actual )
316+ t .Fatalf ("%s \n Expected:\n \" %v\" \ n Got:\n \" %v \" " , c . query , c .expected , actual )
308317 }
309318 }
310319}
@@ -321,7 +330,7 @@ func TestRun_Hash(t *testing.T) {
321330 for _ , c := range cases {
322331 actual := DoRun (c .query )
323332 if ! reflect .DeepEqual (c .expected , actual ) {
324- t .Fatalf ("\n Expected:\n %v\n Got:\n %v" , c .expected , actual )
333+ t .Fatalf ("%s \n Expected:\n %v\n Got:\n %v" , c . query , c .expected , actual )
325334 }
326335 }
327336}
@@ -361,6 +370,8 @@ func GetAttrs(path string, attrs ...string) []string {
361370 return []string {}
362371 }
363372 result [i ] = hex .EncodeToString (h .Sum (nil ))[:7 ]
373+ case "mode" :
374+ result [i ] = (* file ).Mode ().String ()
364375 case "size" :
365376 result [i ] = fmt .Sprintf ("%d" , (* file ).Size ())
366377 case "size:kb" , "size:mb" , "size:gb" :
0 commit comments