本文整理汇总了Golang中github.com/snapcore/snapd/cmd/snap.Parser函数的典型用法代码示例。如果您正苦于以下问题:Golang Parser函数的具体用法?Golang Parser怎么用?Golang Parser使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Parser函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestBuyInvalidCharacters
func (s *BuySnapSuite) TestBuyInvalidCharacters(c *check.C) {
_, err := snap.Parser().ParseArgs([]string{"buy", "a:b"})
c.Assert(err, check.NotNil)
c.Check(err.Error(), check.Equals, "cannot buy snap: invalid characters in name")
c.Check(s.Stdout(), check.Equals, "")
c.Check(s.Stderr(), check.Equals, "")
_, err = snap.Parser().ParseArgs([]string{"buy", "c*d"})
c.Assert(err, check.NotNil)
c.Check(err.Error(), check.Equals, "cannot buy snap: invalid characters in name")
c.Check(s.Stdout(), check.Equals, "")
c.Check(s.Stderr(), check.Equals, "")
}
示例2: TestSnapRunHookUnsetRevisionIntegration
func (s *SnapSuite) TestSnapRunHookUnsetRevisionIntegration(c *check.C) {
// mock installed snap
dirs.SetRootDir(c.MkDir())
defer func() { dirs.SetRootDir("/") }()
si := snaptest.MockSnap(c, string(mockYaml), &snap.SideInfo{
Revision: snap.R(42),
})
err := os.Symlink(si.MountDir(), filepath.Join(si.MountDir(), "../current"))
c.Assert(err, check.IsNil)
// redirect exec
execArg0 := ""
execArgs := []string{}
execEnv := []string{}
restorer := snaprun.MockSyscallExec(func(arg0 string, args []string, envv []string) error {
execArg0 = arg0
execArgs = args
execEnv = envv
return nil
})
defer restorer()
// Specifically pass "unset" which would use the active version.
_, err = snaprun.Parser().ParseArgs([]string{"run", "--hook=configure", "-r=unset", "snapname"})
c.Assert(err, check.IsNil)
c.Check(execArg0, check.Equals, filepath.Join(dirs.LibExecDir, "snap-confine"))
c.Check(execArgs, check.DeepEquals, []string{
filepath.Join(dirs.LibExecDir, "snap-confine"),
"snap.snapname.hook.configure",
filepath.Join(dirs.LibExecDir, "snap-exec"),
"--hook=configure", "snapname"})
c.Check(execEnv, testutil.Contains, "SNAP_REVISION=42")
}
示例3: TestCreateKeyInvalidCharacters
func (s *SnapSuite) TestCreateKeyInvalidCharacters(c *C) {
_, err := snap.Parser().ParseArgs([]string{"create-key", "a b"})
c.Assert(err, NotNil)
c.Check(err.Error(), Equals, "key name \"a b\" is not valid; only ASCII letters, digits, and hyphens are allowed")
c.Check(s.Stdout(), Equals, "")
c.Check(s.Stderr(), Equals, "")
}
示例4: TestLoginAskEmail
func (s *SnapSuite) TestLoginAskEmail(c *C) {
if err := archWithBrokenDevPtmx(); err != nil {
c.Skip(err.Error())
}
n := 0
s.RedirectClientToTestServer(makeLoginTestServer(c, &n))
// send the email
fmt.Fprint(s.stdin, "[email protected]\n")
// send the password
fmt.Fprint(s.term, "some-password\n")
rest, err := snap.Parser().ParseArgs([]string{"login"})
c.Assert(err, IsNil)
c.Assert(rest, DeepEquals, []string{})
// test slightly ugly, on a real system STDOUT will be:
// Email address: [email protected]\n
// because the input to stdin is echoed
c.Check(s.Stdout(), Equals, `Email address: Password of "[email protected]":
Login successful
`)
c.Check(s.Stderr(), Equals, "")
c.Check(n, Equals, 1)
}
示例5: TestSnapRunAppIntegration
func (s *SnapSuite) TestSnapRunAppIntegration(c *check.C) {
// mock installed snap
dirs.SetRootDir(c.MkDir())
defer func() { dirs.SetRootDir("/") }()
si := snaptest.MockSnap(c, string(mockYaml), &snap.SideInfo{
Revision: snap.R("x2"),
})
err := os.Symlink(si.MountDir(), filepath.Join(si.MountDir(), "../current"))
c.Assert(err, check.IsNil)
// redirect exec
execArg0 := ""
execArgs := []string{}
execEnv := []string{}
restorer := snaprun.MockSyscallExec(func(arg0 string, args []string, envv []string) error {
execArg0 = arg0
execArgs = args
execEnv = envv
return nil
})
defer restorer()
// and run it!
rest, err := snaprun.Parser().ParseArgs([]string{"run", "snapname.app", "--arg1", "arg2"})
c.Assert(err, check.IsNil)
c.Assert(rest, check.DeepEquals, []string{"snapname.app", "--arg1", "arg2"})
c.Check(execArg0, check.Equals, filepath.Join(dirs.LibExecDir, "snap-confine"))
c.Check(execArgs, check.DeepEquals, []string{
filepath.Join(dirs.LibExecDir, "snap-confine"),
"snap.snapname.app",
filepath.Join(dirs.LibExecDir, "snap-exec"),
"snapname.app", "--arg1", "arg2"})
c.Check(execEnv, testutil.Contains, "SNAP_REVISION=x2")
}
示例6: TestAutoImportAssertsHappyNotOnClassic
func (s *SnapSuite) TestAutoImportAssertsHappyNotOnClassic(c *C) {
restore := release.MockOnClassic(true)
defer restore()
fakeAssertData := []byte("my-assertion")
s.RedirectClientToTestServer(func(w http.ResponseWriter, r *http.Request) {
c.Errorf("auto-import on classic is disabled, but something tried to do a %q with %s", r.Method, r.URL.Path)
})
fakeAssertsFn := filepath.Join(c.MkDir(), "auto-import.assert")
err := ioutil.WriteFile(fakeAssertsFn, fakeAssertData, 0644)
c.Assert(err, IsNil)
mockMountInfoFmt := `
24 0 8:18 / %s rw,relatime shared:1 - ext4 /dev/sdb2 rw,errors=remount-ro,data=ordered`
content := fmt.Sprintf(mockMountInfoFmt, filepath.Dir(fakeAssertsFn))
restore = snap.MockMountInfoPath(makeMockMountInfo(c, content))
defer restore()
rest, err := snap.Parser().ParseArgs([]string{"auto-import"})
c.Assert(err, IsNil)
c.Assert(rest, DeepEquals, []string{})
c.Check(s.Stdout(), Equals, "")
c.Check(s.Stderr(), Equals, "auto-import is disabled on classic\n")
}
示例7: TestFindNothingFails
func (s *SnapSuite) TestFindNothingFails(c *check.C) {
s.RedirectClientToTestServer(func(w http.ResponseWriter, r *http.Request) {
c.Fatalf("it reached the server")
})
_, err := snap.Parser().ParseArgs([]string{"find"})
c.Assert(err, check.ErrorMatches, `you need to specify a query. Try.*`)
}
示例8: TestFindHello
func (s *SnapSuite) TestFindHello(c *check.C) {
n := 0
s.RedirectClientToTestServer(func(w http.ResponseWriter, r *http.Request) {
switch n {
case 0:
c.Check(r.Method, check.Equals, "GET")
c.Check(r.URL.Path, check.Equals, "/v2/find")
q := r.URL.Query()
c.Check(q.Get("q"), check.Equals, "hello")
fmt.Fprintln(w, findHelloJSON)
default:
c.Fatalf("expected to get 1 requests, now on %d", n+1)
}
n++
})
rest, err := snap.Parser().ParseArgs([]string{"find", "hello"})
c.Assert(err, check.IsNil)
c.Assert(rest, check.DeepEquals, []string{})
c.Check(s.Stdout(), check.Matches, `Name +Version +Developer +Notes +Summary
hello +2.10 +canonical +- +GNU Hello, the "hello world" snap
hello-huge +1.0 +noise +- +a really big snap
`)
c.Check(s.Stderr(), check.Equals, "")
}
示例9: TestListWithNotes
func (s *SnapSuite) TestListWithNotes(c *check.C) {
n := 0
s.RedirectClientToTestServer(func(w http.ResponseWriter, r *http.Request) {
switch n {
case 0:
c.Check(r.Method, check.Equals, "GET")
c.Check(r.URL.Path, check.Equals, "/v2/snaps")
fmt.Fprintln(w, `{"type": "sync", "result": [
{"name": "foo", "status": "active", "version": "4.2", "developer": "bar", "revision":17, "trymode": true}
,{"name": "dm1", "status": "active", "version": "5", "revision":1, "devmode": true, "confinement": "devmode"}
,{"name": "dm2", "status": "active", "version": "5", "revision":1, "devmode": true, "confinement": "strict"}
,{"name": "cf1", "status": "active", "version": "6", "revision":2, "confinement": "devmode"}
]}`)
default:
c.Fatalf("expected to get 1 requests, now on %d", n+1)
}
n++
})
rest, err := snap.Parser().ParseArgs([]string{"list"})
c.Assert(err, check.IsNil)
c.Assert(rest, check.DeepEquals, []string{})
c.Check(s.Stdout(), check.Matches, `(?ms)^Name +Version +Rev +Developer +Notes$`)
c.Check(s.Stdout(), check.Matches, `(?ms).*^foo +4.2 +17 +bar +try$`)
c.Check(s.Stdout(), check.Matches, `(?ms).*^dm1 +.* +devmode$`)
c.Check(s.Stdout(), check.Matches, `(?ms).*^dm2 +.* +devmode$`)
c.Check(s.Stdout(), check.Matches, `(?ms).*^cf1 +.* +jailmode$`)
c.Check(s.Stderr(), check.Equals, "")
}
示例10: TestDeleteKeyRequiresName
func (s *SnapKeysSuite) TestDeleteKeyRequiresName(c *C) {
_, err := snap.Parser().ParseArgs([]string{"delete-key"})
c.Assert(err, NotNil)
c.Check(err.Error(), Equals, "the required argument `<key-name>` was not provided")
c.Check(s.Stdout(), Equals, "")
c.Check(s.Stderr(), Equals, "")
}
示例11: TestBuyHelp
func (s *BuySnapSuite) TestBuyHelp(c *check.C) {
_, err := snap.Parser().ParseArgs([]string{"buy"})
c.Assert(err, check.NotNil)
c.Check(err.Error(), check.Equals, "the required argument `<snap>` was not provided")
c.Check(s.Stdout(), check.Equals, "")
c.Check(s.Stderr(), check.Equals, "")
}
示例12: TestSignBuildWorksDevelGrade
func (s *SnapSignBuildSuite) TestSignBuildWorksDevelGrade(c *C) {
snapFilename := "foo_1_amd64.snap"
snapContent := []byte("sample")
_err := ioutil.WriteFile(snapFilename, snapContent, 0644)
c.Assert(_err, IsNil)
defer os.Remove(snapFilename)
tempdir := c.MkDir()
for _, fileName := range []string{"pubring.gpg", "secring.gpg", "trustdb.gpg"} {
data, err := ioutil.ReadFile(filepath.Join("test-data", fileName))
c.Assert(err, IsNil)
err = ioutil.WriteFile(filepath.Join(tempdir, fileName), data, 0644)
c.Assert(err, IsNil)
}
os.Setenv("SNAP_GNUPG_HOME", tempdir)
defer os.Unsetenv("SNAP_GNUPG_HOME")
_, err := snap.Parser().ParseArgs([]string{"sign-build", snapFilename, "--developer-id", "dev-id1", "--snap-id", "snap-id-1", "--grade", "devel"})
c.Assert(err, IsNil)
assertion, err := asserts.Decode([]byte(s.Stdout()))
c.Assert(err, IsNil)
c.Check(assertion.Type(), Equals, asserts.SnapBuildType)
c.Check(assertion.HeaderString("grade"), Equals, "devel")
// check for valid signature ?!
c.Check(s.Stderr(), Equals, "")
}
示例13: runTryTest
func (s *SnapOpSuite) runTryTest(c *check.C, devmode bool) {
// pass relative path to cmd
tryDir := "some-dir"
s.srv.checker = func(r *http.Request) {
// ensure the client always sends the absolute path
fullTryDir, err := filepath.Abs(tryDir)
c.Assert(err, check.IsNil)
c.Check(r.URL.Path, check.Equals, "/v2/snaps")
postData, err := ioutil.ReadAll(r.Body)
c.Assert(err, check.IsNil)
c.Assert(string(postData), check.Matches, "(?s).*Content-Disposition: form-data; name=\"action\"\r\n\r\ntry\r\n.*")
c.Assert(string(postData), check.Matches, fmt.Sprintf("(?s).*Content-Disposition: form-data; name=\"snap-path\"\r\n\r\n%s\r\n.*", regexp.QuoteMeta(fullTryDir)))
c.Assert(string(postData), check.Matches, fmt.Sprintf("(?s).*Content-Disposition: form-data; name=\"devmode\"\r\n\r\n%s\r\n.*", strconv.FormatBool(devmode)))
}
s.RedirectClientToTestServer(s.srv.handle)
cmd := []string{"try", tryDir}
if devmode {
cmd = append(cmd, "--devmode")
}
rest, err := snap.Parser().ParseArgs(cmd)
c.Assert(err, check.IsNil)
c.Assert(rest, check.DeepEquals, []string{})
c.Check(s.Stdout(), check.Matches, fmt.Sprintf(`(?sm).*foo 1.0 mounted from .*%s`, tryDir))
c.Check(s.Stderr(), check.Equals, "")
// ensure that the fake server api was actually hit
c.Check(s.srv.n, check.Equals, s.srv.total)
}
示例14: TestAutoImportAssertsNotImportedFromLoop
func (s *SnapSuite) TestAutoImportAssertsNotImportedFromLoop(c *C) {
restore := release.MockOnClassic(false)
defer restore()
fakeAssertData := []byte("bad-assertion")
s.RedirectClientToTestServer(func(w http.ResponseWriter, r *http.Request) {
// assertion is ignored, nothing is posted to this endpoint
panic("not reached")
})
fakeAssertsFn := filepath.Join(c.MkDir(), "auto-import.assert")
err := ioutil.WriteFile(fakeAssertsFn, fakeAssertData, 0644)
c.Assert(err, IsNil)
mockMountInfoFmtWithLoop := `
24 0 8:18 / %s rw,relatime shared:1 - squashfs /dev/loop1 rw,errors=remount-ro,data=ordered`
content := fmt.Sprintf(mockMountInfoFmtWithLoop, filepath.Dir(fakeAssertsFn))
restore = snap.MockMountInfoPath(makeMockMountInfo(c, content))
defer restore()
rest, err := snap.Parser().ParseArgs([]string{"auto-import"})
c.Assert(err, IsNil)
c.Assert(rest, DeepEquals, []string{})
c.Check(s.Stdout(), Equals, "")
c.Check(s.Stderr(), Equals, "")
}
示例15: TestExportKeyAccount
func (s *SnapKeysSuite) TestExportKeyAccount(c *C) {
rootPrivKey, _ := assertstest.GenerateKey(1024)
storePrivKey, _ := assertstest.GenerateKey(752)
storeSigning := assertstest.NewStoreStack("canonical", rootPrivKey, storePrivKey)
manager := asserts.NewGPGKeypairManager()
assertstest.NewAccount(storeSigning, "developer1", nil, "")
rest, err := snap.Parser().ParseArgs([]string{"export-key", "another", "--account=developer1"})
c.Assert(err, IsNil)
c.Assert(rest, DeepEquals, []string{})
assertion, err := asserts.Decode(s.stdout.Bytes())
c.Assert(err, IsNil)
c.Check(assertion.Type(), Equals, asserts.AccountKeyRequestType)
c.Check(assertion.Revision(), Equals, 0)
c.Check(assertion.HeaderString("account-id"), Equals, "developer1")
c.Check(assertion.HeaderString("name"), Equals, "another")
c.Check(assertion.HeaderString("public-key-sha3-384"), Equals, "DVQf1U4mIsuzlQqAebjjTPYtYJ-GEhJy0REuj3zvpQYTZ7EJj7adBxIXLJ7Vmk3L")
since, err := time.Parse(time.RFC3339, assertion.HeaderString("since"))
c.Assert(err, IsNil)
zone, offset := since.Zone()
c.Check(zone, Equals, "UTC")
c.Check(offset, Equals, 0)
c.Check(s.Stderr(), Equals, "")
privKey, err := manager.Get(assertion.HeaderString("public-key-sha3-384"))
c.Assert(err, IsNil)
err = asserts.SignatureCheck(assertion, privKey.PublicKey())
c.Assert(err, IsNil)
}