github.com/bugraaydogar/snapd@v0.0.0-20210315170335-8c70bb858939/cmd/snap/cmd_repair_repairs_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2017 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  	"path/filepath"
    24  
    25  	. "gopkg.in/check.v1"
    26  
    27  	snap "github.com/snapcore/snapd/cmd/snap"
    28  	"github.com/snapcore/snapd/dirs"
    29  	"github.com/snapcore/snapd/release"
    30  	"github.com/snapcore/snapd/testutil"
    31  )
    32  
    33  func mockSnapRepair(c *C) *testutil.MockCmd {
    34  	return testutil.MockCommand(c, filepath.Join(dirs.GlobalRootDir, dirs.CoreLibExecDir, "snap-repair"), "")
    35  }
    36  
    37  func (s *SnapSuite) TestSnapShowRepair(c *C) {
    38  	restore := release.MockOnClassic(false)
    39  	defer restore()
    40  
    41  	mockSnapRepair := mockSnapRepair(c)
    42  	defer mockSnapRepair.Restore()
    43  
    44  	_, err := snap.Parser(snap.Client()).ParseArgs([]string{"repair", "canonical-1"})
    45  	c.Assert(err, IsNil)
    46  	c.Check(mockSnapRepair.Calls(), DeepEquals, [][]string{
    47  		{"snap-repair", "show", "canonical-1"},
    48  	})
    49  }
    50  
    51  func (s *SnapSuite) TestSnapShowRepairNoArgs(c *C) {
    52  	restore := release.MockOnClassic(false)
    53  	defer restore()
    54  
    55  	_, err := snap.Parser(snap.Client()).ParseArgs([]string{"repair"})
    56  	c.Assert(err, ErrorMatches, "no <repair-id> given. Try 'snap repairs' to list all repairs or specify a specific repair id.")
    57  }
    58  
    59  func (s *SnapSuite) TestSnapListRepairs(c *C) {
    60  	restore := release.MockOnClassic(false)
    61  	defer restore()
    62  
    63  	mockSnapRepair := mockSnapRepair(c)
    64  	defer mockSnapRepair.Restore()
    65  
    66  	_, err := snap.Parser(snap.Client()).ParseArgs([]string{"repairs"})
    67  	c.Assert(err, IsNil)
    68  	c.Check(mockSnapRepair.Calls(), DeepEquals, [][]string{
    69  		{"snap-repair", "list"},
    70  	})
    71  }