golang.org/x/sys@v0.20.1-0.20240517151509-673e0f94c16d/unix/getfsstat_test.go (about) 1 // Copyright 2022 The Go 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 darwin || dragonfly || freebsd || openbsd 6 7 package unix_test 8 9 import ( 10 "os/exec" 11 "testing" 12 13 "golang.org/x/sys/unix" 14 ) 15 16 func TestGetfsstat(t *testing.T) { 17 n, err := unix.Getfsstat(nil, unix.MNT_NOWAIT) 18 if err != nil { 19 t.Fatal(err) 20 } 21 22 data := make([]unix.Statfs_t, n) 23 n2, err := unix.Getfsstat(data, unix.MNT_NOWAIT) 24 if err != nil { 25 t.Fatal(err) 26 } 27 if n != n2 { 28 t.Errorf("Getfsstat(nil) = %d, but subsequent Getfsstat(slice) = %d", n, n2) 29 } 30 for i, stat := range data { 31 if stat == (unix.Statfs_t{}) { 32 t.Errorf("index %v is an empty Statfs_t struct", i) 33 } 34 } 35 if t.Failed() { 36 for i, stat := range data[:n2] { 37 t.Logf("data[%v] = %+v", i, stat) 38 } 39 mount, err := exec.Command("mount").CombinedOutput() 40 if err != nil { 41 t.Logf("mount: %v\n%s", err, mount) 42 } else { 43 t.Logf("mount: %s", mount) 44 } 45 } 46 }