File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 77 "io"
88 "os"
99 "path/filepath"
10+ "sort"
1011 "strings"
1112 "time"
1213
@@ -121,6 +122,12 @@ func (fs *Memory) Lstat(filename string) (os.FileInfo, error) {
121122 return f .Stat ()
122123}
123124
125+ type ByName []os.FileInfo
126+
127+ func (a ByName ) Len () int { return len (a ) }
128+ func (a ByName ) Less (i , j int ) bool { return a [i ].Name () < a [j ].Name () }
129+ func (a ByName ) Swap (i , j int ) { a [i ], a [j ] = a [j ], a [i ] }
130+
124131func (fs * Memory ) ReadDir (path string ) ([]os.FileInfo , error ) {
125132 if f , has := fs .s .Get (path ); has {
126133 if target , isLink := fs .resolveLink (path , f ); isLink {
@@ -134,6 +141,8 @@ func (fs *Memory) ReadDir(path string) ([]os.FileInfo, error) {
134141 entries = append (entries , fi )
135142 }
136143
144+ sort .Sort (ByName (entries ))
145+
137146 return entries , nil
138147}
139148
Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ func (s *MemorySuite) TestNegativeOffsets(c *C) {
4747 c .Assert (err , ErrorMatches , "writeat negative: negative offset" )
4848}
4949
50+
5051func (s * MemorySuite ) TestExclusive (c * C ) {
5152 f , err := s .FS .OpenFile ("exclusive" , os .O_CREATE | os .O_EXCL | os .O_RDWR , 0666 )
5253 c .Assert (err , IsNil )
@@ -58,4 +59,27 @@ func (s *MemorySuite) TestExclusive(c *C) {
5859
5960 _ , err = s .FS .OpenFile ("exclusive" , os .O_CREATE | os .O_EXCL | os .O_RDWR , 0666 )
6061 c .Assert (err , ErrorMatches , os .ErrExist .Error ())
62+
63+ func (s * MemorySuite ) TestOrder (c * C ) {
64+ var err error
65+
66+ files := []string {
67+ "a" ,
68+ "b" ,
69+ "c" ,
70+ }
71+ for _ , f := range files {
72+ _ , err = s .FS .Create (f )
73+ c .Assert (err , IsNil )
74+ }
75+
76+ attemps := 30
77+ for n := 0 ; n < attemps ; n ++ {
78+ actual , err := s .FS .ReadDir ("" )
79+ c .Assert (err , IsNil )
80+
81+ for i , f := range files {
82+ c .Assert (actual [i ].Name (), Equals , f )
83+ }
84+ }
6185}
You can’t perform that action at this time.
0 commit comments