本文整理汇总了Golang中github.com/snapcore/snapd/snap.R函数的典型用法代码示例。如果您正苦于以下问题:Golang R函数的具体用法?Golang R怎么用?Golang R使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了R函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestValidateRefreshesNoControl
func (s *assertMgrSuite) TestValidateRefreshesNoControl(c *C) {
s.state.Lock()
defer s.state.Unlock()
snapDeclFoo := s.snapDecl(c, "foo", nil)
snapDeclBar := s.snapDecl(c, "bar", nil)
s.stateFromDecl(snapDeclFoo, snap.R(7))
s.stateFromDecl(snapDeclBar, snap.R(3))
err := assertstate.Add(s.state, s.storeSigning.StoreAccountKey(""))
c.Assert(err, IsNil)
err = assertstate.Add(s.state, s.dev1Acct)
c.Assert(err, IsNil)
err = assertstate.Add(s.state, snapDeclFoo)
c.Assert(err, IsNil)
err = assertstate.Add(s.state, snapDeclBar)
c.Assert(err, IsNil)
fooRefresh := &snap.Info{
SideInfo: snap.SideInfo{RealName: "foo", SnapID: "foo-id", Revision: snap.R(9)},
}
validated, err := assertstate.ValidateRefreshes(s.state, []*snap.Info{fooRefresh}, 0)
c.Assert(err, IsNil)
c.Check(validated, DeepEquals, []*snap.Info{fooRefresh})
}
示例2: TestDoDiscardSnapErrorsForActive
func (s *discardSnapSuite) TestDoDiscardSnapErrorsForActive(c *C) {
s.state.Lock()
snapstate.Set(s.state, "foo", &snapstate.SnapState{
Sequence: []*snap.SideInfo{
{RealName: "foo", Revision: snap.R(3)},
},
Current: snap.R(3),
Active: true,
SnapType: "app",
})
t := s.state.NewTask("discard-snap", "test")
t.Set("snap-setup", &snapstate.SnapSetup{
SideInfo: &snap.SideInfo{
RealName: "foo",
Revision: snap.R(3),
},
})
chg := s.state.NewChange("dummy", "...")
chg.AddTask(t)
s.state.Unlock()
s.snapmgr.Ensure()
s.snapmgr.Wait()
s.state.Lock()
defer s.state.Unlock()
c.Check(chg.Status(), Equals, state.ErrorStatus)
c.Check(chg.Err(), ErrorMatches, `(?s).*internal error: cannot discard snap "foo": still active.*`)
}
示例3: TestDoDiscardSnapToEmpty
func (s *discardSnapSuite) TestDoDiscardSnapToEmpty(c *C) {
s.state.Lock()
snapstate.Set(s.state, "foo", &snapstate.SnapState{
Sequence: []*snap.SideInfo{
{RealName: "foo", Revision: snap.R(3)},
},
Current: snap.R(3),
SnapType: "app",
})
t := s.state.NewTask("discard-snap", "test")
t.Set("snap-setup", &snapstate.SnapSetup{
SideInfo: &snap.SideInfo{
RealName: "foo",
Revision: snap.R(33),
},
})
s.state.NewChange("dummy", "...").AddTask(t)
s.state.Unlock()
s.snapmgr.Ensure()
s.snapmgr.Wait()
s.state.Lock()
defer s.state.Unlock()
var snapst snapstate.SnapState
err := snapstate.Get(s.state, "foo", &snapst)
c.Assert(err, Equals, state.ErrNoState)
}
示例4: TestCopyDataDoUndoNoUserHomes
func (s *copydataSuite) TestCopyDataDoUndoNoUserHomes(c *C) {
// this home dir path does not exist
oldSnapDataHomeGlob := dirs.SnapDataHomeGlob
defer func() { dirs.SnapDataHomeGlob = oldSnapDataHomeGlob }()
dirs.SnapDataHomeGlob = filepath.Join(s.tempdir, "no-such-home", "*", "snap")
v1 := snaptest.MockSnap(c, helloYaml1, helloContents, &snap.SideInfo{Revision: snap.R(10)})
s.populateData(c, snap.R(10))
// pretend we install a new version
v2 := snaptest.MockSnap(c, helloYaml2, helloContents, &snap.SideInfo{Revision: snap.R(20)})
// copy data
err := s.be.CopySnapData(v2, v1, &s.nullProgress)
c.Assert(err, IsNil)
v2data := filepath.Join(dirs.SnapDataDir, "hello/20")
l, err := filepath.Glob(filepath.Join(v2data, "*"))
c.Assert(err, IsNil)
c.Assert(l, HasLen, 1)
err = s.be.UndoCopySnapData(v2, v1, &s.nullProgress)
c.Assert(err, IsNil)
// now removed
_, err = os.Stat(v2data)
c.Assert(os.IsNotExist(err), Equals, true)
}
示例5: TestAliasAutoAliasConflict
func (s *snapmgrTestSuite) TestAliasAutoAliasConflict(c *C) {
s.state.Lock()
defer s.state.Unlock()
snapstate.Set(s.state, "alias-snap", &snapstate.SnapState{
Sequence: []*snap.SideInfo{
{RealName: "alias-snap", Revision: snap.R(11)},
},
Current: snap.R(11),
Active: true,
})
s.state.Set("aliases", map[string]map[string]string{
"other-snap": {"alias1": "auto"},
})
chg := s.state.NewChange("alias", "enable an alias")
ts, err := snapstate.Alias(s.state, "alias-snap", []string{"alias1"})
c.Assert(err, IsNil)
chg.AddAll(ts)
s.state.Unlock()
s.snapmgr.Ensure()
s.snapmgr.Wait()
s.state.Lock()
c.Check(chg.Status(), Equals, state.ErrorStatus)
c.Check(chg.Err(), ErrorMatches, `(?s).*cannot enable alias "alias1" for "alias-snap", already enabled for "other-snap".*`)
}
示例6: TestAliasSnapCommandSpaceConflict
func (s *snapmgrTestSuite) TestAliasSnapCommandSpaceConflict(c *C) {
s.state.Lock()
defer s.state.Unlock()
snapstate.Set(s.state, "alias-snap", &snapstate.SnapState{
Sequence: []*snap.SideInfo{
{RealName: "alias-snap", Revision: snap.R(11)},
},
Current: snap.R(11),
Active: true,
})
// the command namespace of this one will conflict
snapstate.Set(s.state, "alias1", &snapstate.SnapState{
Sequence: []*snap.SideInfo{
{RealName: "alias1", Revision: snap.R(3)},
},
Current: snap.R(3),
})
chg := s.state.NewChange("alias", "enable an alias")
ts, err := snapstate.Alias(s.state, "alias-snap", []string{"alias1.cmd1"})
c.Assert(err, IsNil)
chg.AddAll(ts)
s.state.Unlock()
s.snapmgr.Ensure()
s.snapmgr.Wait()
s.state.Lock()
c.Check(chg.Status(), Equals, state.ErrorStatus)
c.Check(chg.Err(), ErrorMatches, `(?s).*cannot enable alias "alias1.cmd1" for "alias-snap", it conflicts with the command namespace of installed snap "alias1".*`)
}
示例7: TestDoUndoSetAutoAliases
func (s *snapmgrTestSuite) TestDoUndoSetAutoAliases(c *C) {
s.state.Lock()
defer s.state.Unlock()
snapstate.AutoAliases = func(st *state.State, info *snap.Info) ([]string, error) {
c.Check(info.Name(), Equals, "alias-snap")
return []string{"alias1", "alias2", "alias4", "alias5"}, nil
}
snapstate.Set(s.state, "alias-snap", &snapstate.SnapState{
Sequence: []*snap.SideInfo{
{RealName: "alias-snap", Revision: snap.R(11)},
},
Current: snap.R(11),
Active: true,
})
s.state.Set("aliases", map[string]map[string]string{
"alias-snap": {
"alias1": "enabled",
"alias2": "auto",
"alias3": "auto",
"alias5": "disabled",
},
})
t := s.state.NewTask("set-auto-aliases", "test")
t.Set("snap-setup", &snapstate.SnapSetup{
SideInfo: &snap.SideInfo{RealName: "alias-snap"},
})
chg := s.state.NewChange("dummy", "...")
chg.AddTask(t)
terr := s.state.NewTask("error-trigger", "provoking total undo")
terr.WaitFor(t)
chg.AddTask(terr)
s.state.Unlock()
for i := 0; i < 3; i++ {
s.snapmgr.Ensure()
s.snapmgr.Wait()
}
s.state.Lock()
c.Check(t.Status(), Equals, state.UndoneStatus, Commentf("%v", chg.Err()))
var allAliases map[string]map[string]string
err := s.state.Get("aliases", &allAliases)
c.Assert(err, IsNil)
c.Check(allAliases, DeepEquals, map[string]map[string]string{
"alias-snap": {
"alias1": "enabled",
"alias2": "auto",
"alias3": "auto",
"alias5": "disabled",
},
})
}
示例8: TestAliasNoAlias
func (s *snapmgrTestSuite) TestAliasNoAlias(c *C) {
s.state.Lock()
defer s.state.Unlock()
snapstate.Set(s.state, "some-snap", &snapstate.SnapState{
Sequence: []*snap.SideInfo{
{RealName: "some-snap", Revision: snap.R(11)},
},
Current: snap.R(11),
Active: true,
})
chg := s.state.NewChange("alias", "enable an alias")
ts, err := snapstate.Alias(s.state, "some-snap", []string{"alias1"})
c.Assert(err, IsNil)
chg.AddAll(ts)
s.state.Unlock()
s.snapmgr.Ensure()
s.snapmgr.Wait()
s.state.Lock()
c.Check(chg.Status(), Equals, state.ErrorStatus)
c.Check(chg.Err(), ErrorMatches, `(?s).*cannot enable alias "alias1" for "some-snap", no such alias.*`)
}
示例9: TestYAML
func (s revisionSuite) TestYAML(c *C) {
for _, v := range []struct {
n int
s string
}{
{0, "unset"},
{10, `"10"`},
{-9, "x9"},
} {
r := snap.R(v.n)
data, err := yaml.Marshal(snap.R(v.n))
c.Assert(err, IsNil)
c.Assert(string(data), Equals, v.s+"\n")
var got snap.Revision
err = yaml.Unmarshal(data, &got)
c.Assert(err, IsNil)
c.Assert(got, Equals, r)
got = snap.Revision{}
err = json.Unmarshal([]byte(strconv.Itoa(r.N)), &got)
c.Assert(err, IsNil)
c.Assert(got, Equals, r)
}
}
示例10: TestCopyDataNoUserHomes
// ensure that even with no home dir there is no error and the
// system data gets copied
func (s *copydataSuite) TestCopyDataNoUserHomes(c *C) {
// this home dir path does not exist
oldSnapDataHomeGlob := dirs.SnapDataHomeGlob
defer func() { dirs.SnapDataHomeGlob = oldSnapDataHomeGlob }()
dirs.SnapDataHomeGlob = filepath.Join(s.tempdir, "no-such-home", "*", "snap")
v1 := snaptest.MockSnap(c, helloYaml1, helloContents, &snap.SideInfo{Revision: snap.R(10)})
err := s.be.CopySnapData(v1, nil, &s.nullProgress)
c.Assert(err, IsNil)
canaryDataFile := filepath.Join(v1.DataDir(), "canary.txt")
err = ioutil.WriteFile(canaryDataFile, []byte(""), 0644)
c.Assert(err, IsNil)
canaryDataFile = filepath.Join(v1.CommonDataDir(), "canary.common")
err = ioutil.WriteFile(canaryDataFile, []byte(""), 0644)
c.Assert(err, IsNil)
v2 := snaptest.MockSnap(c, helloYaml2, helloContents, &snap.SideInfo{Revision: snap.R(20)})
err = s.be.CopySnapData(v2, v1, &s.nullProgress)
c.Assert(err, IsNil)
_, err = os.Stat(filepath.Join(v2.DataDir(), "canary.txt"))
c.Assert(err, IsNil)
_, err = os.Stat(filepath.Join(v2.CommonDataDir(), "canary.common"))
c.Assert(err, IsNil)
// sanity atm
c.Check(v1.DataDir(), Not(Equals), v2.DataDir())
c.Check(v1.CommonDataDir(), Equals, v2.CommonDataDir())
}
示例11: TestDoLinkSnapSuccess
func (s *linkSnapSuite) TestDoLinkSnapSuccess(c *C) {
s.state.Lock()
t := s.state.NewTask("link-snap", "test")
t.Set("snap-setup", &snapstate.SnapSetup{
SideInfo: &snap.SideInfo{
RealName: "foo",
Revision: snap.R(33),
},
Channel: "beta",
})
s.state.NewChange("dummy", "...").AddTask(t)
s.state.Unlock()
s.snapmgr.Ensure()
s.snapmgr.Wait()
s.state.Lock()
defer s.state.Unlock()
var snapst snapstate.SnapState
err := snapstate.Get(s.state, "foo", &snapst)
c.Assert(err, IsNil)
typ, err := snapst.Type()
c.Check(err, IsNil)
c.Check(typ, Equals, snap.TypeApp)
c.Check(snapst.Active, Equals, true)
c.Check(snapst.Sequence, HasLen, 1)
c.Check(snapst.Current, Equals, snap.R(33))
c.Check(snapst.Channel, Equals, "beta")
c.Check(t.Status(), Equals, state.DoneStatus)
c.Check(s.stateBackend.restartRequested, Equals, false)
}
示例12: TestCopyDataDoUndoABA
func (s *copydataSuite) TestCopyDataDoUndoABA(c *C) {
v1 := snaptest.MockSnap(c, helloYaml1, helloContents, &snap.SideInfo{Revision: snap.R(10)})
s.populateData(c, snap.R(10))
c.Check(s.populatedData("10"), Equals, "10\n")
// pretend we install a new version
v2 := snaptest.MockSnap(c, helloYaml2, helloContents, &snap.SideInfo{Revision: snap.R(20)})
// and write our own data to it
s.populateData(c, snap.R(20))
c.Check(s.populatedData("20"), Equals, "20\n")
// and now we pretend to refresh back to v1 (r10)
c.Check(s.be.CopySnapData(v1, v2, &s.nullProgress), IsNil)
// so v1 (r10) now has v2 (r20)'s data and we have trash
c.Check(s.populatedData("10"), Equals, "20\n")
c.Check(s.populatedData("10.old"), Equals, "10\n")
// but oh no! we have to undo it!
c.Check(s.be.UndoCopySnapData(v1, v2, &s.nullProgress), IsNil)
// so now v1 (r10) has v1 (r10)'s data and v2 (r20) has v2 (r20)'s data and we have no trash
c.Check(s.populatedData("10"), Equals, "10\n")
c.Check(s.populatedData("20"), Equals, "20\n")
c.Check(s.populatedData("10.old"), Equals, "")
}
示例13: TestCopyDataDoIdempotent
func (s *copydataSuite) TestCopyDataDoIdempotent(c *C) {
// make sure that a retry wouldn't stumble on partial work
v1 := snaptest.MockSnap(c, helloYaml1, helloContents, &snap.SideInfo{Revision: snap.R(10)})
s.populateData(c, snap.R(10))
homedir := s.populateHomeData(c, "user1", snap.R(10))
// pretend we install a new version
v2 := snaptest.MockSnap(c, helloYaml2, helloContents, &snap.SideInfo{Revision: snap.R(20)})
// copy data
err := s.be.CopySnapData(v2, v1, &s.nullProgress)
c.Assert(err, IsNil)
err = s.be.CopySnapData(v2, v1, &s.nullProgress)
c.Assert(err, IsNil)
v2data := filepath.Join(dirs.SnapDataDir, "hello/20")
l, err := filepath.Glob(filepath.Join(v2data, "*"))
c.Assert(err, IsNil)
c.Assert(l, HasLen, 1)
v2HomeData := filepath.Join(homedir, "hello/20")
l, err = filepath.Glob(filepath.Join(v2HomeData, "*"))
c.Assert(err, IsNil)
c.Assert(l, HasLen, 1)
}
示例14: TestDoUndoMountSnap
func (s *mountSnapSuite) TestDoUndoMountSnap(c *C) {
v1 := "name: core\nversion: 1.0\n"
testSnap := snaptest.MakeTestSnapWithFiles(c, v1, nil)
s.state.Lock()
defer s.state.Unlock()
si1 := &snap.SideInfo{
RealName: "core",
Revision: snap.R(1),
}
si2 := &snap.SideInfo{
RealName: "core",
Revision: snap.R(2),
}
snapstate.Set(s.state, "core", &snapstate.SnapState{
Sequence: []*snap.SideInfo{si1},
Current: si1.Revision,
SnapType: "os",
})
t := s.state.NewTask("mount-snap", "test")
t.Set("snap-setup", &snapstate.SnapSetup{
SideInfo: si2,
SnapPath: testSnap,
})
chg := s.state.NewChange("dummy", "...")
chg.AddTask(t)
terr := s.state.NewTask("error-trigger", "provoking total undo")
terr.WaitFor(t)
chg.AddTask(terr)
s.state.Unlock()
for i := 0; i < 3; i++ {
s.snapmgr.Ensure()
s.snapmgr.Wait()
}
s.state.Lock()
// ensure undo was called the right way
c.Check(s.fakeBackend.ops, DeepEquals, fakeOps{
{
op: "current",
old: "/snap/core/1",
},
{
op: "setup-snap",
name: testSnap,
revno: snap.R(2),
},
{
op: "undo-setup-snap",
name: "/snap/core/2",
stype: "os",
},
})
}
示例15: TestCopyDataUndoIdempotent
func (s *copydataSuite) TestCopyDataUndoIdempotent(c *C) {
// make sure that a retry wouldn't stumble on partial work
v1 := snaptest.MockSnap(c, helloYaml1, helloContents, &snap.SideInfo{Revision: snap.R(10)})
s.populateData(c, snap.R(10))
homedir := s.populateHomeData(c, "user1", snap.R(10))
// pretend we install a new version
v2 := snaptest.MockSnap(c, helloYaml2, helloContents, &snap.SideInfo{Revision: snap.R(20)})
// copy data
err := s.be.CopySnapData(v2, v1, &s.nullProgress)
c.Assert(err, IsNil)
v2data := filepath.Join(dirs.SnapDataDir, "hello/20")
err = s.be.UndoCopySnapData(v2, v1, &s.nullProgress)
c.Assert(err, IsNil)
err = s.be.UndoCopySnapData(v2, v1, &s.nullProgress)
c.Assert(err, IsNil)
// now removed
_, err = os.Stat(v2data)
c.Assert(os.IsNotExist(err), Equals, true)
v2HomeData := filepath.Join(homedir, "hello/20")
_, err = os.Stat(v2HomeData)
c.Assert(os.IsNotExist(err), Equals, true)
}