github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/cmd/snap/cmd_unalias_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  	. "github.com/snapcore/snapd/cmd/snap"
    29  )
    30  
    31  func (s *SnapSuite) TestUnaliasHelp(c *C) {
    32  	msg := `Usage:
    33    snap.test unalias [unalias-OPTIONS] [<alias-or-snap>]
    34  
    35  The unalias command removes a single alias if the provided argument is a manual
    36  alias, or disables all aliases of a snap, including manual ones, if the
    37  argument is a snap name.
    38  
    39  [unalias command options]
    40        --no-wait            Do not wait for the operation to finish but just
    41                             print the change id.
    42  `
    43  	s.testSubCommandHelp(c, "unalias", msg)
    44  }
    45  
    46  func (s *SnapSuite) TestUnalias(c *C) {
    47  	s.RedirectClientToTestServer(func(w http.ResponseWriter, r *http.Request) {
    48  		switch r.URL.Path {
    49  		case "/v2/aliases":
    50  			c.Check(r.Method, Equals, "POST")
    51  			c.Check(DecodedRequestBody(c, r), DeepEquals, map[string]interface{}{
    52  				"action": "unalias",
    53  				"snap":   "alias1",
    54  				"alias":  "alias1",
    55  			})
    56  			w.WriteHeader(202)
    57  			fmt.Fprintln(w, `{"type":"async", "status-code": 202, "change": "zzz"}`)
    58  		case "/v2/changes/zzz":
    59  			c.Check(r.Method, Equals, "GET")
    60  			fmt.Fprintln(w, `{"type":"sync", "result":{"ready": true, "status": "Done", "data": {"aliases-removed": [{"alias": "alias1", "snap": "foo", "app": "foo"}]}}}`)
    61  		default:
    62  			c.Fatalf("unexpected path %q", r.URL.Path)
    63  		}
    64  	})
    65  	rest, err := Parser(Client()).ParseArgs([]string{"unalias", "alias1"})
    66  	c.Assert(err, IsNil)
    67  	c.Assert(rest, DeepEquals, []string{})
    68  	c.Assert(s.Stdout(), Equals, ""+
    69  		"Removed:\n"+
    70  		"  - foo as alias1\n",
    71  	)
    72  	c.Assert(s.Stderr(), Equals, "")
    73  }