本文整理匯總了Golang中github.com/contiv/netplugin/core.StateDriver.ReadState方法的典型用法代碼示例。如果您正苦於以下問題:Golang StateDriver.ReadState方法的具體用法?Golang StateDriver.ReadState怎麽用?Golang StateDriver.ReadState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/contiv/netplugin/core.StateDriver
的用法示例。
在下文中一共展示了StateDriver.ReadState方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: commonTestStateDriverReadStateAfterUpdate
func commonTestStateDriverReadStateAfterUpdate(t *testing.T, d core.StateDriver) {
state := &testState{IntField: 1234, StrField: "testString"}
key := "testKeyReadUpdate"
err := d.WriteState(key, state, json.Marshal)
if err != nil {
t.Fatalf("failed to write state. Error: %s", err)
}
state.StrField = "testStringUpdated"
err = d.WriteState(key, state, json.Marshal)
if err != nil {
t.Fatalf("failed to update state. Error: %s", err)
}
readState := &testState{}
err = d.ReadState(key, readState, json.Unmarshal)
if err != nil {
t.Fatalf("failed to read state. Error: %s", err)
}
if readState.IntField != state.IntField || readState.StrField != state.StrField {
t.Fatalf("Read state didn't match state written. Wrote: %v Read: %v",
state, readState)
}
}
示例2: commonTestStateDriverReadStateAfterClear
func commonTestStateDriverReadStateAfterClear(t *testing.T, d core.StateDriver) {
state := &testState{IntField: 1234, StrField: "testString"}
key := "testKeyReadClear"
err := d.WriteState(key, state, json.Marshal)
if err != nil {
t.Fatalf("failed to write state. Error: %s", err)
}
err = d.ClearState(key)
if err != nil {
t.Fatalf("failed to clear state. Error: %s", err)
}
readState := &testState{}
err = d.ReadState(key, readState, json.Unmarshal)
if err == nil {
t.Fatalf("Able to read cleared state!. Key: %s, Value: %v",
key, readState)
}
}