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