github.com/rigado/snapd@v2.42.5-go-mod+incompatible/overlord/snapstate/aux_store_info_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2018 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package snapstate_test 21 22 import ( 23 "path/filepath" 24 25 "gopkg.in/check.v1" 26 27 "github.com/snapcore/snapd/dirs" 28 "github.com/snapcore/snapd/osutil" 29 "github.com/snapcore/snapd/overlord/snapstate" 30 "github.com/snapcore/snapd/snap" 31 ) 32 33 type auxInfoSuite struct{} 34 35 var _ = check.Suite(&auxInfoSuite{}) 36 37 func (s *auxInfoSuite) SetUpTest(c *check.C) { 38 dirs.SetRootDir(c.MkDir()) 39 } 40 41 func (s *auxInfoSuite) TestAuxStoreInfoFilename(c *check.C) { 42 // sanity check 43 filename := snapstate.AuxStoreInfoFilename("some-snap-id") 44 c.Check(filename, check.Equals, filepath.Join(dirs.SnapAuxStoreInfoDir, "some-snap-id.json")) 45 } 46 47 func (s *auxInfoSuite) TestAuxStoreInfoRoundTrip(c *check.C) { 48 media := snap.MediaInfos{{Type: "1-2-3-testing"}} 49 info := &snap.Info{SuggestedName: "some-snap"} 50 info.SnapID = "some-id" 51 filename := snapstate.AuxStoreInfoFilename(info.SnapID) 52 c.Assert(osutil.FileExists(filename), check.Equals, false) 53 c.Check(snapstate.RetrieveAuxStoreInfo(info), check.IsNil) 54 c.Check(info.Media, check.HasLen, 0) 55 56 c.Assert(snapstate.KeepAuxStoreInfo(info.SnapID, &snapstate.AuxStoreInfo{Media: media}), check.IsNil) 57 c.Check(osutil.FileExists(filename), check.Equals, true) 58 59 c.Assert(snapstate.RetrieveAuxStoreInfo(info), check.IsNil) 60 c.Check(info.Media, check.HasLen, 1) 61 c.Check(info.Media, check.DeepEquals, media) 62 info.Media = nil 63 64 c.Assert(snapstate.DiscardAuxStoreInfo(info.SnapID), check.IsNil) 65 c.Assert(osutil.FileExists(filename), check.Equals, false) 66 67 c.Check(snapstate.RetrieveAuxStoreInfo(info), check.IsNil) 68 c.Check(info.Media, check.HasLen, 0) 69 70 c.Check(snapstate.DiscardAuxStoreInfo(info.SnapID), check.IsNil) 71 }