本文整理匯總了Golang中github.com/docker/swarmkit/api.MaybeEncryptedRecord.Unmarshal方法的典型用法代碼示例。如果您正苦於以下問題:Golang MaybeEncryptedRecord.Unmarshal方法的具體用法?Golang MaybeEncryptedRecord.Unmarshal怎麽用?Golang MaybeEncryptedRecord.Unmarshal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/docker/swarmkit/api.MaybeEncryptedRecord
的用法示例。
在下文中一共展示了MaybeEncryptedRecord.Unmarshal方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestSnapshotterSavesSnapshotWithEncryption
// The snapshot data (but not metadata or anything else) is encryptd before being
// passed to the wrapped Snapshotter.
func TestSnapshotterSavesSnapshotWithEncryption(t *testing.T) {
tempdir, err := ioutil.TempDir("", "snapwrap")
require.NoError(t, err)
defer os.RemoveAll(tempdir)
c := NewSnapFactory(meowCrypter{}, encryption.NoopCrypter)
wrapped := c.New(tempdir)
require.NoError(t, wrapped.SaveSnap(fakeSnapshotData))
ogSnap := OriginalSnap.New(tempdir)
readSnap, err := ogSnap.Load()
require.NoError(t, err)
r := api.MaybeEncryptedRecord{}
require.NoError(t, r.Unmarshal(readSnap.Data))
require.NotEqual(t, fakeSnapshotData.Data, r.Data)
require.Equal(t, fakeSnapshotData.Metadata, readSnap.Metadata)
}
示例2: TestSave
// The entry data and metadata are encryptd with the given encrypter, and a regular
// WAL will see them as such.
func TestSave(t *testing.T) {
metadata, entries, snapshot := makeWALData(1, 1)
crypter := &meowCrypter{}
c := NewWALFactory(crypter, encryption.NoopCrypter)
tempdir := createWithWAL(t, c, metadata, snapshot, entries)
defer os.RemoveAll(tempdir)
ogWAL, err := OriginalWAL.Open(tempdir, snapshot)
require.NoError(t, err)
defer ogWAL.Close()
meta, state, ents, err := ogWAL.ReadAll()
require.NoError(t, err)
require.Equal(t, metadata, meta)
require.Equal(t, state, state)
for _, ent := range ents {
var encrypted api.MaybeEncryptedRecord
require.NoError(t, encrypted.Unmarshal(ent.Data))
require.Equal(t, crypter.Algorithm(), encrypted.Algorithm)
require.True(t, bytes.HasSuffix(encrypted.Data, []byte("🐱")))
}
}