github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/cmd/snap/cmd_delete_key_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 "encoding/json" 24 25 . "gopkg.in/check.v1" 26 27 snap "github.com/snapcore/snapd/cmd/snap" 28 ) 29 30 func (s *SnapKeysSuite) TestDeleteKeyRequiresName(c *C) { 31 _, err := snap.Parser(snap.Client()).ParseArgs([]string{"delete-key"}) 32 c.Assert(err, NotNil) 33 c.Check(err.Error(), Equals, "the required argument `<key-name>` was not provided") 34 c.Check(s.Stdout(), Equals, "") 35 c.Check(s.Stderr(), Equals, "") 36 } 37 38 func (s *SnapKeysSuite) TestDeleteKeyNonexistent(c *C) { 39 _, err := snap.Parser(snap.Client()).ParseArgs([]string{"delete-key", "nonexistent"}) 40 c.Assert(err, NotNil) 41 c.Check(err.Error(), Equals, "cannot find key named \"nonexistent\" in GPG keyring") 42 c.Check(s.Stdout(), Equals, "") 43 c.Check(s.Stderr(), Equals, "") 44 } 45 46 func (s *SnapKeysSuite) TestDeleteKey(c *C) { 47 rest, err := snap.Parser(snap.Client()).ParseArgs([]string{"delete-key", "another"}) 48 c.Assert(err, IsNil) 49 c.Assert(rest, DeepEquals, []string{}) 50 c.Check(s.Stdout(), Equals, "") 51 c.Check(s.Stderr(), Equals, "") 52 _, err = snap.Parser(snap.Client()).ParseArgs([]string{"keys", "--json"}) 53 c.Assert(err, IsNil) 54 expectedResponse := []snap.Key{ 55 { 56 Name: "default", 57 Sha3_384: "g4Pks54W_US4pZuxhgG_RHNAf_UeZBBuZyGRLLmMj1Do3GkE_r_5A5BFjx24ZwVJ", 58 }, 59 } 60 var obtainedResponse []snap.Key 61 json.Unmarshal(s.stdout.Bytes(), &obtainedResponse) 62 c.Check(obtainedResponse, DeepEquals, expectedResponse) 63 c.Check(s.Stderr(), Equals, "") 64 } 65 66 func (s *SnapKeysSuite) TestDeleteKeyExternalUnsupported(c *C) { 67 _, restore := mockNopExtKeyMgr(c) 68 defer restore() 69 70 _, err := snap.Parser(snap.Client()).ParseArgs([]string{"delete-key", "key"}) 71 c.Assert(err, NotNil) 72 c.Check(err.Error(), Equals, "cannot delete external keypair manager key via snap command, use the appropriate external procedure") 73 c.Check(s.Stdout(), Equals, "") 74 c.Check(s.Stderr(), Equals, "") 75 }