本文整理匯總了Golang中github.com/tedsuo/rata.RequestGenerator.CreateRequest方法的典型用法代碼示例。如果您正苦於以下問題:Golang RequestGenerator.CreateRequest方法的具體用法?Golang RequestGenerator.CreateRequest怎麽用?Golang RequestGenerator.CreateRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/tedsuo/rata.RequestGenerator
的用法示例。
在下文中一共展示了RequestGenerator.CreateRequest方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: constructRequest
func constructRequest(reqGenerator *rata.RequestGenerator, spec atc.HijackProcessSpec, id string, token *rc.TargetToken) *http.Request {
payload, err := json.Marshal(spec)
if err != nil {
log.Fatalln("failed to marshal process spec:", err)
}
hijackReq, err := reqGenerator.CreateRequest(
atc.HijackContainer,
rata.Params{"id": id},
bytes.NewBuffer(payload),
)
if err != nil {
log.Fatalln("failed to create hijack request:", err)
}
if token != nil {
hijackReq.Header.Add("Authorization", token.Type+" "+token.Value)
}
return hijackReq
}
示例2: constructRequest
func constructRequest(reqGenerator *rata.RequestGenerator, spec atc.HijackProcessSpec, reqValues url.Values) *http.Request {
payload, err := json.Marshal(spec)
if err != nil {
log.Fatalln("failed to marshal process spec:", err)
}
hijackReq, err := reqGenerator.CreateRequest(
atc.Hijack,
rata.Params{},
bytes.NewBuffer(payload),
)
if err != nil {
log.Fatalln("failed to create hijack request:", err)
}
if hijackReq.URL.User != nil {
hijackReq.Header.Add("Authorization", basicAuth(hijackReq.URL.User))
hijackReq.URL.User = nil
}
hijackReq.URL.RawQuery = reqValues.Encode()
return hijackReq
}
示例3:
},
},
},
},
},
}
})
Describe("GET /api/v1/pipelines/:name/config", func() {
var (
response *http.Response
)
JustBeforeEach(func() {
req, err := requestGenerator.CreateRequest(atc.GetConfig, rata.Params{
"pipeline_name": "something-else",
}, nil)
Expect(err).NotTo(HaveOccurred())
response, err = client.Do(req)
Expect(err).NotTo(HaveOccurred())
})
Context("when authenticated", func() {
BeforeEach(func() {
authValidator.IsAuthenticatedReturns(true)
})
Context("when the config can be loaded", func() {
BeforeEach(func() {
configDB.GetConfigReturns(config, 1, nil)
示例4:
})
AfterEach(func() {
cliRunner.StopAPIServer()
})
Context("when the store is fresh", func() {
BeforeEach(func() {
simulator.Tick(simulator.TicksToAttainFreshness)
cliRunner.StartAPIServer(simulator.currentTimestamp)
})
It("returns the apps", func() {
getAppstatus, err := requestGenerator.CreateRequest(
"bulk_app_state",
nil,
bytes.NewBufferString(validRequest),
)
Expect(err).NotTo(HaveOccurred())
getAppstatus.SetBasicAuth(username, password)
response, err := httpClient.Do(getAppstatus)
Expect(err).NotTo(HaveOccurred())
defer response.Body.Close()
Expect(response.StatusCode).To(Equal(http.StatusOK))
bodyBytes, err := ioutil.ReadAll(response.Body)
Expect(err).NotTo(HaveOccurred())
bodyString := string(bodyBytes)
示例5:
instanceKey0 := models.NewActualLRPInstanceKey("some-instance-guid-0", "cell-id")
err := bbsClient.ClaimActualLRP("some-process-guid", 0, &instanceKey0)
Expect(err).NotTo(HaveOccurred())
lrpKey1 := models.NewActualLRPKey("some-process-guid", 1, "some-domain")
instanceKey1 := models.NewActualLRPInstanceKey("some-instance-guid-1", "cell-id")
netInfo := models.NewActualLRPNetInfo("1.2.3.4", models.NewPortMapping(65100, 8080))
err = bbsClient.StartActualLRP(&lrpKey1, &instanceKey1, &netInfo)
Expect(err).NotTo(HaveOccurred())
})
It("reports the state of the given process guid's instances", func() {
getLRPs, err := requestGenerator.CreateRequest(
tps.LRPStatus,
rata.Params{"guid": "some-process-guid"},
nil,
)
Expect(err).NotTo(HaveOccurred())
response, err := httpClient.Do(getLRPs)
Expect(err).NotTo(HaveOccurred())
var lrpInstances []cc_messages.LRPInstance
err = json.NewDecoder(response.Body).Decode(&lrpInstances)
Expect(err).NotTo(HaveOccurred())
Expect(lrpInstances).To(HaveLen(3))
for i, _ := range lrpInstances {
Expect(lrpInstances[i]).NotTo(BeZero())
lrpInstances[i].Since = 0
示例6: getBuild
func getBuild(client *http.Client, reqGenerator *rata.RequestGenerator, jobName string, buildName string, pipelineName string) atc.Build {
if pipelineName != "" && jobName == "" {
fmt.Fprintln(os.Stderr, "job must be specified if pipeline is specified")
os.Exit(1)
}
if pipelineName == "" {
pipelineName = atc.DefaultPipelineName
}
if buildName != "" {
var buildReq *http.Request
var err error
if jobName != "" {
buildReq, err = reqGenerator.CreateRequest(
atc.GetJobBuild,
rata.Params{
"job_name": jobName,
"build_name": buildName,
"pipeline_name": pipelineName,
},
nil,
)
} else {
buildReq, err = reqGenerator.CreateRequest(
atc.GetBuild,
rata.Params{"build_id": buildName},
nil,
)
}
if err != nil {
log.Fatalln("failed to create request", err)
}
buildResp, err := client.Do(buildReq)
if err != nil {
log.Fatalln("failed to get builds:", err)
}
if buildResp.StatusCode != http.StatusOK {
log.Println("bad response when getting build:")
buildResp.Body.Close()
buildResp.Write(os.Stderr)
os.Exit(1)
}
var build atc.Build
err = json.NewDecoder(buildResp.Body).Decode(&build)
if err != nil {
log.Fatalln("failed to decode job:", err)
}
return build
} else if jobName != "" {
jobReq, err := reqGenerator.CreateRequest(
atc.GetJob,
rata.Params{"job_name": jobName, "pipeline_name": pipelineName},
nil,
)
if err != nil {
log.Fatalln("failed to create request", err)
}
jobResp, err := client.Do(jobReq)
if err != nil {
log.Fatalln("failed to get builds:", err)
}
if jobResp.StatusCode != http.StatusOK {
log.Println("bad response when getting job:")
jobResp.Body.Close()
jobResp.Write(os.Stderr)
os.Exit(1)
}
var job atc.Job
err = json.NewDecoder(jobResp.Body).Decode(&job)
if err != nil {
log.Fatalln("failed to decode job:", err)
}
if job.NextBuild != nil {
return *job.NextBuild
} else if job.FinishedBuild != nil {
return *job.FinishedBuild
} else {
println("job has no builds")
os.Exit(1)
}
} else {
buildsReq, err := reqGenerator.CreateRequest(
atc.ListBuilds,
nil,
nil,
)
if err != nil {
log.Fatalln("failed to create request", err)
}
//.........這裏部分代碼省略.........
示例7:
err = desireTaskRequest.Unmarshal(data)
Expect(err).NotTo(HaveOccurred())
Expect(desireTaskRequest.TaskDefinition.MemoryMb).To(Equal(int32(1024)))
Expect(desireTaskRequest.TaskDefinition.DiskMb).To(Equal(int32(128)))
Expect(desireTaskRequest.TaskDefinition.CompletionCallbackUrl).To(Equal(callbackURL))
})
req, err := requestGenerator.CreateRequest(stager.StageRoute, rata.Params{"staging_guid": "my-task-guid"}, strings.NewReader(`{
"app_id":"my-app-guid",
"file_descriptors":3,
"memory_mb" : 1024,
"disk_mb" : 128,
"environment" : [],
"lifecycle": "buildpack",
"lifecycle_data": {
"buildpacks" : [],
"stack":"linux",
"app_bits_download_uri":"http://example.com/app_bits"
}
}`))
Expect(err).NotTo(HaveOccurred())
req.Header.Set("Content-Type", "application/json")
resp, err := httpClient.Do(req)
Expect(err).NotTo(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusAccepted))
Eventually(fakeBBS.ReceivedRequests).Should(HaveLen(1))
Consistently(runner.Session()).ShouldNot(gexec.Exit())
示例8:
process ifrit.Process
)
requestDesireWithInstances := func(nInstances int) (*http.Response, error) {
req, err := requestGenerator.CreateRequest(nsync.DesireAppRoute, rata.Params{"process_guid": "the-guid"}, strings.NewReader(`{
"process_guid": "the-guid",
"droplet_uri": "http://the-droplet.uri.com",
"start_command": "the-start-command",
"execution_metadata": "execution-metadata-1",
"memory_mb": 128,
"disk_mb": 512,
"file_descriptors": 32,
"num_instances": `+strconv.Itoa(nInstances)+`,
"stack": "some-stack",
"log_guid": "the-log-guid",
"health_check_timeout_in_seconds": 123456,
"ports": [8080,5222],
"etag": "2.1",
"routing_info": {
"http_routes": [
{"hostname": "route-1"}
],
"tcp_routes": [
{"router_group_guid": "guid-1", "external_port":5222, "container_port":60000}
]
}
}`))
Expect(err).NotTo(HaveOccurred())
req.Header.Set("Content-Type", "application/json")
return httpClient.Do(req)