Skip to content

Commit

Permalink
Merge pull request #6131 from chipaca/kill-current
Browse files Browse the repository at this point in the history
store:  remove unused currentSnap and currentSnapJSON
  • Loading branch information
zyga authored Nov 13, 2018
2 parents 48b4c6c + e2c504d commit eedf964
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 136 deletions.
4 changes: 0 additions & 4 deletions store/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ var (
UseDeltas = useDeltas
ApplyDelta = applyDelta

// FIXME: there is a name clash, store has both "currentSnap"
// and "CurrentSnap" which do different things.
GetCurrentSnap = currentSnap

AuthLocation = authLocation
AuthURL = authURL
StoreURL = storeURL
Expand Down
39 changes: 0 additions & 39 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1272,45 +1272,6 @@ type RefreshCandidate struct {
Amend bool
}

// the exact bits that we need to send to the store
type currentSnapJSON struct {
SnapID string `json:"snap_id"`
Channel string `json:"channel"`
Revision int `json:"revision,omitempty"`
Epoch snap.Epoch `json:"epoch"`
Confinement string `json:"confinement"`
IgnoreValidation bool `json:"ignore_validation,omitempty"`
}

func currentSnap(cs *RefreshCandidate) *currentSnapJSON {
// the store gets confused if we send snaps without a snapid
// (like local ones)
if cs.SnapID == "" {
if cs.Revision.Store() {
logger.Noticef("store.currentSnap got given a RefreshCandidate with an empty SnapID but a store revision!")
}
return nil
}
if !cs.Revision.Store() && !cs.Amend {
logger.Noticef("store.currentSnap got given a RefreshCandidate with a non-empty SnapID but a non-store revision!")
return nil
}

channel := cs.Channel
if channel == "" {
channel = "stable"
}

return &currentSnapJSON{
SnapID: cs.SnapID,
Channel: channel,
Epoch: cs.Epoch,
Revision: cs.Revision.N,
IgnoreValidation: cs.IgnoreValidation,
// confinement purposely left empty
}
}

func findRev(needle snap.Revision, haystack []snap.Revision) bool {
for _, r := range haystack {
if needle == r {
Expand Down
93 changes: 0 additions & 93 deletions store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2960,99 +2960,6 @@ func (s *storeTestSuite) TestFindCommonIDs(c *C) {
c.Check(infos[0].CommonIDs, DeepEquals, []string{"org.hello"})
}

func (s *storeTestSuite) TestCurrentSnap(c *C) {
cand := &store.RefreshCandidate{
SnapID: helloWorldSnapID,
Channel: "stable",
Revision: snap.R(1),
Epoch: *snap.E("1"),
}
cs := store.GetCurrentSnap(cand)
c.Assert(cs, NotNil)
c.Check(cs.SnapID, Equals, cand.SnapID)
c.Check(cs.Channel, Equals, cand.Channel)
c.Check(cs.Epoch, DeepEquals, cand.Epoch)
c.Check(cs.Revision, Equals, cand.Revision.N)
c.Check(cs.IgnoreValidation, Equals, cand.IgnoreValidation)
c.Check(s.logbuf.String(), Equals, "")
}

func (s *storeTestSuite) TestCurrentSnapIgnoreValidation(c *C) {
cand := &store.RefreshCandidate{
SnapID: helloWorldSnapID,
Channel: "stable",
Revision: snap.R(1),
Epoch: *snap.E("1"),
IgnoreValidation: true,
}
cs := store.GetCurrentSnap(cand)
c.Assert(cs, NotNil)
c.Check(cs.SnapID, Equals, cand.SnapID)
c.Check(cs.Channel, Equals, cand.Channel)
c.Check(cs.Epoch, DeepEquals, cand.Epoch)
c.Check(cs.Revision, Equals, cand.Revision.N)
c.Check(cs.IgnoreValidation, Equals, cand.IgnoreValidation)
c.Check(s.logbuf.String(), Equals, "")
}

func (s *storeTestSuite) TestCurrentSnapNoChannel(c *C) {
cand := &store.RefreshCandidate{
SnapID: helloWorldSnapID,
Revision: snap.R(1),
Epoch: *snap.E("1"),
}
cs := store.GetCurrentSnap(cand)
c.Assert(cs, NotNil)
c.Check(cs.SnapID, Equals, cand.SnapID)
c.Check(cs.Channel, Equals, "stable")
c.Check(cs.Epoch, DeepEquals, cand.Epoch)
c.Check(cs.Revision, Equals, cand.Revision.N)
c.Check(s.logbuf.String(), Equals, "")
}

func (s *storeTestSuite) TestCurrentSnapNilNoID(c *C) {
cand := &store.RefreshCandidate{
SnapID: "",
Revision: snap.R(1),
}
cs := store.GetCurrentSnap(cand)
c.Assert(cs, IsNil)
c.Check(s.logbuf.String(), Matches, "(?m).* an empty SnapID but a store revision!")
}

func (s *storeTestSuite) TestCurrentSnapNilLocalRevision(c *C) {
cand := &store.RefreshCandidate{
SnapID: helloWorldSnapID,
Revision: snap.R("x1"),
}
cs := store.GetCurrentSnap(cand)
c.Assert(cs, IsNil)
c.Check(s.logbuf.String(), Matches, "(?m).* a non-empty SnapID but a non-store revision!")
}

func (s *storeTestSuite) TestCurrentSnapNilLocalRevisionNoID(c *C) {
cand := &store.RefreshCandidate{
SnapID: "",
Revision: snap.R("x1"),
}
cs := store.GetCurrentSnap(cand)
c.Assert(cs, IsNil)
c.Check(s.logbuf.String(), Equals, "")
}

func (s *storeTestSuite) TestCurrentSnapRevLocalRevWithAmendHappy(c *C) {
cand := &store.RefreshCandidate{
SnapID: helloWorldSnapID,
Revision: snap.R("x1"),
Amend: true,
}
cs := store.GetCurrentSnap(cand)
c.Assert(cs, NotNil)
c.Check(cs.SnapID, Equals, cand.SnapID)
c.Check(cs.Revision, Equals, cand.Revision.N)
c.Check(s.logbuf.String(), Equals, "")
}

func (s *storeTestSuite) TestAuthLocationDependsOnEnviron(c *C) {
c.Assert(os.Setenv("SNAPPY_USE_STAGING_STORE", ""), IsNil)
before := store.AuthLocation()
Expand Down

0 comments on commit eedf964

Please sign in to comment.