afero_test.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. // Copyright © 2014 Steve Francia <spf@spf13.com>.
  2. // Copyright 2009 The Go Authors. All rights reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package afero
  15. import (
  16. "bytes"
  17. "fmt"
  18. "io"
  19. "io/ioutil"
  20. "os"
  21. "path/filepath"
  22. "runtime"
  23. "strings"
  24. "syscall"
  25. "testing"
  26. )
  27. var testName = "test.txt"
  28. var Fss = []Fs{&MemMapFs{}, &OsFs{}}
  29. var testRegistry map[Fs][]string = make(map[Fs][]string)
  30. func testDir(fs Fs) string {
  31. name, err := TempDir(fs, "", "afero")
  32. if err != nil {
  33. panic(fmt.Sprint("unable to work with test dir", err))
  34. }
  35. testRegistry[fs] = append(testRegistry[fs], name)
  36. return name
  37. }
  38. func tmpFile(fs Fs) File {
  39. x, err := TempFile(fs, "", "afero")
  40. if err != nil {
  41. panic(fmt.Sprint("unable to work with temp file", err))
  42. }
  43. testRegistry[fs] = append(testRegistry[fs], x.Name())
  44. return x
  45. }
  46. //Read with length 0 should not return EOF.
  47. func TestRead0(t *testing.T) {
  48. for _, fs := range Fss {
  49. f := tmpFile(fs)
  50. defer f.Close()
  51. f.WriteString("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
  52. var b []byte
  53. // b := make([]byte, 0)
  54. n, err := f.Read(b)
  55. if n != 0 || err != nil {
  56. t.Errorf("%v: Read(0) = %d, %v, want 0, nil", fs.Name(), n, err)
  57. }
  58. f.Seek(0, 0)
  59. b = make([]byte, 100)
  60. n, err = f.Read(b)
  61. if n <= 0 || err != nil {
  62. t.Errorf("%v: Read(100) = %d, %v, want >0, nil", fs.Name(), n, err)
  63. }
  64. }
  65. }
  66. func TestOpenFile(t *testing.T) {
  67. defer removeAllTestFiles(t)
  68. for _, fs := range Fss {
  69. tmp := testDir(fs)
  70. path := filepath.Join(tmp, testName)
  71. f, err := fs.OpenFile(path, os.O_RDWR|os.O_CREATE, 0600)
  72. if err != nil {
  73. t.Error(fs.Name(), "OpenFile (O_CREATE) failed:", err)
  74. continue
  75. }
  76. io.WriteString(f, "initial")
  77. f.Close()
  78. f, err = fs.OpenFile(path, os.O_WRONLY|os.O_APPEND, 0600)
  79. if err != nil {
  80. t.Error(fs.Name(), "OpenFile (O_APPEND) failed:", err)
  81. continue
  82. }
  83. io.WriteString(f, "|append")
  84. f.Close()
  85. f, err = fs.OpenFile(path, os.O_RDONLY, 0600)
  86. contents, _ := ioutil.ReadAll(f)
  87. expectedContents := "initial|append"
  88. if string(contents) != expectedContents {
  89. t.Errorf("%v: appending, expected '%v', got: '%v'", fs.Name(), expectedContents, string(contents))
  90. }
  91. f.Close()
  92. f, err = fs.OpenFile(path, os.O_RDWR|os.O_TRUNC, 0600)
  93. if err != nil {
  94. t.Error(fs.Name(), "OpenFile (O_TRUNC) failed:", err)
  95. continue
  96. }
  97. contents, _ = ioutil.ReadAll(f)
  98. if string(contents) != "" {
  99. t.Errorf("%v: expected truncated file, got: '%v'", fs.Name(), string(contents))
  100. }
  101. f.Close()
  102. }
  103. }
  104. func TestCreate(t *testing.T) {
  105. defer removeAllTestFiles(t)
  106. for _, fs := range Fss {
  107. tmp := testDir(fs)
  108. path := filepath.Join(tmp, testName)
  109. f, err := fs.Create(path)
  110. if err != nil {
  111. t.Error(fs.Name(), "Create failed:", err)
  112. f.Close()
  113. continue
  114. }
  115. io.WriteString(f, "initial")
  116. f.Close()
  117. f, err = fs.Create(path)
  118. if err != nil {
  119. t.Error(fs.Name(), "Create failed:", err)
  120. f.Close()
  121. continue
  122. }
  123. secondContent := "second create"
  124. io.WriteString(f, secondContent)
  125. f.Close()
  126. f, err = fs.Open(path)
  127. if err != nil {
  128. t.Error(fs.Name(), "Open failed:", err)
  129. f.Close()
  130. continue
  131. }
  132. buf, err := ReadAll(f)
  133. if err != nil {
  134. t.Error(fs.Name(), "ReadAll failed:", err)
  135. f.Close()
  136. continue
  137. }
  138. if string(buf) != secondContent {
  139. t.Error(fs.Name(), "Content should be", "\""+secondContent+"\" but is \""+string(buf)+"\"")
  140. f.Close()
  141. continue
  142. }
  143. f.Close()
  144. }
  145. }
  146. func TestMemFileRead(t *testing.T) {
  147. f := tmpFile(new(MemMapFs))
  148. // f := MemFileCreate("testfile")
  149. f.WriteString("abcd")
  150. f.Seek(0, 0)
  151. b := make([]byte, 8)
  152. n, err := f.Read(b)
  153. if n != 4 {
  154. t.Errorf("didn't read all bytes: %v %v %v", n, err, b)
  155. }
  156. if err != nil {
  157. t.Errorf("err is not nil: %v %v %v", n, err, b)
  158. }
  159. n, err = f.Read(b)
  160. if n != 0 {
  161. t.Errorf("read more bytes: %v %v %v", n, err, b)
  162. }
  163. if err != io.EOF {
  164. t.Errorf("error is not EOF: %v %v %v", n, err, b)
  165. }
  166. }
  167. func TestRename(t *testing.T) {
  168. defer removeAllTestFiles(t)
  169. for _, fs := range Fss {
  170. tDir := testDir(fs)
  171. from := filepath.Join(tDir, "/renamefrom")
  172. to := filepath.Join(tDir, "/renameto")
  173. exists := filepath.Join(tDir, "/renameexists")
  174. file, err := fs.Create(from)
  175. if err != nil {
  176. t.Fatalf("%s: open %q failed: %v", fs.Name(), to, err)
  177. }
  178. if err = file.Close(); err != nil {
  179. t.Errorf("%s: close %q failed: %v", fs.Name(), to, err)
  180. }
  181. file, err = fs.Create(exists)
  182. if err != nil {
  183. t.Fatalf("%s: open %q failed: %v", fs.Name(), to, err)
  184. }
  185. if err = file.Close(); err != nil {
  186. t.Errorf("%s: close %q failed: %v", fs.Name(), to, err)
  187. }
  188. err = fs.Rename(from, to)
  189. if err != nil {
  190. t.Fatalf("%s: rename %q, %q failed: %v", fs.Name(), to, from, err)
  191. }
  192. file, err = fs.Create(from)
  193. if err != nil {
  194. t.Fatalf("%s: open %q failed: %v", fs.Name(), to, err)
  195. }
  196. if err = file.Close(); err != nil {
  197. t.Errorf("%s: close %q failed: %v", fs.Name(), to, err)
  198. }
  199. err = fs.Rename(from, exists)
  200. if err != nil {
  201. t.Errorf("%s: rename %q, %q failed: %v", fs.Name(), exists, from, err)
  202. }
  203. names, err := readDirNames(fs, tDir)
  204. if err != nil {
  205. t.Errorf("%s: readDirNames error: %v", fs.Name(), err)
  206. }
  207. found := false
  208. for _, e := range names {
  209. if e == "renamefrom" {
  210. t.Error("File is still called renamefrom")
  211. }
  212. if e == "renameto" {
  213. found = true
  214. }
  215. }
  216. if !found {
  217. t.Error("File was not renamed to renameto")
  218. }
  219. _, err = fs.Stat(to)
  220. if err != nil {
  221. t.Errorf("%s: stat %q failed: %v", fs.Name(), to, err)
  222. }
  223. }
  224. }
  225. func TestRemove(t *testing.T) {
  226. for _, fs := range Fss {
  227. x, err := TempFile(fs, "", "afero")
  228. if err != nil {
  229. t.Error(fmt.Sprint("unable to work with temp file", err))
  230. }
  231. path := x.Name()
  232. x.Close()
  233. tDir := filepath.Dir(path)
  234. err = fs.Remove(path)
  235. if err != nil {
  236. t.Errorf("%v: Remove() failed: %v", fs.Name(), err)
  237. continue
  238. }
  239. _, err = fs.Stat(path)
  240. if !os.IsNotExist(err) {
  241. t.Errorf("%v: Remove() didn't remove file", fs.Name())
  242. continue
  243. }
  244. // Deleting non-existent file should raise error
  245. err = fs.Remove(path)
  246. if !os.IsNotExist(err) {
  247. t.Errorf("%v: Remove() didn't raise error for non-existent file", fs.Name())
  248. }
  249. f, err := fs.Open(tDir)
  250. if err != nil {
  251. t.Error("TestDir should still exist:", err)
  252. }
  253. names, err := f.Readdirnames(-1)
  254. if err != nil {
  255. t.Error("Readdirnames failed:", err)
  256. }
  257. for _, e := range names {
  258. if e == testName {
  259. t.Error("File was not removed from parent directory")
  260. }
  261. }
  262. }
  263. }
  264. func TestTruncate(t *testing.T) {
  265. defer removeAllTestFiles(t)
  266. for _, fs := range Fss {
  267. f := tmpFile(fs)
  268. defer f.Close()
  269. checkSize(t, f, 0)
  270. f.Write([]byte("hello, world\n"))
  271. checkSize(t, f, 13)
  272. f.Truncate(10)
  273. checkSize(t, f, 10)
  274. f.Truncate(1024)
  275. checkSize(t, f, 1024)
  276. f.Truncate(0)
  277. checkSize(t, f, 0)
  278. _, err := f.Write([]byte("surprise!"))
  279. if err == nil {
  280. checkSize(t, f, 13+9) // wrote at offset past where hello, world was.
  281. }
  282. }
  283. }
  284. func TestSeek(t *testing.T) {
  285. defer removeAllTestFiles(t)
  286. for _, fs := range Fss {
  287. f := tmpFile(fs)
  288. defer f.Close()
  289. const data = "hello, world\n"
  290. io.WriteString(f, data)
  291. type test struct {
  292. in int64
  293. whence int
  294. out int64
  295. }
  296. var tests = []test{
  297. {0, 1, int64(len(data))},
  298. {0, 0, 0},
  299. {5, 0, 5},
  300. {0, 2, int64(len(data))},
  301. {0, 0, 0},
  302. {-1, 2, int64(len(data)) - 1},
  303. {1 << 33, 0, 1 << 33},
  304. {1 << 33, 2, 1<<33 + int64(len(data))},
  305. }
  306. for i, tt := range tests {
  307. off, err := f.Seek(tt.in, tt.whence)
  308. if off != tt.out || err != nil {
  309. if e, ok := err.(*os.PathError); ok && e.Err == syscall.EINVAL && tt.out > 1<<32 {
  310. // Reiserfs rejects the big seeks.
  311. // http://code.google.com/p/go/issues/detail?id=91
  312. break
  313. }
  314. t.Errorf("#%d: Seek(%v, %v) = %v, %v want %v, nil", i, tt.in, tt.whence, off, err, tt.out)
  315. }
  316. }
  317. }
  318. }
  319. func TestReadAt(t *testing.T) {
  320. defer removeAllTestFiles(t)
  321. for _, fs := range Fss {
  322. f := tmpFile(fs)
  323. defer f.Close()
  324. const data = "hello, world\n"
  325. io.WriteString(f, data)
  326. b := make([]byte, 5)
  327. n, err := f.ReadAt(b, 7)
  328. if err != nil || n != len(b) {
  329. t.Fatalf("ReadAt 7: %d, %v", n, err)
  330. }
  331. if string(b) != "world" {
  332. t.Fatalf("ReadAt 7: have %q want %q", string(b), "world")
  333. }
  334. }
  335. }
  336. func TestWriteAt(t *testing.T) {
  337. defer removeAllTestFiles(t)
  338. for _, fs := range Fss {
  339. f := tmpFile(fs)
  340. defer f.Close()
  341. const data = "hello, world\n"
  342. io.WriteString(f, data)
  343. n, err := f.WriteAt([]byte("WORLD"), 7)
  344. if err != nil || n != 5 {
  345. t.Fatalf("WriteAt 7: %d, %v", n, err)
  346. }
  347. f2, err := fs.Open(f.Name())
  348. if err != nil {
  349. t.Fatalf("%v: ReadFile %s: %v", fs.Name(), f.Name(), err)
  350. }
  351. defer f2.Close()
  352. buf := new(bytes.Buffer)
  353. buf.ReadFrom(f2)
  354. b := buf.Bytes()
  355. if string(b) != "hello, WORLD\n" {
  356. t.Fatalf("after write: have %q want %q", string(b), "hello, WORLD\n")
  357. }
  358. }
  359. }
  360. func setupTestDir(t *testing.T, fs Fs) string {
  361. path := testDir(fs)
  362. return setupTestFiles(t, fs, path)
  363. }
  364. func setupTestDirRoot(t *testing.T, fs Fs) string {
  365. path := testDir(fs)
  366. setupTestFiles(t, fs, path)
  367. return path
  368. }
  369. func setupTestDirReusePath(t *testing.T, fs Fs, path string) string {
  370. testRegistry[fs] = append(testRegistry[fs], path)
  371. return setupTestFiles(t, fs, path)
  372. }
  373. func setupTestFiles(t *testing.T, fs Fs, path string) string {
  374. testSubDir := filepath.Join(path, "more", "subdirectories", "for", "testing", "we")
  375. err := fs.MkdirAll(testSubDir, 0700)
  376. if err != nil && !os.IsExist(err) {
  377. t.Fatal(err)
  378. }
  379. f, err := fs.Create(filepath.Join(testSubDir, "testfile1"))
  380. if err != nil {
  381. t.Fatal(err)
  382. }
  383. f.WriteString("Testfile 1 content")
  384. f.Close()
  385. f, err = fs.Create(filepath.Join(testSubDir, "testfile2"))
  386. if err != nil {
  387. t.Fatal(err)
  388. }
  389. f.WriteString("Testfile 2 content")
  390. f.Close()
  391. f, err = fs.Create(filepath.Join(testSubDir, "testfile3"))
  392. if err != nil {
  393. t.Fatal(err)
  394. }
  395. f.WriteString("Testfile 3 content")
  396. f.Close()
  397. f, err = fs.Create(filepath.Join(testSubDir, "testfile4"))
  398. if err != nil {
  399. t.Fatal(err)
  400. }
  401. f.WriteString("Testfile 4 content")
  402. f.Close()
  403. return testSubDir
  404. }
  405. func TestReaddirnames(t *testing.T) {
  406. defer removeAllTestFiles(t)
  407. for _, fs := range Fss {
  408. testSubDir := setupTestDir(t, fs)
  409. tDir := filepath.Dir(testSubDir)
  410. root, err := fs.Open(tDir)
  411. if err != nil {
  412. t.Fatal(fs.Name(), tDir, err)
  413. }
  414. defer root.Close()
  415. namesRoot, err := root.Readdirnames(-1)
  416. if err != nil {
  417. t.Fatal(fs.Name(), namesRoot, err)
  418. }
  419. sub, err := fs.Open(testSubDir)
  420. if err != nil {
  421. t.Fatal(err)
  422. }
  423. defer sub.Close()
  424. namesSub, err := sub.Readdirnames(-1)
  425. if err != nil {
  426. t.Fatal(fs.Name(), namesSub, err)
  427. }
  428. findNames(fs, t, tDir, testSubDir, namesRoot, namesSub)
  429. }
  430. }
  431. func TestReaddirSimple(t *testing.T) {
  432. defer removeAllTestFiles(t)
  433. for _, fs := range Fss {
  434. testSubDir := setupTestDir(t, fs)
  435. tDir := filepath.Dir(testSubDir)
  436. root, err := fs.Open(tDir)
  437. if err != nil {
  438. t.Fatal(err)
  439. }
  440. defer root.Close()
  441. rootInfo, err := root.Readdir(1)
  442. if err != nil {
  443. t.Log(myFileInfo(rootInfo))
  444. t.Error(err)
  445. }
  446. rootInfo, err = root.Readdir(5)
  447. if err != io.EOF {
  448. t.Log(myFileInfo(rootInfo))
  449. t.Error(err)
  450. }
  451. sub, err := fs.Open(testSubDir)
  452. if err != nil {
  453. t.Fatal(err)
  454. }
  455. defer sub.Close()
  456. subInfo, err := sub.Readdir(5)
  457. if err != nil {
  458. t.Log(myFileInfo(subInfo))
  459. t.Error(err)
  460. }
  461. }
  462. }
  463. func TestReaddir(t *testing.T) {
  464. defer removeAllTestFiles(t)
  465. for num := 0; num < 6; num++ {
  466. outputs := make([]string, len(Fss))
  467. infos := make([]string, len(Fss))
  468. for i, fs := range Fss {
  469. testSubDir := setupTestDir(t, fs)
  470. //tDir := filepath.Dir(testSubDir)
  471. root, err := fs.Open(testSubDir)
  472. if err != nil {
  473. t.Fatal(err)
  474. }
  475. defer root.Close()
  476. for j := 0; j < 6; j++ {
  477. info, err := root.Readdir(num)
  478. outputs[i] += fmt.Sprintf("%v Error: %v\n", myFileInfo(info), err)
  479. infos[i] += fmt.Sprintln(len(info), err)
  480. }
  481. }
  482. fail := false
  483. for i, o := range infos {
  484. if i == 0 {
  485. continue
  486. }
  487. if o != infos[i-1] {
  488. fail = true
  489. break
  490. }
  491. }
  492. if fail {
  493. t.Log("Readdir outputs not equal for Readdir(", num, ")")
  494. for i, o := range outputs {
  495. t.Log(Fss[i].Name())
  496. t.Log(o)
  497. }
  498. t.Fail()
  499. }
  500. }
  501. }
  502. // https://github.com/spf13/afero/issues/169
  503. func TestReaddirRegularFile(t *testing.T) {
  504. defer removeAllTestFiles(t)
  505. for _, fs := range Fss {
  506. f := tmpFile(fs)
  507. defer f.Close()
  508. _, err := f.Readdirnames(-1)
  509. if err == nil {
  510. t.Fatal("Expected error")
  511. }
  512. _, err = f.Readdir(-1)
  513. if err == nil {
  514. t.Fatal("Expected error")
  515. }
  516. }
  517. }
  518. type myFileInfo []os.FileInfo
  519. func (m myFileInfo) String() string {
  520. out := "Fileinfos:\n"
  521. for _, e := range m {
  522. out += " " + e.Name() + "\n"
  523. }
  524. return out
  525. }
  526. func TestReaddirAll(t *testing.T) {
  527. defer removeAllTestFiles(t)
  528. for _, fs := range Fss {
  529. testSubDir := setupTestDir(t, fs)
  530. tDir := filepath.Dir(testSubDir)
  531. root, err := fs.Open(tDir)
  532. if err != nil {
  533. t.Fatal(err)
  534. }
  535. defer root.Close()
  536. rootInfo, err := root.Readdir(-1)
  537. if err != nil {
  538. t.Fatal(err)
  539. }
  540. var namesRoot = []string{}
  541. for _, e := range rootInfo {
  542. namesRoot = append(namesRoot, e.Name())
  543. }
  544. sub, err := fs.Open(testSubDir)
  545. if err != nil {
  546. t.Fatal(err)
  547. }
  548. defer sub.Close()
  549. subInfo, err := sub.Readdir(-1)
  550. if err != nil {
  551. t.Fatal(err)
  552. }
  553. var namesSub = []string{}
  554. for _, e := range subInfo {
  555. namesSub = append(namesSub, e.Name())
  556. }
  557. findNames(fs, t, tDir, testSubDir, namesRoot, namesSub)
  558. }
  559. }
  560. func findNames(fs Fs, t *testing.T, tDir, testSubDir string, root, sub []string) {
  561. var foundRoot bool
  562. for _, e := range root {
  563. f, err := fs.Open(filepath.Join(tDir, e))
  564. if err != nil {
  565. t.Error("Open", filepath.Join(tDir, e), ":", err)
  566. }
  567. defer f.Close()
  568. if equal(e, "we") {
  569. foundRoot = true
  570. }
  571. }
  572. if !foundRoot {
  573. t.Logf("Names root: %v", root)
  574. t.Logf("Names sub: %v", sub)
  575. t.Error("Didn't find subdirectory we")
  576. }
  577. var found1, found2 bool
  578. for _, e := range sub {
  579. f, err := fs.Open(filepath.Join(testSubDir, e))
  580. if err != nil {
  581. t.Error("Open", filepath.Join(testSubDir, e), ":", err)
  582. }
  583. defer f.Close()
  584. if equal(e, "testfile1") {
  585. found1 = true
  586. }
  587. if equal(e, "testfile2") {
  588. found2 = true
  589. }
  590. }
  591. if !found1 {
  592. t.Logf("Names root: %v", root)
  593. t.Logf("Names sub: %v", sub)
  594. t.Error("Didn't find testfile1")
  595. }
  596. if !found2 {
  597. t.Logf("Names root: %v", root)
  598. t.Logf("Names sub: %v", sub)
  599. t.Error("Didn't find testfile2")
  600. }
  601. }
  602. func removeAllTestFiles(t *testing.T) {
  603. for fs, list := range testRegistry {
  604. for _, path := range list {
  605. if err := fs.RemoveAll(path); err != nil {
  606. t.Error(fs.Name(), err)
  607. }
  608. }
  609. }
  610. testRegistry = make(map[Fs][]string)
  611. }
  612. func equal(name1, name2 string) (r bool) {
  613. switch runtime.GOOS {
  614. case "windows":
  615. r = strings.ToLower(name1) == strings.ToLower(name2)
  616. default:
  617. r = name1 == name2
  618. }
  619. return
  620. }
  621. func checkSize(t *testing.T, f File, size int64) {
  622. dir, err := f.Stat()
  623. if err != nil {
  624. t.Fatalf("Stat %q (looking for size %d): %s", f.Name(), size, err)
  625. }
  626. if dir.Size() != size {
  627. t.Errorf("Stat %q: size %d want %d", f.Name(), dir.Size(), size)
  628. }
  629. }