github.com/stulluk/snapd@v0.0.0-20210611110309-f6d5d5bd24b0/cmd/snap/cmd_unset_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2019 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  	"gopkg.in/check.v1"
    24  
    25  	snapunset "github.com/snapcore/snapd/cmd/snap"
    26  )
    27  
    28  func (s *snapSetSuite) TestInvalidUnsetParameters(c *check.C) {
    29  	invalidParameters := []string{"unset"}
    30  	_, err := snapunset.Parser(snapunset.Client()).ParseArgs(invalidParameters)
    31  	c.Check(err, check.ErrorMatches, "the required arguments `<snap>` and `<conf key> \\(at least 1 argument\\)` were not provided")
    32  	c.Check(s.setConfApiCalls, check.Equals, 0)
    33  
    34  	invalidParameters = []string{"unset", "snap-name"}
    35  	_, err = snapunset.Parser(snapunset.Client()).ParseArgs(invalidParameters)
    36  	c.Check(err, check.ErrorMatches, "the required argument `<conf key> \\(at least 1 argument\\)` was not provided")
    37  	c.Check(s.setConfApiCalls, check.Equals, 0)
    38  }
    39  
    40  func (s *snapSetSuite) TestSnapUnset(c *check.C) {
    41  	// expected value is "nil" as the key is unset
    42  	s.mockSetConfigServer(c, nil)
    43  
    44  	_, err := snapunset.Parser(snapunset.Client()).ParseArgs([]string{"unset", "snapname", "key"})
    45  	c.Assert(err, check.IsNil)
    46  	c.Check(s.setConfApiCalls, check.Equals, 1)
    47  }