當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ensure.Err函數代碼示例

本文整理匯總了Golang中github.com/facebookgo/ensure.Err函數的典型用法代碼示例。如果您正苦於以下問題:Golang Err函數的具體用法?Golang Err怎麽用?Golang Err使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Err函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestDeleteHook

func TestDeleteHook(t *testing.T) {
	t.Parallel()
	h := newHarness(t)
	defer h.Stop()

	c := &configureCmd{}
	_, _, err := c.deleteHook(h.env, nil, "delete")
	ensure.Err(t, err, regexp.MustCompile("invalid format"))

	_, _, err = c.deleteHook(h.env, nil, "invalid", "1")
	ensure.Err(t, err, regexp.MustCompile("invalid format"))

	_, _, err = c.deleteHook(h.env, nil, "delete", "1", "2")
	ensure.Err(t, err, regexp.MustCompile("invalid trigger name"))

	var hooksOps []*hookOperation
	_, ops, err := c.deleteHook(h.env, hooksOps, "delete", "call")
	ensure.Nil(t, err)
	ensure.DeepEqual(t, ops[len(ops)-1].method, "DELETE")
	ensure.DeepEqual(
		t,
		*ops[len(ops)-1].function,
		functionHook{FunctionName: "call"},
	)

	_, ops, err = c.deleteHook(h.env, hooksOps, "delete", "_User", "beforeSave")
	ensure.Nil(t, err)
	ensure.DeepEqual(t, ops[len(ops)-1].method, "DELETE")
	ensure.DeepEqual(
		t,
		*ops[len(ops)-1].trigger,
		triggerHook{ClassName: "_User", TriggerName: "beforeSave"},
	)
}
開發者ID:Georotzen,項目名稱:parse-cli,代碼行數:34,代碼來源:configure_cmd_test.go

示例2: TestReadTriggerParams

func TestReadTriggerParams(t *testing.T) {
	t.Parallel()

	h := newHarness(t)
	defer h.Stop()

	h.env.In = ioutil.NopCloser(strings.NewReader("\n"))
	_, err := readTriggerName(h.env)
	ensure.Err(t, err, regexp.MustCompile("Class name cannot be empty"))

	h.env.In = ioutil.NopCloser(strings.NewReader("foo\n"))
	_, err = readTriggerName(h.env)
	ensure.Err(t, err, regexp.MustCompile("Trigger name cannot be empty"))

	h.env.In = ioutil.NopCloser(strings.NewReader("foo\nbeforeSave"))
	hook, err := readTriggerName(h.env)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, *hook, triggerHook{ClassName: "foo", TriggerName: "beforeSave"})

	h.env.In = ioutil.NopCloser(strings.NewReader("foo\nbeforeSave\napi.example.com/foo/beforeSave\n"))
	hook, err = readTriggerParams(h.env)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, *hook, triggerHook{
		ClassName:   "foo",
		TriggerName: "beforeSave",
		URL:         "https://api.example.com/foo/beforeSave",
	})
}
開發者ID:huamichaelchen,項目名稱:parse-cli,代碼行數:28,代碼來源:triggers_cmd_test.go

示例3: TestParserEmail

func TestParserEmail(t *testing.T) {
	t.Parallel()

	h := parsecli.NewTokenHarness(t)
	h.MakeEmptyRoot()
	defer h.Stop()

	ensure.Nil(t, parsecli.CreateConfigWithContent(filepath.Join(h.Env.Root, parsecli.ParseLocal), "{}"))
	ensure.Nil(t,
		parsecli.CreateConfigWithContent(
			filepath.Join(h.Env.Root, parsecli.ParseProject),
			`{"project_type": 1}`,
		),
	)

	var c configureCmd
	ensure.Nil(t, c.parserEmail(h.Env, []string{"email2"}))
	ensure.DeepEqual(
		t,
		h.Out.String(),
		`Successfully configured email for current project to: "email2"
`,
	)

	ensure.Err(t, c.parserEmail(h.Env, nil), regexp.MustCompile("Invalid args:"))
	ensure.Err(t, c.parserEmail(h.Env, []string{"a", "b"}), regexp.MustCompile("Invalid args:"))
}
開發者ID:swhitley,項目名稱:parse-cli,代碼行數:27,代碼來源:configure_test.go

示例4: TestProjectType

func TestProjectType(t *testing.T) {
	t.Parallel()
	h := parsecli.NewHarness(t)
	defer h.Stop()

	h.MakeEmptyRoot()
	ensure.Nil(t, parsecli.CloneSampleCloudCode(h.Env, false))

	c := &configureCmd{}
	err := c.projectType(h.Env, []string{"1", "2"})
	ensure.Err(t, err, regexp.MustCompile("only an optional project type argument is expected"))

	h.Env.In = ioutil.NopCloser(strings.NewReader("invalid\n"))
	err = c.projectType(h.Env, nil)
	ensure.StringContains(t, h.Err.String(), "Invalid selection. Please enter a number")
	ensure.Err(t, err, regexp.MustCompile("Could not make a selection. Please try again."))
	h.Err.Reset()
	h.Out.Reset()

	h.Env.In = ioutil.NopCloser(strings.NewReader("0\n"))
	err = c.projectType(h.Env, nil)
	ensure.StringContains(t, h.Err.String(), "Please enter a number between 1 and")
	ensure.Err(t, err, regexp.MustCompile("Could not make a selection. Please try again."))
	h.Err.Reset()
	h.Out.Reset()

	h.Env.In = ioutil.NopCloser(strings.NewReader("1\n"))
	err = c.projectType(h.Env, nil)
	ensure.StringContains(t, h.Out.String(), "Successfully set project type to: parse")
	ensure.Nil(t, err)
}
開發者ID:swhitley,項目名稱:parse-cli,代碼行數:31,代碼來源:configure_test.go

示例5: TestDeployRetries

func TestDeployRetries(t *testing.T) {
	t.Parallel()

	h := newHarness(t)
	defer h.Stop()

	info := &struct {
		ReleaseName  string            `json:"releaseName,omitempty"`
		Description  string            `json:"description,omitempty"`
		ParseVersion string            `json:"parseVersion,omitempty"`
		Checksums    map[string]string `json:"checksums,omitempty"`
		Versions     map[string]string `json:"userFiles,omitempty"`
	}{
		ReleaseName:  "v1",
		ParseVersion: "latest",
		Checksums:    map[string]string{"main.js": "d41d8cd98f00b204e9800998ecf8427e"},
		Versions:     map[string]string{"main.js": "f1"},
	}
	ht := transportFunc(func(r *http.Request) (*http.Response, error) {
		ensure.DeepEqual(t, r.URL.Path, "/1/deploy")
		return &http.Response{
			StatusCode: http.StatusOK,
			Body:       ioutil.NopCloser(strings.NewReader(jsonStr(t, info))),
		}, nil
	})
	h.env.ParseAPIClient = &ParseAPIClient{apiClient: &parse.Client{Transport: ht}}

	d := &deployCmd{Retries: 1}
	ctx := context{Config: defaultParseConfig}
	ctx.Config.getProjectConfig().Parse.JSSDK = "latest"

	ensure.Err(t, d.run(h.env, &ctx), regexp.MustCompile("no such file or directory"))
	ensure.DeepEqual(t, h.Err.String(), "")

	h.Err.Reset()
	d.Retries = 2
	ensure.Err(t, d.run(h.env, &ctx), regexp.MustCompile("no such file or directory"))
	ensure.DeepEqual(
		t,
		h.Err.String(),
		"Deploy failed with error:\nlstat cloud: no such file or directory\nWill retry in 0 seconds.\n\n",
	)

	h.Err.Reset()
	d.Retries = 5
	ensure.Err(t, d.run(h.env, &ctx), regexp.MustCompile("no such file or directory"))
	errStr := "Deploy failed with error:\nlstat cloud: no such file or directory\nWill retry in 0 seconds.\n\n"
	errStr += strings.Repeat("Sorry, deploy failed again with same error.\nWill retry in 0 seconds.\n\n", 3)
	ensure.DeepEqual(t, h.Err.String(), errStr)
}
開發者ID:Georotzen,項目名稱:parse-cli,代碼行數:50,代碼來源:deploy_cmd_test.go

示例6: TestUploadFileNoFile

func TestUploadFileNoFile(t *testing.T) {
	t.Parallel()
	h := newHarness(t)
	defer h.Stop()

	var d deployCmd
	_, err := d.uploadFile("cloud/master.js", "", h.env, nil)
	switch runtime.GOOS {
	case "windows":
		ensure.Err(t, err, regexp.MustCompile(`The system cannot find the path specified.`))
	default:
		ensure.Err(t, err, regexp.MustCompile(`no such file or directory`))
	}
}
開發者ID:Georotzen,項目名稱:parse-cli,代碼行數:14,代碼來源:deploy_cmd_test.go

示例7: TestSetVersionInvalid

func TestSetVersionInvalid(t *testing.T) {
	t.Parallel()
	h, c := newJsSdkHarnessWithConfig(t)
	defer h.Stop()
	j := jsSDKCmd{newVersion: "1.2.12"}
	ensure.Err(t, j.setVersion(h.env, c), regexp.MustCompile("Invalid SDK version selected"))
}
開發者ID:Georotzen,項目名稱:parse-cli,代碼行數:7,代碼來源:jssdk_cmd_test.go

示例8: TestSecondUnixListenInherited

func TestSecondUnixListenInherited(t *testing.T) {
	var n Net
	tmpfile, err := ioutil.TempFile("", "TestSecondUnixListenInherited-")
	ensure.Nil(t, err)
	ensure.Nil(t, tmpfile.Close())
	ensure.Nil(t, os.Remove(tmpfile.Name()))
	defer os.Remove(tmpfile.Name())
	l1, err := net.Listen("unix", tmpfile.Name())
	ensure.Nil(t, err)
	file, err := l1.(*net.UnixListener).File()
	ensure.Nil(t, err)
	n.fdStart = dup(t, int(file.Fd()))
	ensure.Nil(t, file.Close())
	os.Setenv(envCountKey, "1")
	ensure.Nil(t, n.inherit())
	ensure.DeepEqual(t, len(n.inherited), 1)
	l2, err := n.Listen("unix", tmpfile.Name())
	ensure.Nil(t, err)
	ensure.DeepEqual(t, len(n.active), 1)
	ensure.DeepEqual(t, n.inherited[0], nil)
	_, err = n.Listen("unix", tmpfile.Name())
	ensure.Err(t, err, regexp.MustCompile("bind: address already in use$"))
	ensure.Nil(t, l1.Close())
	ensure.Nil(t, l2.Close())
}
開發者ID:absolute8511,項目名稱:grace,代碼行數:25,代碼來源:net_test.go

示例9: TestShouldCreateNewApp

func TestShouldCreateNewApp(t *testing.T) {
	t.Parallel()
	h := parsecli.NewHarness(t)
	defer h.Stop()

	n := &newCmd{}

	h.Env.In = ioutil.NopCloser(strings.NewReader("new"))
	decision, err := n.promptCreateNewApp(h.Env, false)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, decision, "new")

	h.Env.In = ioutil.NopCloser(strings.NewReader("existing"))
	decision, err = n.promptCreateNewApp(h.Env, false)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, decision, "existing")

	h.Env.In = ioutil.NopCloser(strings.NewReader("other"))
	_, err = n.promptCreateNewApp(h.Env, false)
	ensure.Err(t, err, regexp.MustCompile("are the only valid options"))

	decision, err = n.promptCreateNewApp(h.Env, true)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, decision, "existing")

	n.createNewApp = true
	decision, err = n.promptCreateNewApp(h.Env, true)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, decision, "new")
}
開發者ID:z7z8th,項目名稱:parse-cli,代碼行數:30,代碼來源:new_test.go

示例10: TestConfigureAcessToken

func TestConfigureAcessToken(t *testing.T) {
	t.Parallel()

	h, _ := newAppHarness(t)
	defer h.Stop()

	c := configureCmd{login: login{tokenReader: strings.NewReader("")}}
	h.env.In = ioutil.NopCloser(strings.NewReader("token\n"))
	ensure.Nil(t, c.accountKey(h.env))
	ensure.DeepEqual(
		t,
		h.Out.String(),
		`
Input your account key or press enter to generate a new one.
Account Key: Successfully stored credentials.
`)
	h.env.In = ioutil.NopCloser(strings.NewReader("email\ninvalid\n"))
	ensure.Err(t, c.accountKey(h.env), regexp.MustCompile("Please try again"))
	ensure.DeepEqual(t,
		h.Err.String(),
		`Sorry, the account key you provided is not valid.
Please follow instructions at https://www.parse.com/account_keys to generate a new account key.
`,
	)
}
開發者ID:vamsirajendra,項目名稱:parse-cli,代碼行數:25,代碼來源:configure_cmd_test.go

示例11: TestConfigureAcessToken

func TestConfigureAcessToken(t *testing.T) {
	t.Parallel()

	h, _ := newAppHarness(t)
	defer h.Stop()

	c := configureCmd{login: login{tokenReader: strings.NewReader("")}}
	h.env.In = ioutil.NopCloser(strings.NewReader("n\ntoken\n"))
	ensure.Nil(t, c.accessToken(h.env))
	ensure.DeepEqual(t,
		h.Out.String(),
		`Please enter an access token if you already generated it.
If you do not have an access token or would like to generate a new one,
please type: "y" to open the browser or "n" to continue: Access Token: Successfully stored credentials.
`,
	)
	h.env.In = ioutil.NopCloser(strings.NewReader("n\nemail\ninvalid\n"))
	ensure.Err(t, c.accessToken(h.env), regexp.MustCompile("Please try again"))
	ensure.DeepEqual(t,
		h.Err.String(),
		`Sorry, the access token you provided is not valid.
Please follow instructions at https://www.parse.com/account_keys to generate a new access token.
`,
	)
}
開發者ID:google2013,項目名稱:parse-cli,代碼行數:25,代碼來源:configure_cmd_test.go

示例12: TestGetHostFromURL

func TestGetHostFromURL(t *testing.T) {
	urlStr := "https://api.parse.com/1/"
	host, err := getHostFromURL(urlStr, "")
	ensure.Nil(t, err)
	ensure.DeepEqual(t, host, "api.parse.com")

	urlStr = "https://api.parse.com/1/"
	host, err = getHostFromURL(urlStr, "[email protected]")
	ensure.Nil(t, err)
	ensure.DeepEqual(t, host, "api.parse.com#[email protected]")

	urlStr = "https://api.example.com:8080/1/"
	host, err = getHostFromURL(urlStr, "")
	ensure.Nil(t, err)
	ensure.DeepEqual(t, host, "api.example.com")

	urlStr = "https://api.example.com:8080/1/"
	host, err = getHostFromURL(urlStr, "[email protected]")
	ensure.Nil(t, err)
	ensure.DeepEqual(t, host, "api.example.com#[email protected]")

	urlStr = "api.example.com:8080:90"
	host, err = getHostFromURL(urlStr, "")
	ensure.Err(t, err, regexp.MustCompile("not a valid url"))
}
開發者ID:Georotzen,項目名稱:parse-cli,代碼行數:25,代碼來源:utils_test.go

示例13: TestLogin

func TestLogin(t *testing.T) {
	t.Parallel()

	h, _ := newAppHarness(t)
	defer h.Stop()

	l := &loginCmd{tokenReader: strings.NewReader("")}

	h.env.In = ioutil.NopCloser(strings.NewReader("n\nemail\ntoken\n"))
	ensure.Nil(t, l.run(h.env))
	ensure.DeepEqual(t,
		h.Out.String(),
		`Please enter the email id you used to register with Parse
and an account key if you already generated it.
If you do not have an account key or would like to generate a new one,
please type: "y" to open the browser or "n" to continue: Email: Account Key: Successfully stored credentials.
`)

	h.env.In = ioutil.NopCloser(strings.NewReader("n\nemail\ninvalid\n"))
	ensure.Err(t, l.run(h.env), regexp.MustCompile("Please try again"))
	ensure.DeepEqual(t,
		h.Err.String(),
		`Sorry, we do not have a user with this email and account key.
Please follow instructions at https://www.parse.com/account/keys to generate a new account key.
`)
}
開發者ID:huamichaelchen,項目名稱:parse-cli,代碼行數:26,代碼來源:login_cmd_test.go

示例14: TestConfigAddAliasBadLink

func TestConfigAddAliasBadLink(t *testing.T) {
	t.Parallel()
	const name = "foo"
	const link = "bar"
	c := parseConfig{}
	ensure.Err(t, c.addAlias(name, link), regexp.MustCompile("wasn't found"))
}
開發者ID:huamichaelchen,項目名稱:parse-cli,代碼行數:7,代碼來源:legacy_config_test.go

示例15: TestConfigAppDefaultNotFound

func TestConfigAppDefaultNotFound(t *testing.T) {
	t.Parallel()
	c := parseConfig{Applications: map[string]*parseAppConfig{}}
	ac, err := c.app(defaultKey)
	ensure.True(t, ac == nil)
	ensure.Err(t, err, regexp.MustCompile("No default app configured"))
}
開發者ID:huamichaelchen,項目名稱:parse-cli,代碼行數:7,代碼來源:legacy_config_test.go


注:本文中的github.com/facebookgo/ensure.Err函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。