mirror of
https://github.com/dutchcoders/transfer.sh.git
synced 2024-12-13 14:20:18 +01:00
cb6e5cb0c7
* use dep for vendoring * lets encrypt * moved web to transfer.sh-web repo * single command install * added first tests
43 lines
730 B
Go
43 lines
730 B
Go
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
|
|
}
|