@@ -160,6 +160,37 @@ func TestGetDevices(t *testing.T) {
160160 }
161161 })
162162 })
163+ t .Run ("two devices" , func (t * testing.T ) {
164+ nullDev := filepath .Join (dir , "null" )
165+ if err := ioutil .WriteFile (nullDev , nil , 0600 ); err != nil {
166+ t .Fatal (err )
167+ }
168+
169+ if err := unix .Mount ("/dev/null" , nullDev , "" , unix .MS_BIND , "" ); err != nil {
170+ t .Fatal (err )
171+ }
172+ defer unix .Unmount (filepath .Join (dir , "null" ), unix .MNT_DETACH )
173+ devices , err := getDevices (dir , "" )
174+ if err != nil {
175+ t .Fatal (err )
176+ }
177+
178+ if len (devices ) != 2 {
179+ t .Fatalf ("expected two devices %v" , devices )
180+ }
181+ if devices [0 ].Path == devices [1 ].Path {
182+ t .Fatalf ("got same path for the two devices %s" , devices [0 ].Path )
183+ }
184+ if devices [0 ].Path != zero && devices [0 ].Path != nullDev {
185+ t .Fatalf ("got unexpected device path %s" , devices [0 ].Path )
186+ }
187+ if devices [1 ].Path != zero && devices [1 ].Path != nullDev {
188+ t .Fatalf ("got unexpected device path %s" , devices [1 ].Path )
189+ }
190+ if devices [0 ].Major == devices [1 ].Major && devices [0 ].Minor == devices [1 ].Minor {
191+ t .Fatalf ("got sema mojor and minor on two devices %s %s" , devices [0 ].Path , devices [1 ].Path )
192+ }
193+ })
163194 t .Run ("With symlink in dir" , func (t * testing.T ) {
164195 if err := os .Symlink ("/dev/zero" , filepath .Join (dir , "zerosym" )); err != nil {
165196 t .Fatal (err )
0 commit comments