github.com/kubiko/snapd@v0.0.0-20201013125620-d4f3094d9ddf/cmd/snap/notes_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2016 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 main_test 21 22 import ( 23 "gopkg.in/check.v1" 24 25 "github.com/snapcore/snapd/client" 26 snap "github.com/snapcore/snapd/cmd/snap" 27 ) 28 29 type notesSuite struct{} 30 31 var _ = check.Suite(¬esSuite{}) 32 33 func (notesSuite) TestNoNotes(c *check.C) { 34 c.Check((&snap.Notes{}).String(), check.Equals, "-") 35 } 36 37 func (notesSuite) TestNotesPrice(c *check.C) { 38 c.Check((&snap.Notes{ 39 Price: "3.50GBP", 40 }).String(), check.Equals, "3.50GBP") 41 } 42 43 func (notesSuite) TestNotesPrivate(c *check.C) { 44 c.Check((&snap.Notes{ 45 Private: true, 46 }).String(), check.Equals, "private") 47 } 48 49 func (notesSuite) TestNotesDevMode(c *check.C) { 50 c.Check((&snap.Notes{ 51 DevMode: true, 52 }).String(), check.Equals, "devmode") 53 } 54 55 func (notesSuite) TestNotesJailMode(c *check.C) { 56 c.Check((&snap.Notes{ 57 JailMode: true, 58 }).String(), check.Equals, "jailmode") 59 } 60 61 func (notesSuite) TestNotesClassic(c *check.C) { 62 c.Check((&snap.Notes{ 63 Classic: true, 64 }).String(), check.Equals, "classic") 65 } 66 67 func (notesSuite) TestNotesTryMode(c *check.C) { 68 c.Check((&snap.Notes{ 69 TryMode: true, 70 }).String(), check.Equals, "try") 71 } 72 73 func (notesSuite) TestNotesDisabled(c *check.C) { 74 c.Check((&snap.Notes{ 75 Disabled: true, 76 }).String(), check.Equals, "disabled") 77 } 78 79 func (notesSuite) TestNotesBroken(c *check.C) { 80 c.Check((&snap.Notes{ 81 Broken: true, 82 }).String(), check.Equals, "broken") 83 } 84 85 func (notesSuite) TestNotesIgnoreValidation(c *check.C) { 86 c.Check((&snap.Notes{ 87 IgnoreValidation: true, 88 }).String(), check.Equals, "ignore-validation") 89 } 90 91 func (notesSuite) TestNotesInCohort(c *check.C) { 92 c.Check((&snap.Notes{ 93 InCohort: true, 94 }).String(), check.Equals, "in-cohort") 95 } 96 97 func (notesSuite) TestNotesNothing(c *check.C) { 98 c.Check((&snap.Notes{}).String(), check.Equals, "-") 99 } 100 101 func (notesSuite) TestNotesTwo(c *check.C) { 102 c.Check((&snap.Notes{ 103 DevMode: true, 104 Broken: true, 105 }).String(), check.Matches, "(devmode,broken|broken,devmode)") 106 } 107 108 func (notesSuite) TestNotesFromLocal(c *check.C) { 109 // Check that DevMode note is derived from DevMode flag, not DevModeConfinement type. 110 c.Check(snap.NotesFromLocal(&client.Snap{DevMode: true}).DevMode, check.Equals, true) 111 c.Check(snap.NotesFromLocal(&client.Snap{Confinement: client.DevModeConfinement}).DevMode, check.Equals, false) 112 c.Check(snap.NotesFromLocal(&client.Snap{IgnoreValidation: true}).IgnoreValidation, check.Equals, true) 113 // check that a cohort key in a snap sets the InCohort note flag 114 c.Check(snap.NotesFromLocal(&client.Snap{CohortKey: ""}).InCohort, check.Equals, false) 115 c.Check(snap.NotesFromLocal(&client.Snap{CohortKey: "123"}).InCohort, check.Equals, true) 116 c.Check(snap.NotesFromLocal(&client.Snap{Health: &client.SnapHealth{Status: "blocked"}}).Health, check.Equals, "blocked") 117 }