diff options
author | Marius Halden <marius.h@lden.org> | 2019-02-26 02:06:19 +0100 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2019-02-26 02:06:19 +0100 |
commit | 51ffcda86f2417fe929fdaabad2903dfcad523f5 (patch) | |
tree | 1221ac180cdd68552a1f3a4c69697ea63eaf4954 | |
parent | ca0043ccc98a575daade3197b22e321a7d3ad945 (diff) | |
download | gojail-51ffcda86f2417fe929fdaabad2903dfcad523f5.tar.gz gojail-51ffcda86f2417fe929fdaabad2903dfcad523f5.tar.bz2 gojail-51ffcda86f2417fe929fdaabad2903dfcad523f5.tar.xz |
Add test for get
-rw-r--r-- | jail.go | 11 | ||||
-rw-r--r-- | jail_test.go | 35 |
2 files changed, 40 insertions, 6 deletions
@@ -36,6 +36,7 @@ package jail // } import "C" import "errors" +import "fmt" import "unsafe" const ( @@ -87,8 +88,6 @@ func mapToIov(params map[string]interface{}) (unsafe.Pointer, int, []unsafe.Poin i++ } - //C.print_iov((*C.struct_iovec)(iov), C.int(len(params)*2)) - return iov, len(params)*2, freeList } @@ -102,19 +101,19 @@ func iovToMap(iov unsafe.Pointer, niov int, params map[string]interface{}) { key = (*C.char)(C.get_iov_field((*C.struct_iovec)(iov), C.int(i+0), &key_len)) val = C.get_iov_field((*C.struct_iovec)(iov), C.int(i+1), &val_len) - go_key := C.GoStringN(key, C.int(key_len)) - if v, ok := params[go_key]; !ok { + go_key := C.GoString(key) + if v, ok := params[go_key]; ok { if _, ok := v.(int); ok { params[go_key] = int(*(*C.int)(val)) } else if _, ok := v.(string); ok { - params[go_key] = C.GoStringN((*C.char)(val), C.int(val_len)) + params[go_key] = C.GoString((*C.char)(val)) } else if _, ok := v.(bool); ok { // XXX: noop for now } else { panic("Got unknown type from kernel") } } else { - panic("Got unknown key from kernel") + panic(fmt.Sprintf("Got unknown key from kernel: %v", go_key)) } } } diff --git a/jail_test.go b/jail_test.go index 1967175..72e9fa3 100644 --- a/jail_test.go +++ b/jail_test.go @@ -33,6 +33,41 @@ func TestRemove(t *testing.T) { } } +func TestGet(t *testing.T) { + params := make(map[string]interface{}) + params["name"] = "test_get" + params["path"] = "/" + params["persist"] = true + + jid, err := Set(params, JAIL_CREATE) + if err != nil { + t.Error("Failed to create jail: ", err.Error()) + } + + delete(params, "persist") + params["name"] = " " + params["path"] = " " + params["jid"] = jid + + jid, err = Get(params, 0) + if err != nil { + t.Error("Failed to get jail info: ", err.Error()) + } + + if params["name"] != "test_get" { + t.Error("Wrong name: ", params["name"]) + } + + if params["path"] != "/" { + t.Error("Wrong path: ", params["path"]) + } + + err = Remove(jid) + if err != nil { + t.Error("Failed to remove jail: ", err.Error()) + } +} + func TestCreate(t *testing.T) { params := make(map[string]interface{}) params["name"] = "test_create" |