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


Golang parsecli.NewHarness函數代碼示例

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


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

示例1: TestReadTriggerParams

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

	h := parsecli.NewHarness(t)
	defer h.Stop()

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

	h.Env.In = ioutil.NopCloser(strings.NewReader("foo\n"))
	_, err = readTriggerName(h.Env, nil)
	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, nil)
	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, nil)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, *hook, triggerHook{
		ClassName:   "foo",
		TriggerName: "beforeSave",
		URL:         "https://api.example.com/foo/beforeSave",
	})
}
開發者ID:swhitley,項目名稱:parse-cli,代碼行數:28,代碼來源:triggers_test.go

示例2: 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

示例3: TestSetupAndConfigure

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

	n := &newCmd{}
	h.Env.Type = parsecli.ParseFormat
	h.Env.In = ioutil.NopCloser(strings.NewReader("\n"))
	code, err := n.setupSample(h.Env, "myapp", &parsecli.ParseAppConfig{ApplicationID: "a"}, true, false)
	ensure.Nil(t, err)
	ensure.True(t, code)

	type jsSDKVersion struct {
		JS []string `json:"js"`
	}
	ht := parsecli.TransportFunc(func(r *http.Request) (*http.Response, error) {
		ensure.DeepEqual(t, r.URL.Path, "/1/jsVersions")
		rows := jsSDKVersion{JS: []string{"1.5.0", "1.6.0"}}
		return &http.Response{
			StatusCode: http.StatusOK,
			Body:       ioutil.NopCloser(strings.NewReader(jsonStr(t, rows))),
		}, nil
	})
	h.Env.ParseAPIClient = &parsecli.ParseAPIClient{APIClient: &parse.Client{Transport: ht}}
	err = n.configureSample(
		&addCmd{MakeDefault: true},
		"yolo",
		(&parsecli.ParseAppConfig{ApplicationID: "a"}).WithInternalMasterKey("m"),
		nil,
		h.Env,
	)
	ensure.Nil(t, err)
}
開發者ID:z7z8th,項目名稱:parse-cli,代碼行數:34,代碼來源:new_test.go

示例4: TestMakeNewRelease

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

	var d deployCmd
	info := deployInfo{
		ReleaseName:  "v2",
		ParseVersion: "latest",
		Checksums: deployFileData{
			Cloud:  map[string]string{"main.js": "4ece160cc8e5e828ee718e7367cf5d37"},
			Public: map[string]string{"index.html": "9e2354a0ebac5852bc674026137c8612"},
		},
		Versions: deployFileData{
			Cloud:  map[string]string{"main.js": "f2"},
			Public: map[string]string{"index.html": "f2"},
		},
	}
	ht := parsecli.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 = &parsecli.ParseAPIClient{APIClient: &parse.Client{Transport: ht}}
	res, err := d.makeNewRelease(&deployInfo{}, h.Env)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, info, res)
}
開發者ID:swhitley,項目名稱:parse-cli,代碼行數:30,代碼來源:deploy_test.go

示例5: TestGetPrevDeplInfo

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

	var d deployCmd
	info := &deployInfo{
		ReleaseName:  "v1",
		ParseVersion: "latest",
		Checksums: deployFileData{
			Cloud:  map[string]string{"main.js": "d41d8cd98f00b204e9800998ecf8427e"},
			Public: map[string]string{"index.html": "d41d8cd98f00b204e9800998ecf8427e"},
		},
		Versions: deployFileData{
			Cloud:  map[string]string{"main.js": "f1"},
			Public: map[string]string{"index.html": "f1"},
		},
	}
	ht := parsecli.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 = &parsecli.ParseAPIClient{APIClient: &parse.Client{Transport: ht}}
	res, err := d.getPrevDeplInfo(h.Env)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, res, info)
}
開發者ID:swhitley,項目名稱:parse-cli,代碼行數:30,代碼來源:deploy_test.go

示例6: TestGenericGetSourceFiles

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

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

	ensure.Nil(t, os.Mkdir(filepath.Join(h.Env.Root, "src"), 0755))
	for _, name := range []string{"index.html"} {
		file, err := os.Create(filepath.Join(h.Env.Root, "src", name))
		ensure.Nil(t, err)
		ensure.Nil(t, file.Close())
	}

	ensure.Nil(t, os.Symlink(filepath.Join(h.Env.Root, "src"), filepath.Join(h.Env.Root, "public")))

	var d deployCmd

	files, ignored, err := d.getSourceFiles(
		filepath.Join(h.Env.Root, "public"),
		map[string]struct{}{".html": {}},
		h.Env,
	)

	ensure.Nil(t, err)
	ensure.DeepEqual(t, files, []string{filepath.Join(h.Env.Root, "public", "index.html")})
	ensure.DeepEqual(t, len(ignored), 0)
}
開發者ID:swhitley,項目名稱:parse-cli,代碼行數:28,代碼來源:deploy_test.go

示例7: TestLatestVersion

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

	h := parsecli.NewHarness(t)
	defer h.Stop()

	ht := parsecli.TransportFunc(func(r *http.Request) (*http.Response, error) {
		ensure.DeepEqual(t, r.URL.Path, "/1/supported")
		return &http.Response{
			StatusCode: http.StatusOK,
			Body: ioutil.NopCloser(
				jsonpipe.Encode(
					map[string]string{"version": "2.0.2"},
				),
			),
		}, nil
	})
	h.Env.ParseAPIClient = &parsecli.ParseAPIClient{APIClient: &parse.Client{Transport: ht}}
	u := new(updateCmd)

	latestVersion, err := u.latestVersion(h.Env)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, latestVersion, "2.0.2")

	downloadURL, err := u.getDownloadURL(h.Env)
	ensure.StringContains(t,
		downloadURL, "https://github.com/ParsePlatform/parse-cli/releases/download/release_2.0.2")
}
開發者ID:swhitley,項目名稱:parse-cli,代碼行數:28,代碼來源:update_test.go

示例8: 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

示例9: TestLogInvalidLevel

func TestLogInvalidLevel(t *testing.T) {
	t.Parallel()
	l := logsCmd{}
	h := parsecli.NewHarness(t)
	defer h.Stop()
	err := l.run(h.Env, nil)
	ensure.Err(t, err, regexp.MustCompile(`invalid level: ""`))
}
開發者ID:swhitley,項目名稱:parse-cli,代碼行數:8,代碼來源:logs_test.go

示例10: TestFindAAPT

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

	aapts := findAAPT("Resources")
	ensure.DeepEqual(t, aapts[:], []string{filepath.Join("Resources", "build_tools", "aapt")})
}
開發者ID:swhitley,項目名稱:parse-cli,代碼行數:8,代碼來源:android_symbol_uploader_test.go

示例11: TestPrintListOneAppNoDefaultKey

func TestPrintListOneAppNoDefaultKey(t *testing.T) {
	t.Parallel()
	conf := &parsecli.ParseConfig{Applications: map[string]*parsecli.ParseAppConfig{"first": {}}}
	h := parsecli.NewHarness(t)
	defer h.Stop()
	conf.PrettyPrintApps(h.Env)
	ensure.DeepEqual(t, h.Out.String(), "The following apps are associated with Cloud Code in the current directory:\n  first\n")
}
開發者ID:swhitley,項目名稱:parse-cli,代碼行數:8,代碼來源:list_test.go

示例12: TestRunSymbolsCmd

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

	h := parsecli.NewHarness(t)
	defer h.Stop()

	s := &symbolsCmd{}
	ensure.Err(t, s.run(h.Env, nil), regexp.MustCompile("Please specify path"))
}
開發者ID:swhitley,項目名稱:parse-cli,代碼行數:9,代碼來源:symbols_test.go

示例13: TestVersion

func TestVersion(t *testing.T) {
	t.Parallel()
	h := parsecli.NewHarness(t)
	defer h.Stop()
	var c versionCmd
	err := c.run(h.Env)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, h.Out.String(), parsecli.Version+"\n")
	ensure.DeepEqual(t, h.Err.String(), "")
}
開發者ID:swhitley,項目名稱:parse-cli,代碼行數:10,代碼來源:version_test.go

示例14: TestBase64MD5OfFileNoFile

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

	h.MakeEmptyRoot()
	testFile := filepath.Join(h.Env.Root, "test")
	_, err := base64MD5OfFile(testFile)
	ensure.NotNil(t, err)
}
開發者ID:swhitley,項目名稱:parse-cli,代碼行數:10,代碼來源:parse_symbol_uploader_test.go

示例15: TestUpgradeLegacyNoOp

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

	h := parsecli.NewHarness(t)
	defer h.Stop()

	var m migrateCmd
	c := &parsecli.ParseConfig{ProjectConfig: &parsecli.ProjectConfig{Type: parsecli.ParseFormat}}
	_, err := m.upgradeLegacy(h.Env, c)
	ensure.Err(t, err, regexp.MustCompile("Already using the preferred config format."))
}
開發者ID:swhitley,項目名稱:parse-cli,代碼行數:11,代碼來源:migrate_test.go


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