github.com/kubiko/snapd@v0.0.0-20201013125620-d4f3094d9ddf/cmd/snap/cmd_sign_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 "fmt" 24 "time" 25 26 . "gopkg.in/check.v1" 27 28 "github.com/snapcore/snapd/asserts" 29 30 snap "github.com/snapcore/snapd/cmd/snap" 31 ) 32 33 var statement = []byte(fmt.Sprintf(`{"type": "snap-build", 34 "authority-id": "devel1", 35 "series": "16", 36 "snap-id": "snapidsnapidsnapidsnapidsnapidsn", 37 "snap-sha3-384": "QlqR0uAWEAWF5Nwnzj5kqmmwFslYPu1IL16MKtLKhwhv0kpBv5wKZ_axf_nf_2cL", 38 "snap-size": "1", 39 "grade": "devel", 40 "timestamp": %q 41 }`, time.Now().Format(time.RFC3339))) 42 43 func (s *SnapKeysSuite) TestHappyDefaultKey(c *C) { 44 s.stdin.Write(statement) 45 46 rest, err := snap.Parser(snap.Client()).ParseArgs([]string{"sign"}) 47 c.Assert(err, IsNil) 48 c.Assert(rest, DeepEquals, []string{}) 49 50 a, err := asserts.Decode(s.stdout.Bytes()) 51 c.Assert(err, IsNil) 52 c.Check(a.Type(), Equals, asserts.SnapBuildType) 53 } 54 55 func (s *SnapKeysSuite) TestHappyNonDefaultKey(c *C) { 56 s.stdin.Write(statement) 57 58 rest, err := snap.Parser(snap.Client()).ParseArgs([]string{"sign", "-k", "another"}) 59 c.Assert(err, IsNil) 60 c.Assert(rest, DeepEquals, []string{}) 61 62 a, err := asserts.Decode(s.stdout.Bytes()) 63 c.Assert(err, IsNil) 64 c.Check(a.Type(), Equals, asserts.SnapBuildType) 65 }