当前位置: 首页>>代码示例>>Golang>>正文


Golang parsecli.TransportFunc函数代码示例

本文整理汇总了Golang中github.com/ParsePlatform/parse-cli/parsecli.TransportFunc函数的典型用法代码示例。如果您正苦于以下问题:Golang TransportFunc函数的具体用法?Golang TransportFunc怎么用?Golang TransportFunc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了TransportFunc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

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

示例2: TestUploadSourceFilesChanged

func TestUploadSourceFilesChanged(t *testing.T) {
	t.Parallel()
	h := createParseProject(t)
	defer h.Stop()

	u := &uploader{
		DirName:  "cloud",
		Suffixes: map[string]struct{}{".js": {}},
		EndPoint: "uploads",
		Env:      h.Env,
		PrevChecksums: map[string]string{
			"main.js": "d41d8cd98f00b204e9800998ecf8427e",
		},
		PrevVersions: map[string]string{
			"main.js": "f1",
		},
	}

	ht := parsecli.TransportFunc(func(r *http.Request) (*http.Response, error) {
		ensure.DeepEqual(t, r.URL.Path, "/1/uploads")
		return &http.Response{
			StatusCode: http.StatusOK,
			Body:       ioutil.NopCloser(strings.NewReader(`{"version": "f2"}`)),
		}, nil
	})

	h.Env.ParseAPIClient = &parsecli.ParseAPIClient{APIClient: &parse.Client{Transport: ht}}

	var d deployCmd
	checksums, versions, err := d.uploadSourceFiles(u)
	ensure.Nil(t, err)
	ensure.DeepEqual(t, checksums, map[string]string{"main.js": "4ece160cc8e5e828ee718e7367cf5d37"})
	ensure.DeepEqual(t, versions, map[string]string{"main.js": "f2"})
}
开发者ID:swhitley,项目名称:parse-cli,代码行数:34,代码来源:deploy_test.go

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

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

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

示例6: setupForDeploy

func setupForDeploy(t testing.TB, info *deployInfo) *parsecli.Harness {
	h := createParseProject(t)

	ht := parsecli.TransportFunc(func(r *http.Request) (*http.Response, error) {
		switch r.URL.Path {
		case "/1/deploy":
			return &http.Response{
				StatusCode: http.StatusOK,
				Body:       ioutil.NopCloser(strings.NewReader(jsonStr(t, info))),
			}, nil
		case "/1/scripts", "/1/hosted_files":
			return &http.Response{
				StatusCode: http.StatusOK,
				Body:       ioutil.NopCloser(strings.NewReader(`{"version":"f2"}`)),
			}, nil
		case "/1/jsVersions":
			return &http.Response{
				StatusCode: http.StatusOK,
				Body:       ioutil.NopCloser(strings.NewReader(`{"js":["1.0","2.0"]}`)),
			}, nil
		default:
			return &http.Response{
				StatusCode: http.StatusExpectationFailed,
				Body:       ioutil.NopCloser(strings.NewReader(`{"error": "something is wrong"}`)),
			}, nil
		}
	})
	h.Env.ParseAPIClient = &parsecli.ParseAPIClient{APIClient: &parse.Client{Transport: ht}}
	return h
}
开发者ID:swhitley,项目名称:parse-cli,代码行数:30,代码来源:deploy_test.go

示例7: TestReleasesCmdError

func TestReleasesCmdError(t *testing.T) {
	h, c := newReleasesCmdHarness(t)
	defer h.Stop()
	ht := parsecli.TransportFunc(func(r *http.Request) (*http.Response, error) {
		return nil, stackerr.New("Throws error")
	})
	h.Env.ParseAPIClient = &parsecli.ParseAPIClient{APIClient: &parse.Client{Transport: ht}}

	ensure.NotNil(t, c.run(h.Env, &parsecli.Context{}))
}
开发者ID:swhitley,项目名称:parse-cli,代码行数:10,代码来源:releases_test.go

示例8: newJsSdkHarnessError

func newJsSdkHarnessError(t testing.TB) *parsecli.Harness {
	h := parsecli.NewHarness(t)
	ht := parsecli.TransportFunc(func(r *http.Request) (*http.Response, error) {
		ensure.DeepEqual(t, r.URL.Path, "/1/jsVersions")
		return &http.Response{
			StatusCode: http.StatusExpectationFailed,
			Body:       ioutil.NopCloser(strings.NewReader(`{"error":"something is wrong"}`)),
		}, nil
	})
	h.Env.ParseAPIClient = &parsecli.ParseAPIClient{APIClient: &parse.Client{Transport: ht}}
	return h
}
开发者ID:swhitley,项目名称:parse-cli,代码行数:12,代码来源:jssdk_test.go

示例9: newJsSdkHarness

func newJsSdkHarness(t testing.TB) *parsecli.Harness {
	h := parsecli.NewHarness(t)
	ht := parsecli.TransportFunc(func(r *http.Request) (*http.Response, error) {
		ensure.DeepEqual(t, r.URL.Path, "/1/jsVersions")
		rows := jsSDKVersion{JS: []string{"1.2.8", "1.2.9", "1.2.10", "1.2.11", "0.2.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}}
	return h
}
开发者ID:swhitley,项目名称:parse-cli,代码行数:13,代码来源:jssdk_test.go

示例10: TestDeployRetries

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

	h := parsecli.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 := 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}}

	d := &deployCmd{Retries: 1}
	ctx := parsecli.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:swhitley,项目名称:parse-cli,代码行数:50,代码来源:deploy_test.go

示例11: TestUploadFiles

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

	h.MakeEmptyRoot()
	createRandomFiles(t, h)

	names := []string{"a", "b"}
	ht := parsecli.TransportFunc(func(r *http.Request) (*http.Response, error) {
		switch filepath.Base(r.URL.Path) {
		case names[0]:
			ensure.NotNil(t, r.Header)
			ensure.DeepEqual(t, r.Header.Get("Key"), "Value")
			ensure.DeepEqual(t, r.Header.Get("Content-Type"), "application/octet-stream")
			ensure.DeepEqual(t, r.Header.Get("Content-MD5"), "4JnleFGzGppuArF6N50EWg==")
			return &http.Response{
				StatusCode: http.StatusOK,
				Body:       ioutil.NopCloser(strings.NewReader(`{"status":"success"}`)),
			}, nil
		case names[1]:
			ensure.NotNil(t, r.Header)
			ensure.DeepEqual(t, r.Header.Get("Key"), "Value")
			ensure.DeepEqual(t, r.Header.Get("Content-Type"), "application/octet-stream")
			ensure.DeepEqual(t, r.Header.Get("Content-MD5"), "Fv43qsp6mnGCJlC00VkOcA==")
			return &http.Response{
				StatusCode: http.StatusOK,
				Body:       ioutil.NopCloser(strings.NewReader(`{"status":"success"}`)),
			}, nil
		default:
			return &http.Response{
				StatusCode: http.StatusInternalServerError,
				Body:       ioutil.NopCloser(strings.NewReader(`{"error":"something is wrong"}`)),
			}, nil
		}
	})
	h.Env.ParseAPIClient = &parsecli.ParseAPIClient{APIClient: &parse.Client{Transport: ht}}

	var filenames []string
	for _, name := range names {
		filenames = append(filenames, filepath.Join(h.Env.Root, name))
	}
	ensure.Nil(t, uploadSymbolFiles(filenames[:],
		map[string]string{"Key": "Value"}, true, h.Env))
	for _, filename := range filenames {
		_, err := os.Lstat(filename)
		ensure.NotNil(t, err)
		ensure.True(t, os.IsNotExist(err))
	}
}
开发者ID:swhitley,项目名称:parse-cli,代码行数:50,代码来源:parse_symbol_uploader_test.go

示例12: TestGetPrevDeplInfoError

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

	var d deployCmd
	ht := parsecli.TransportFunc(func(r *http.Request) (*http.Response, error) {
		ensure.DeepEqual(t, r.URL.Path, "/1/deploy")
		return &http.Response{
			StatusCode: http.StatusExpectationFailed,
			Body:       ioutil.NopCloser(strings.NewReader(`{"error": "something is wrong"}`)),
		}, nil
	})
	h.Env.ParseAPIClient = &parsecli.ParseAPIClient{APIClient: &parse.Client{Transport: ht}}
	_, err := d.getPrevDeplInfo(h.Env)
	ensure.Err(t, err, regexp.MustCompile("something is wrong"))
}
开发者ID:swhitley,项目名称:parse-cli,代码行数:17,代码来源:deploy_test.go

示例13: TestRollbackError

func TestRollbackError(t *testing.T) {
	t.Parallel()
	var r rollbackCmd
	h := parsecli.NewHarness(t)
	defer h.Stop()
	var res struct{ Error string }
	res.Error = "something is wrong"
	ht := parsecli.TransportFunc(func(r *http.Request) (*http.Response, error) {
		ensure.DeepEqual(t, r.URL.Path, "/1/deploy")
		return &http.Response{
			StatusCode: http.StatusExpectationFailed,
			Body:       ioutil.NopCloser(strings.NewReader(jsonStr(t, &res))),
		}, nil
	})
	h.Env.ParseAPIClient = &parsecli.ParseAPIClient{APIClient: &parse.Client{Transport: ht}}
	ensure.Err(t, r.run(h.Env, nil), regexp.MustCompile("something is wrong"))
}
开发者ID:swhitley,项目名称:parse-cli,代码行数:17,代码来源:rollback_test.go

示例14: TestLogWithoutFollow

func TestLogWithoutFollow(t *testing.T) {
	t.Parallel()
	l := logsCmd{level: "INFO"}
	h := parsecli.NewHarness(t)
	defer h.Stop()
	ht := parsecli.TransportFunc(func(r *http.Request) (*http.Response, error) {
		ensure.DeepEqual(t, r.URL.Path, "/1/scriptlog")
		rows := []logResponse{{Message: "foo bar"}, {Message: "baz"}}
		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 := l.run(h.Env, &parsecli.Context{})
	ensure.Nil(t, err)
	ensure.DeepEqual(t, h.Out.String(), "baz\nfoo bar\n")
}
开发者ID:swhitley,项目名称:parse-cli,代码行数:18,代码来源:logs_test.go

示例15: newRollbackCmdHarness

func newRollbackCmdHarness(t testing.TB) *parsecli.Harness {
	h := parsecli.NewHarness(t)
	ht := parsecli.TransportFunc(func(r *http.Request) (*http.Response, error) {
		ensure.DeepEqual(t, r.URL.Path, "/1/deploy")
		var req, res rollbackInfo
		ensure.Nil(t, json.NewDecoder(r.Body).Decode(&req))
		if req.ReleaseName == "" {
			res.ReleaseName = "v0"
		} else {
			res.ReleaseName = req.ReleaseName
		}
		return &http.Response{
			StatusCode: http.StatusOK,
			Body:       ioutil.NopCloser(strings.NewReader(jsonStr(t, &res))),
		}, nil
	})
	h.Env.ParseAPIClient = &parsecli.ParseAPIClient{APIClient: &parse.Client{Transport: ht}}
	return h
}
开发者ID:swhitley,项目名称:parse-cli,代码行数:19,代码来源:rollback_test.go


注:本文中的github.com/ParsePlatform/parse-cli/parsecli.TransportFunc函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。