コード例 #1
0
ファイル: main_test.go プロジェクト: niemeyer/snapd
func (s *SnapSuite) TestUnknownCommand(c *C) {
	restore := mockArgs("snap", "unknowncmd")
	defer restore()

	err := snap.RunMain()
	c.Assert(err, ErrorMatches, `unknown command "unknowncmd", see "snap --help"`)
}
コード例 #2
0
ファイル: main_test.go プロジェクト: niemeyer/snapd
func (s *SnapSuite) TestExtraArgs(c *C) {
	restore := mockArgs("snap", "abort", "1", "xxx", "zzz")
	defer restore()

	err := snap.RunMain()
	c.Assert(err, ErrorMatches, `too many arguments for command`)
}
コード例 #3
0
ファイル: cmd_help_test.go プロジェクト: niemeyer/snapd
func (s *SnapSuite) TestHelpPrintsHelp(c *check.C) {
	origArgs := os.Args
	defer func() { os.Args = origArgs }()

	for _, cmdLine := range [][]string{
		{"snap", "help"},
		{"snap", "--help"},
		{"snap", "-h"},
	} {
		os.Args = cmdLine

		err := snap.RunMain()
		c.Assert(err, check.IsNil)
		c.Check(s.Stdout(), check.Matches, `(?smU)Usage:
 +snap \[OPTIONS\] <command>

The snap tool interacts with the snapd daemon to control the snappy software
platform.


Application Options:
 +--version +Print the version and exit

Help Options:
 +-h, --help +Show this help message

Available commands:
 +abort.*
`)
		c.Check(s.Stderr(), check.Equals, "")
	}
}
コード例 #4
0
ファイル: main_test.go プロジェクト: niemeyer/snapd
func (s *SnapSuite) TestErrorResult(c *C) {
	s.RedirectClientToTestServer(func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintln(w, `{"type": "error", "result": {"message": "cannot do something"}}`)
	})

	restore := mockArgs("snap", "install", "foo")
	defer restore()

	err := snap.RunMain()
	c.Assert(err, ErrorMatches, `cannot do something`)
}
コード例 #5
0
ファイル: main_test.go プロジェクト: niemeyer/snapd
func (s *SnapSuite) TestAccessDeniedHint(c *C) {
	s.RedirectClientToTestServer(func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintln(w, `{"type": "error", "result": {"message": "access denied", "kind": "login-required"}, "status-code": 401}`)
	})

	restore := mockArgs("snap", "install", "foo")
	defer restore()

	err := snap.RunMain()
	c.Assert(err, NotNil)
	c.Check(err.Error(), Equals, `access denied (try with sudo)`)
}
コード例 #6
0
ファイル: main_test.go プロジェクト: niemeyer/snapd
func (s *SnapSuite) TestVersionOnAllSnap(c *C) {
	s.RedirectClientToTestServer(func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintln(w, `{"type":"sync","status-code":200,"status":"OK","result":{"os-release":{"id":"ubuntu","version-id":"12.34"},"series":"56","version":"7.89"}}`)
	})
	restore := mockArgs("snap", "--version")
	defer restore()
	restore = mockVersion("4.56")
	defer restore()

	c.Assert(func() { snap.RunMain() }, PanicMatches, `internal error: exitStatus\{0\} .*`)
	c.Assert(s.Stdout(), Equals, "snap    4.56\nsnapd   7.89\nseries  56\n")
	c.Assert(s.Stderr(), Equals, "")
}
コード例 #7
0
ファイル: cmd_help_test.go プロジェクト: niemeyer/snapd
func (s *SnapSuite) TestSubCommandHelpPrintsHelp(c *check.C) {
	origArgs := os.Args
	defer func() { os.Args = origArgs }()

	os.Args = []string{"snap", "install", "--help"}

	err := snap.RunMain()
	c.Assert(err, check.IsNil)
	c.Check(s.Stdout(), check.Matches, `(?smU)Usage:
 +snap \[OPTIONS\] install \[install-OPTIONS\] <snap>...
.*
`)
	c.Check(s.Stderr(), check.Equals, "")
}
コード例 #8
0
ファイル: cmd_help_test.go プロジェクト: pedronis/snappy
func (s *SnapSuite) TestHelpPrintsHelp(c *check.C) {
	origArgs := os.Args
	defer func() { os.Args = origArgs }()

	for _, cmdLine := range [][]string{
		{"snap", "help"},
		{"snap", "--help"},
		{"snap", "-h"},
	} {
		os.Args = cmdLine

		err := snap.RunMain()
		c.Assert(err, check.IsNil)
		c.Check(s.Stdout(), check.Matches, `(?smU)Usage:
 +snap \[OPTIONS\] <command>

Install, configure, refresh and remove snap packages. Snaps are
'universal' packages that work across many different Linux systems,
enabling secure distribution of the latest apps and utilities for
cloud, servers, desktops and the internet of things.

This is the CLI for snapd, a background service that takes care of
snaps on the system. Start with 'snap list' to see installed snaps.


Application Options:
 +--version +Print the version and exit

Help Options:
 +-h, --help +Show this help message

Available commands:
 +abort.*
`)
		c.Check(s.Stderr(), check.Equals, "")
	}
}