github.com/bugraaydogar/snapd@v0.0.0-20210315170335-8c70bb858939/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  	"github.com/snapcore/snapd/snapdtool"
    30  )
    31  
    32  func (s *SnapSuite) TestVersionCommandOnClassic(c *C) {
    33  	s.RedirectClientToTestServer(func(w http.ResponseWriter, r *http.Request) {
    34  		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","architecture":"ia64"}}`)
    35  	})
    36  	restore := mockArgs("snap", "version")
    37  	defer restore()
    38  	restore = snapdtool.MockVersion("4.56")
    39  	defer restore()
    40  
    41  	_, err := snap.Parser(snap.Client()).ParseArgs([]string{"version"})
    42  	c.Assert(err, IsNil)
    43  	c.Assert(s.Stdout(), Equals, "snap    4.56\nsnapd   7.89\nseries  56\nubuntu  12.34\n")
    44  	c.Assert(s.Stderr(), Equals, "")
    45  }
    46  
    47  func (s *SnapSuite) TestVersionCommandOnAllSnap(c *C) {
    48  	s.RedirectClientToTestServer(func(w http.ResponseWriter, r *http.Request) {
    49  		fmt.Fprintln(w, `{"type":"sync","status-code":200,"status":"OK","result":{"os-release":{"id":"ubuntu","version-id":"12.34"},"series":"56","version":"7.89","architecture":"powerpc","virtualization":"qemu"}}`)
    50  	})
    51  	restore := mockArgs("snap", "--version")
    52  	defer restore()
    53  	restore = snapdtool.MockVersion("4.56")
    54  	defer restore()
    55  
    56  	_, err := snap.Parser(snap.Client()).ParseArgs([]string{"version"})
    57  	c.Assert(err, IsNil)
    58  	c.Assert(s.Stdout(), Equals, "snap    4.56\nsnapd   7.89\nseries  56\n")
    59  	c.Assert(s.Stderr(), Equals, "")
    60  }
    61  
    62  func (s *SnapSuite) TestVersionCommandOnClassicNoOsVersion(c *C) {
    63  	s.RedirectClientToTestServer(func(w http.ResponseWriter, r *http.Request) {
    64  		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"}}`)
    65  	})
    66  	restore := mockArgs("snap", "version")
    67  	defer restore()
    68  	restore = snapdtool.MockVersion("4.56")
    69  	defer restore()
    70  
    71  	_, err := snap.Parser(snap.Client()).ParseArgs([]string{"version"})
    72  	c.Assert(err, IsNil)
    73  	c.Assert(s.Stdout(), Equals, "snap    4.56\nsnapd   7.89\nseries  56\narch    -\n")
    74  	c.Assert(s.Stderr(), Equals, "")
    75  }