From f7f90fe57fbf85111224c1468f8a12cc0fd193bf Mon Sep 17 00:00:00 2001 From: Faruk Kasumovic Date: Thu, 11 Jun 2015 00:51:46 +0200 Subject: [PATCH] - Pretty much completed set of examples and tests on 'pool' APIs implemented so far --- zpool.go | 7 +++++++ zpool_test.go | 28 +++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/zpool.go b/zpool.go index 0ef1c33..0fb98ba 100644 --- a/zpool.go +++ b/zpool.go @@ -136,6 +136,13 @@ func PoolPropertyToName(p PoolProp) (name string) { return } +// Map POOL STATE to string. +func PoolStateToName(state PoolState) (name string) { + ps := C.pool_state_t(state) + name = C.GoString(C.zpool_pool_state_to_name(ps)) + return +} + // Re-read ZFS pool properties and features, refresh Pool.Properties and // Pool.Features map func (pool *Pool) ReloadProperties() (err error) { diff --git a/zpool_test.go b/zpool_test.go index 43f6de5..5cc3079 100644 --- a/zpool_test.go +++ b/zpool_test.go @@ -227,6 +227,17 @@ func zpoolTestPoolProp(t *testing.T) { return } + // this test pool should not be bootable + prop, err := pool.GetProperty(zfs.PoolPropBootfs) + if err != nil { + t.Error(err) + return + } + if prop.Value != "-" { + t.Errorf("Failed at bootable fs property evaluation") + return + } + // fetch all properties if err = pool.ReloadProperties(); err != nil { t.Error(err) @@ -253,10 +264,12 @@ func zpoolTestPoolStatusAndState(t *testing.T) { return } - if _, err = pool.State(); err != nil { + var pstate zfs.PoolState + if pstate, err = pool.State(); err != nil { t.Error(err.Error()) return } + println("POOL", TST_POOL_NAME, "state:", zfs.PoolStateToName(pstate)) println("PASS\n") } @@ -412,3 +425,16 @@ func ExamplePool_ExportForce() { panic(err) } } + +func ExamplePool_State() { + p, err := zfs.PoolOpen("TESTPOOL") + if err != nil { + panic(err) + } + defer p.Close() + pstate, err := p.State() + if err != nil { + panic(err) + } + println("POOL TESTPOOL state:", zfs.PoolStateToName(pstate)) +}