Skip to content

Commit 4f61da8

Browse files
tklausergopherbot
authored andcommitted
unix: use ByteSliceToString in TestMountUnmount on zos
Use the existing ByteSliceToString implementation instead of duplicating it in TestMountUnmount. Change-Id: Ia47510ac1ac8094a7e9265edf8a452bcacf06032 Reviewed-on: https://go-review.googlesource.com/c/sys/+/411379 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org>
1 parent ff8c426 commit 4f61da8

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

unix/syscall_zos_test.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
package unix_test
99

1010
import (
11-
"bytes"
1211
"flag"
1312
"fmt"
1413
"io/ioutil"
@@ -608,14 +607,6 @@ func chtmpdir(t *testing.T) func() {
608607
}
609608

610609
func TestMountUnmount(t *testing.T) {
611-
b2s := func(arr []byte) string {
612-
nulli := bytes.IndexByte(arr, 0)
613-
if nulli == -1 {
614-
return string(arr)
615-
} else {
616-
return string(arr[:nulli])
617-
}
618-
}
619610
// use an available fs
620611
var buffer struct {
621612
header unix.W_Mnth
@@ -632,7 +623,7 @@ func TestMountUnmount(t *testing.T) {
632623
var mountpoint string
633624
var available bool = false
634625
for i := 0; i < fsCount; i++ {
635-
err = unix.Unmount(b2s(buffer.fsinfo[i].Mountpoint[:]), unix.MTM_RDWR)
626+
err = unix.Unmount(unix.ByteSliceToString(buffer.fsinfo[i].Mountpoint[:]), unix.MTM_RDWR)
636627
if err != nil {
637628
// Unmount and Mount require elevated privilege
638629
// If test is run without such permission, skip test
@@ -646,9 +637,9 @@ func TestMountUnmount(t *testing.T) {
646637
}
647638
} else {
648639
available = true
649-
fs = b2s(buffer.fsinfo[i].Fsname[:])
650-
fstype = b2s(buffer.fsinfo[i].Fstname[:])
651-
mountpoint = b2s(buffer.fsinfo[i].Mountpoint[:])
640+
fs = unix.ByteSliceToString(buffer.fsinfo[i].Fsname[:])
641+
fstype = unix.ByteSliceToString(buffer.fsinfo[i].Fstname[:])
642+
mountpoint = unix.ByteSliceToString(buffer.fsinfo[i].Mountpoint[:])
652643
t.Logf("using file system = %s; fstype = %s and mountpoint = %s\n", fs, fstype, mountpoint)
653644
break
654645
}
@@ -663,7 +654,7 @@ func TestMountUnmount(t *testing.T) {
663654
t.Fatalf("W_Getmntent_A returns with error: %s", err.Error())
664655
}
665656
for i := 0; i < fsCount; i++ {
666-
if b2s(buffer.fsinfo[i].Fsname[:]) == fs {
657+
if unix.ByteSliceToString(buffer.fsinfo[i].Fsname[:]) == fs {
667658
t.Fatalf("File system found after unmount")
668659
}
669660
}
@@ -679,7 +670,8 @@ func TestMountUnmount(t *testing.T) {
679670
}
680671
fsMounted := false
681672
for i := 0; i < fsCount; i++ {
682-
if b2s(buffer.fsinfo[i].Fsname[:]) == fs && b2s(buffer.fsinfo[i].Mountpoint[:]) == mountpoint {
673+
if unix.ByteSliceToString(buffer.fsinfo[i].Fsname[:]) == fs &&
674+
unix.ByteSliceToString(buffer.fsinfo[i].Mountpoint[:]) == mountpoint {
683675
fsMounted = true
684676
}
685677
}

0 commit comments

Comments
 (0)