github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/pkg/mount/scuzz_mount_test.go (about) 1 // Copyright 2020 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build amd64 6 // +build amd64 7 8 package mount_test 9 10 import ( 11 "testing" 12 13 "github.com/mvdan/u-root-coreutils/pkg/mount/block" 14 "github.com/mvdan/u-root-coreutils/pkg/mount/scuzz" 15 "github.com/mvdan/u-root-coreutils/pkg/testutil" 16 ) 17 18 func TestIdentify(t *testing.T) { 19 testutil.SkipIfNotRoot(t) 20 21 disk, err := scuzz.NewSGDisk("/dev/sda") 22 if err != nil { 23 t.Fatal(err) 24 } 25 defer disk.Close() 26 27 info, err := disk.Identify() 28 if err != nil { 29 t.Fatal(err) 30 } 31 t.Logf("Identify(/dev/sda): %v", info) 32 33 device, err := block.Device("/dev/sda") 34 if err != nil { 35 t.Fatal(err) 36 } 37 size, err := device.Size() 38 if err != nil { 39 t.Fatal(err) 40 } 41 42 if info.NumberSectors != size/512 { 43 t.Errorf("Identify(/dev/sda).NumberSectors = %d, want %d", info.NumberSectors, size/512) 44 } 45 }