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