github.com/rigado/snapd@v2.42.5-go-mod+incompatible/cmd/snap/cmd_version_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 "net/http" 25 26 . "gopkg.in/check.v1" 27 28 snap "github.com/snapcore/snapd/cmd/snap" 29 ) 30 31 func (s *SnapSuite) TestVersionCommandOnClassic(c *C) { 32 s.RedirectClientToTestServer(func(w http.ResponseWriter, r *http.Request) { 33 fmt.Fprintln(w, `{"type":"sync","status-code":200,"status":"OK","result":{"on-classic":true,"os-release":{"id":"ubuntu","version-id":"12.34"},"series":"56","version":"7.89"}}`) 34 }) 35 restore := mockArgs("snap", "version") 36 defer restore() 37 restore = mockVersion("4.56") 38 defer restore() 39 40 _, err := snap.Parser(snap.Client()).ParseArgs([]string{"version"}) 41 c.Assert(err, IsNil) 42 c.Assert(s.Stdout(), Equals, "snap 4.56\nsnapd 7.89\nseries 56\nubuntu 12.34\n") 43 c.Assert(s.Stderr(), Equals, "") 44 } 45 46 func (s *SnapSuite) TestVersionCommandOnAllSnap(c *C) { 47 s.RedirectClientToTestServer(func(w http.ResponseWriter, r *http.Request) { 48 fmt.Fprintln(w, `{"type":"sync","status-code":200,"status":"OK","result":{"os-release":{"id":"ubuntu","version-id":"12.34"},"series":"56","version":"7.89"}}`) 49 }) 50 restore := mockArgs("snap", "--version") 51 defer restore() 52 restore = mockVersion("4.56") 53 defer restore() 54 55 _, err := snap.Parser(snap.Client()).ParseArgs([]string{"version"}) 56 c.Assert(err, IsNil) 57 c.Assert(s.Stdout(), Equals, "snap 4.56\nsnapd 7.89\nseries 56\n") 58 c.Assert(s.Stderr(), Equals, "") 59 } 60 61 func (s *SnapSuite) TestVersionCommandOnClassicNoOsVersion(c *C) { 62 s.RedirectClientToTestServer(func(w http.ResponseWriter, r *http.Request) { 63 fmt.Fprintln(w, `{"type":"sync","status-code":200,"status":"OK","result":{"on-classic": true,"os-release":{"id":"arch","version-id":""},"series":"56","version":"7.89"}}`) 64 }) 65 restore := mockArgs("snap", "version") 66 defer restore() 67 restore = mockVersion("4.56") 68 defer restore() 69 70 _, err := snap.Parser(snap.Client()).ParseArgs([]string{"version"}) 71 c.Assert(err, IsNil) 72 c.Assert(s.Stdout(), Equals, "snap 4.56\nsnapd 7.89\nseries 56\narch -\n") 73 c.Assert(s.Stderr(), Equals, "") 74 }