本文整理汇总了Golang中github.com/snapcore/snapd/asserts.Assertion.Revision方法的典型用法代码示例。如果您正苦于以下问题:Golang Assertion.Revision方法的具体用法?Golang Assertion.Revision怎么用?Golang Assertion.Revision使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/snapcore/snapd/asserts.Assertion
的用法示例。
在下文中一共展示了Assertion.Revision方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Add
// Add one assertion to the batch.
func (b *Batch) Add(a asserts.Assertion) error {
if err := b.bs.Put(a.Type(), a); err != nil {
if revErr, ok := err.(*asserts.RevisionError); ok {
if revErr.Current >= a.Revision() {
// we already got something more recent
return nil
}
}
return err
}
b.refs = append(b.refs, a.Ref())
return nil
}
示例2: TestSearchFormat
func (mbss *memBackstoreSuite) TestSearchFormat(c *C) {
bs := asserts.NewMemoryBackstore()
af0, err := asserts.Decode([]byte("type: test-only-2\n" +
"authority-id: auth-id1\n" +
"pk1: foo\n" +
"pk2: bar\n" +
"sign-key-sha3-384: Jv8_JiHiIzJVcO9M55pPdqSDWUvuhfDIBJUS-3VW7F_idjix7Ffn5qMxB21ZQuij" +
"\n\n" +
"AXNpZw=="))
c.Assert(err, IsNil)
af1, err := asserts.Decode([]byte("type: test-only-2\n" +
"authority-id: auth-id1\n" +
"pk1: foo\n" +
"pk2: bar\n" +
"format: 1\n" +
"revision: 1\n" +
"sign-key-sha3-384: Jv8_JiHiIzJVcO9M55pPdqSDWUvuhfDIBJUS-3VW7F_idjix7Ffn5qMxB21ZQuij" +
"\n\n" +
"AXNpZw=="))
c.Assert(err, IsNil)
af2, err := asserts.Decode([]byte("type: test-only-2\n" +
"authority-id: auth-id1\n" +
"pk1: foo\n" +
"pk2: baz\n" +
"format: 2\n" +
"revision: 1\n" +
"sign-key-sha3-384: Jv8_JiHiIzJVcO9M55pPdqSDWUvuhfDIBJUS-3VW7F_idjix7Ffn5qMxB21ZQuij" +
"\n\n" +
"AXNpZw=="))
c.Assert(err, IsNil)
err = bs.Put(asserts.TestOnly2Type, af0)
c.Assert(err, IsNil)
queries := []map[string]string{
{"pk1": "foo", "pk2": "bar"},
{"pk1": "foo"},
{"pk2": "bar"},
}
for _, q := range queries {
var a asserts.Assertion
foundCb := func(a1 asserts.Assertion) {
a = a1
}
err := bs.Search(asserts.TestOnly2Type, q, foundCb, 1)
c.Assert(err, IsNil)
c.Check(a.Revision(), Equals, 0)
}
err = bs.Put(asserts.TestOnly2Type, af1)
c.Assert(err, IsNil)
for _, q := range queries {
var a asserts.Assertion
foundCb := func(a1 asserts.Assertion) {
a = a1
}
err := bs.Search(asserts.TestOnly2Type, q, foundCb, 1)
c.Assert(err, IsNil)
c.Check(a.Revision(), Equals, 1)
err = bs.Search(asserts.TestOnly2Type, q, foundCb, 0)
c.Assert(err, IsNil)
c.Check(a.Revision(), Equals, 0)
}
err = bs.Put(asserts.TestOnly2Type, af2)
c.Assert(err, IsNil)
var as []asserts.Assertion
foundCb := func(a1 asserts.Assertion) {
as = append(as, a1)
}
err = bs.Search(asserts.TestOnly2Type, map[string]string{
"pk1": "foo",
}, foundCb, 1) // will not find af2
c.Assert(err, IsNil)
c.Check(as, HasLen, 1)
c.Check(as[0].Revision(), Equals, 1)
}