github.com/david-imola/snapd@v0.0.0-20210611180407-2de8ddeece6d/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 c.Check(info.Website, check.Equals, "") 56 c.Check(info.StoreURL, check.Equals, "") 57 58 aux := &snapstate.AuxStoreInfo{ 59 Media: media, 60 Website: "http://example.com/some-snap", 61 StoreURL: "https://snapcraft.io/some-snap", 62 } 63 c.Assert(snapstate.KeepAuxStoreInfo(info.SnapID, aux), check.IsNil) 64 c.Check(osutil.FileExists(filename), check.Equals, true) 65 66 c.Assert(snapstate.RetrieveAuxStoreInfo(info), check.IsNil) 67 c.Check(info.Media, check.HasLen, 1) 68 c.Check(info.Media, check.DeepEquals, media) 69 c.Check(info.Website, check.Equals, "http://example.com/some-snap") 70 c.Check(info.StoreURL, check.Equals, "https://snapcraft.io/some-snap") 71 info.Media = nil 72 info.Website = "" 73 info.StoreURL = "" 74 75 c.Assert(snapstate.DiscardAuxStoreInfo(info.SnapID), check.IsNil) 76 c.Assert(osutil.FileExists(filename), check.Equals, false) 77 78 c.Check(snapstate.RetrieveAuxStoreInfo(info), check.IsNil) 79 c.Check(info.Media, check.HasLen, 0) 80 c.Check(info.Website, check.Equals, "") 81 c.Check(info.StoreURL, check.Equals, "") 82 83 c.Check(snapstate.DiscardAuxStoreInfo(info.SnapID), check.IsNil) 84 }