github.com/rigado/snapd@v2.42.5-go-mod+incompatible/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  	"os"
    24  	"path/filepath"
    25  
    26  	. "gopkg.in/check.v1"
    27  
    28  	snap "github.com/snapcore/snapd/cmd/snap"
    29  	"github.com/snapcore/snapd/dirs"
    30  	"github.com/snapcore/snapd/release"
    31  	"github.com/snapcore/snapd/testutil"
    32  )
    33  
    34  func mockSnapRepair(c *C) *testutil.MockCmd {
    35  	coreLibExecDir := filepath.Join(dirs.GlobalRootDir, dirs.CoreLibExecDir)
    36  	err := os.MkdirAll(coreLibExecDir, 0755)
    37  	c.Assert(err, IsNil)
    38  	return testutil.MockCommand(c, filepath.Join(coreLibExecDir, "snap-repair"), "")
    39  }
    40  
    41  func (s *SnapSuite) TestSnapShowRepair(c *C) {
    42  	restore := release.MockOnClassic(false)
    43  	defer restore()
    44  
    45  	mockSnapRepair := mockSnapRepair(c)
    46  	defer mockSnapRepair.Restore()
    47  
    48  	_, err := snap.Parser(snap.Client()).ParseArgs([]string{"repair", "canonical-1"})
    49  	c.Assert(err, IsNil)
    50  	c.Check(mockSnapRepair.Calls(), DeepEquals, [][]string{
    51  		{"snap-repair", "show", "canonical-1"},
    52  	})
    53  }
    54  
    55  func (s *SnapSuite) TestSnapListRepairs(c *C) {
    56  	restore := release.MockOnClassic(false)
    57  	defer restore()
    58  
    59  	mockSnapRepair := mockSnapRepair(c)
    60  	defer mockSnapRepair.Restore()
    61  
    62  	_, err := snap.Parser(snap.Client()).ParseArgs([]string{"repairs"})
    63  	c.Assert(err, IsNil)
    64  	c.Check(mockSnapRepair.Calls(), DeepEquals, [][]string{
    65  		{"snap-repair", "list"},
    66  	})
    67  }