Skip to content

Commit

Permalink
Moved LoadFile test to a linux-only test file.
Browse files Browse the repository at this point in the history
  • Loading branch information
vaughan0 committed Sep 23, 2013
1 parent 85f6018 commit 3c405a4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 37 deletions.
43 changes: 43 additions & 0 deletions ini_linux_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package ini

import (
"reflect"
"syscall"
"testing"
)

func TestLoadFile(t *testing.T) {
originalOpenFiles := numFilesOpen(t)

file, err := LoadFile("test.ini")
if err != nil {
t.Fatal(err)
}

if originalOpenFiles != numFilesOpen(t) {
t.Error("test.ini not closed")
}

if !reflect.DeepEqual(file, File{"default": {"stuff": "things"}}) {
t.Error("file not read correctly")
}
}

func numFilesOpen(t *testing.T) (num uint64) {
var rlimit syscall.Rlimit
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit)
if err != nil {
t.Fatal(err)
}
maxFds := int(rlimit.Cur)

var stat syscall.Stat_t
for i := 0; i < maxFds; i++ {
if syscall.Fstat(i, &stat) == nil {
num++
} else {
return
}
}
return
}
37 changes: 0 additions & 37 deletions ini_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ini
import (
"reflect"
"strings"
"syscall"
"testing"
)

Expand Down Expand Up @@ -88,39 +87,3 @@ func TestDefinedSectionBehaviour(t *testing.T) {
"a": {"this": "that"},
})
}

func TestLoadFile(t *testing.T) {
originalOpenFiles := numFilesOpen(t)

file, err := LoadFile("test.ini")
if err != nil {
t.Fatal(err)
}

if originalOpenFiles != numFilesOpen(t) {
t.Error("test.ini not closed")
}

if !reflect.DeepEqual(file, File{"default": {"stuff": "things"}}) {
t.Error("file not read correctly")
}
}

func numFilesOpen(t *testing.T) (num uint64) {
var rlimit syscall.Rlimit
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit)
if err != nil {
t.Fatal(err)
}
maxFds := int(rlimit.Cur)

var stat syscall.Stat_t
for i := 0; i < maxFds; i++ {
if syscall.Fstat(i, &stat) == nil {
num++
} else {
return
}
}
return
}

0 comments on commit 3c405a4

Please sign in to comment.