本文整理匯總了Golang中github.com/cloudfoundry-incubator/cf-test-helpers/runner.Curl函數的典型用法代碼示例。如果您正苦於以下問題:Golang Curl函數的具體用法?Golang Curl怎麽用?Golang Curl使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Curl函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runPushTests
func runPushTests(appName, appUrl string, testConfig *smoke.Config) {
if testConfig.SkipSSLValidation {
Expect(runner.Curl("-k", appUrl).Wait(CF_TIMEOUT_IN_SECONDS)).To(Say("It just needed to be restarted!"))
} else {
Expect(runner.Curl(appUrl).Wait(CF_TIMEOUT_IN_SECONDS)).To(Say("It just needed to be restarted!"))
}
instances := 2
maxAttempts := 30
ExpectAppToScale(appName, instances)
ExpectAllAppInstancesToStart(appName, instances, maxAttempts)
ExpectAllAppInstancesToBeReachable(appUrl, instances, maxAttempts)
if testConfig.Cleanup {
Expect(cf.Cf("delete", appName, "-f", "-r").Wait(CF_TIMEOUT_IN_SECONDS)).To(Exit(0))
Eventually(func() *Session {
appStatusSession := cf.Cf("app", appName)
Expect(appStatusSession.Wait(CF_TIMEOUT_IN_SECONDS)).To(Exit(1))
return appStatusSession
}, 5).Should(Say("not found"))
Eventually(func() *Session {
if testConfig.SkipSSLValidation {
return runner.Curl("-k", appUrl).Wait(CF_TIMEOUT_IN_SECONDS)
} else {
return runner.Curl(appUrl).Wait(CF_TIMEOUT_IN_SECONDS)
}
}, 5).Should(Say("404"))
}
}
示例2: AuthenticateUser
func AuthenticateUser(authorizationEndpoint string, username string, password string) (cookie string) {
loginCsrfUri := fmt.Sprintf("%v/login", authorizationEndpoint)
cookieFile, err := ioutil.TempFile("", "cats-csrf-cookie"+generator.RandomName())
Expect(err).ToNot(HaveOccurred())
cookiePath := cookieFile.Name()
defer func() {
cookieFile.Close()
os.Remove(cookiePath)
}()
curl := runner.Curl(loginCsrfUri, `--insecure`, `-i`, `-v`, `-c`, cookiePath).Wait(DEFAULT_TIMEOUT)
apiResponse := string(curl.Out.Contents())
csrfRegEx, _ := regexp.Compile(`name="X-Uaa-Csrf" value="(.*)"`)
csrfToken := csrfRegEx.FindStringSubmatch(apiResponse)[1]
loginUri := fmt.Sprintf("%v/login.do", authorizationEndpoint)
usernameEncoded := url.QueryEscape(username)
passwordEncoded := url.QueryEscape(password)
csrfTokenEncoded := url.QueryEscape(csrfToken)
loginCredentials := fmt.Sprintf("username=%v&password=%v&X-Uaa-Csrf=%v", usernameEncoded, passwordEncoded, csrfTokenEncoded)
curl = runner.Curl(loginUri, `--data`, loginCredentials, `--insecure`, `-i`, `-v`, `-b`, cookiePath).Wait(DEFAULT_TIMEOUT)
Expect(curl).To(Exit(0))
apiResponse = string(curl.Out.Contents())
jsessionRegEx, _ := regexp.Compile(`JSESSIONID([^;]*)`)
vcapidRegEx, _ := regexp.Compile(`__VCAP_ID__([^;]*)`)
sessionId := jsessionRegEx.FindString(apiResponse)
vcapId := vcapidRegEx.FindString(apiResponse)
cookie = fmt.Sprintf("%v;%v", sessionId, vcapId)
return
}
示例3: CurlAppWithTimeout
// Curls an app's endpoint and exit successfully before the specified timeout
func CurlAppWithTimeout(appName, path string, timeout time.Duration) string {
config := LoadConfig()
uri := AppUri(appName, path)
var curlCmd *gexec.Session
if config.SkipSSLValidation {
curlCmd = runner.Curl("-k", uri)
} else {
curlCmd = runner.Curl(uri)
}
runner.NewCmdRunner(curlCmd, timeout).Run()
Expect(string(curlCmd.Err.Contents())).To(HaveLen(0))
return string(curlCmd.Out.Contents())
}
示例4: CurlAppWithTimeout
// Curls an app's endpoint and exit successfully before the specified timeout
func CurlAppWithTimeout(appName, path string, timeout time.Duration) string {
uri := AppUri(appName, path)
curlCmd := runner.Curl(uri)
runner.NewCmdRunner(curlCmd, timeout).Run()
Expect(string(curlCmd.Err.Contents())).To(HaveLen(0))
return string(curlCmd.Out.Contents())
}
示例5: CurlAppWithTimeout
// Curls an app's endpoint and exit successfully before the specified timeout
func CurlAppWithTimeout(appName, path string, timeout time.Duration) string {
uri := AppUri(appName, path)
curl := runner.Curl(uri).Wait(timeout)
Expect(curl).To(Exit(0))
Expect(string(curl.Err.Contents())).To(HaveLen(0))
return string(curl.Out.Contents())
}
示例6: SetOauthEndpoints
func SetOauthEndpoints(apiEndpoint string, config *OAuthConfig) {
url := fmt.Sprintf("%v/info", apiEndpoint)
curl := runner.Curl(url).Wait(DEFAULT_TIMEOUT)
Expect(curl).To(Exit(0))
apiResponse := curl.Out.Contents()
jsonResult := ParseJsonResponse(apiResponse)
config.TokenEndpoint = fmt.Sprintf("%v", jsonResult[`token_endpoint`])
config.AuthorizationEndpoint = fmt.Sprintf("%v", jsonResult[`authorization_endpoint`])
return
}
示例7: AuthorizeScopes
func AuthorizeScopes(cookie string, config OAuthConfig) (authCode string) {
authorizedScopes := `scope.0=scope.openid&scope.1=scope.cloud_controller.read&scope.2=scope.cloud_controller.write&user_oauth_approval=true`
authorizeScopesUri := fmt.Sprintf("%v/oauth/authorize", config.AuthorizationEndpoint)
curl := runner.Curl(authorizeScopesUri, `-i`, `--data`, authorizedScopes, `--cookie`, cookie, `--insecure`, `-v`).Wait(DEFAULT_TIMEOUT)
Expect(curl).To(Exit(0))
apiResponse := string(curl.Out.Contents())
pattern := fmt.Sprintf(`%v\?code=([a-zA-Z0-9]+)`, regexp.QuoteMeta(config.RedirectUri))
regEx, _ := regexp.Compile(pattern)
authCode = regEx.FindStringSubmatch(apiResponse)[1]
return
}
示例8: ExpectAllAppInstancesToBeReachable
// Curls the appUrl (up to maxAttempts) until all instances have been seen
func ExpectAllAppInstancesToBeReachable(appUrl string, instances int, maxAttempts int) {
matcher := regexp.MustCompile(`instance[ _]index["]{0,1}:[ ]{0,1}(\d+)`)
branchesSeen := make([]bool, instances)
var sawAll bool
var testConfig = smoke.GetConfig()
var session *Session
for i := 0; i < maxAttempts; i++ {
if testConfig.SkipSSLValidation {
session = runner.Curl("-k", appUrl)
} else {
session = runner.Curl(appUrl)
}
Expect(session.Wait(CF_TIMEOUT_IN_SECONDS)).To(Exit(0))
output := string(session.Out.Contents())
matches := matcher.FindStringSubmatch(output)
if matches == nil {
Fail("Expected app curl output to include an instance_index; got " + output)
}
indexString := matches[1]
index, err := strconv.Atoi(indexString)
if err != nil {
Fail("Failed to parse instance index value " + indexString)
}
branchesSeen[index] = true
if allTrue(branchesSeen) {
sawAll = true
break
}
}
Expect(sawAll).To(BeTrue(), fmt.Sprintf("Expected to hit all %d app instances in %d attempts, but didn't", instances, maxAttempts))
}
示例9: GetAccessToken
func GetAccessToken(authCode string, config OAuthConfig) (accessToken string) {
clientCredentials := []byte(fmt.Sprintf("%v:%v", config.ClientId, config.ClientSecret))
encodedClientCredentials := base64.StdEncoding.EncodeToString(clientCredentials)
authHeader := fmt.Sprintf("Authorization: Basic %v", encodedClientCredentials)
requestTokenUri := fmt.Sprintf("%v/oauth/token", config.TokenEndpoint)
requestTokenData := fmt.Sprintf("scope=%v&code=%v&grant_type=authorization_code&redirect_uri=%v", config.RequestedScopes, authCode, config.RedirectUri)
curl := runner.Curl(requestTokenUri, `-H`, authHeader, `--data`, requestTokenData, `--insecure`, `-v`).Wait(DEFAULT_TIMEOUT)
Expect(curl).To(Exit(0))
apiResponse := curl.Out.Contents()
jsonResult := ParseJsonResponse(apiResponse)
accessToken = fmt.Sprintf("%v", jsonResult[`access_token`])
return
}
示例10: SetOauthEndpoints
func SetOauthEndpoints(apiEndpoint string, config *OAuthConfig) {
args := []string{}
if helpers.LoadConfig().SkipSSLValidation {
args = append(args, "--insecure")
}
args = append(args, fmt.Sprintf("%v/info", apiEndpoint))
curl := runner.Curl(args...).Wait(DEFAULT_TIMEOUT)
Expect(curl).To(Exit(0))
apiResponse := curl.Out.Contents()
jsonResult := ParseJsonResponse(apiResponse)
config.TokenEndpoint = fmt.Sprintf("%v", jsonResult[`token_endpoint`])
config.AuthorizationEndpoint = fmt.Sprintf("%v", jsonResult[`authorization_endpoint`])
return
}
示例11: curlApexDomainUrl
func curlApexDomainUrl() textproto.MIMEHeader {
appsDomain := config.AppsDomain
apexDomainUrl := config.Protocol() + appsDomain + "/"
curlCmd := runner.Curl(apexDomainUrl, "-I").Wait(helpers.CURL_TIMEOUT)
Expect(curlCmd).To(Exit(0))
Expect(string(curlCmd.Err.Contents())).To(HaveLen(0))
curlResponse := string(curlCmd.Out.Contents())
reader := textproto.NewReader(bufio.NewReader(bytes.NewBufferString(curlResponse)))
reader.ReadLine()
m, err := reader.ReadMIMEHeader()
Expect(err).ShouldNot(HaveOccurred())
return m
}
示例12: AuthenticateUser
func AuthenticateUser(authorizationEndpoint string, username string, password string) (cookie string) {
loginUri := fmt.Sprintf("%v/login.do", authorizationEndpoint)
usernameEncoded := url.QueryEscape(username)
passwordEncoded := url.QueryEscape(password)
loginCredentials := fmt.Sprintf("username=%v&password=%v", usernameEncoded, passwordEncoded)
curl := runner.Curl(loginUri, `--data`, loginCredentials, `--insecure`, `-i`, `-v`).Wait(DEFAULT_TIMEOUT)
Expect(curl).To(Exit(0))
apiResponse := string(curl.Out.Contents())
jsessionRegEx, _ := regexp.Compile(`JSESSIONID([^;]*)`)
vcapidRegEx, _ := regexp.Compile(`__VCAP_ID__([^;]*)`)
sessionId := jsessionRegEx.FindString(apiResponse)
vcapId := vcapidRegEx.FindString(apiResponse)
cookie = fmt.Sprintf("%v;%v", sessionId, vcapId)
return
}
示例13: QueryServiceInstancePermissionEndpoint
func QueryServiceInstancePermissionEndpoint(apiEndpoint string, accessToken string, serviceInstanceGuid string) (canManage string, httpCode string) {
canManage = `not populated`
authHeader := fmt.Sprintf("Authorization: bearer %v", accessToken)
permissionsUri := fmt.Sprintf("%v/v2/service_instances/%v/permissions", apiEndpoint, serviceInstanceGuid)
curl := runner.Curl(permissionsUri, `-H`, authHeader, `-w`, `:TestReponseCode:%{http_code}`, `--insecure`, `-v`).Wait(DEFAULT_TIMEOUT)
Expect(curl).To(Exit(0))
apiResponse := string(curl.Out.Contents())
resultMap := strings.Split(apiResponse, `:TestReponseCode:`)
resultText := resultMap[0]
httpCode = resultMap[1]
if httpCode == `200` {
jsonResult := ParseJsonResponse([]byte(resultText))
canManage = fmt.Sprintf("%v", jsonResult[`manage`])
}
return
}
示例14: RequestScopes
func RequestScopes(cookie string, config OAuthConfig) (authCode string, httpCode string) {
authCode = `initialized`
requestScopesUri := fmt.Sprintf("%v/oauth/authorize?client_id=%v&response_type=code+id_token&redirect_uri=%v&scope=%v",
config.AuthorizationEndpoint,
url.QueryEscape(config.ClientId),
config.RedirectUri,
config.RequestedScopes)
curl := runner.Curl(requestScopesUri, `-L`, `--cookie`, cookie, `--insecure`, `-w`, `:TestReponseCode:%{http_code}`, `-v`).Wait(DEFAULT_TIMEOUT)
Expect(curl).To(Exit(0))
apiResponse := string(curl.Out.Contents())
resultMap := strings.Split(apiResponse, `:TestReponseCode:`)
httpCode = resultMap[1]
if httpCode == `200` {
authCode = AuthorizeScopes(cookie, config)
}
return
}
示例15:
createServiceStdout := createServiceSession.Out
select {
case <-createServiceStdout.Detect("FAILED"):
Eventually(createServiceSession, config.ScaledTimeout(timeout)).Should(Say("instance limit for this service has been reached"))
Eventually(createServiceSession, config.ScaledTimeout(timeout)).Should(Exit(1))
fmt.Println("No Plan Instances available for testing plan:", planName)
case <-createServiceStdout.Detect("OK"):
Eventually(createServiceSession, config.ScaledTimeout(timeout)).Should(Exit(0))
Eventually(cf.Cf("bind-service", appName, serviceInstanceName), config.ScaledTimeout(timeout)).Should(Exit(0))
Eventually(cf.Cf("start", appName), config.ScaledTimeout(5*time.Minute)).Should(Exit(0))
uri := appUri(appName) + "/store"
fmt.Println("Posting to url: ", uri)
Eventually(runner.Curl("-d", "myvalue", "-X", "POST", uri, "-k", "-f"), config.ScaledTimeout(timeout), retryInterval).Should(Exit(0))
fmt.Println("\n")
fmt.Println("Getting from url: ", uri)
Eventually(runner.Curl(uri, "-k"), config.ScaledTimeout(timeout), retryInterval).Should(Say("myvalue"))
fmt.Println("\n")
Eventually(cf.Cf("unbind-service", appName, serviceInstanceName), config.ScaledTimeout(timeout)).Should(Exit(0))
Eventually(cf.Cf("delete-service", "-f", serviceInstanceName), config.ScaledTimeout(timeout)).Should(Exit(0))
}
createServiceStdout.CancelDetects()
})
}
Context("for each plan", func() {