func CreateUaaProtectedServer(manifest string, deployments []models.IndexDeployment, uaaEndpoint string) *ghttp.Server { yaml, err := ioutil.ReadFile(manifest) Expect(err).ToNot(HaveOccurred()) diegoDeployment := models.ShowDeployment{ Manifest: string(yaml), } server := ghttp.NewServer() server.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/info"), ghttp.RespondWith(200, fmt.Sprintf(`{"user_authentication":{"type":"uaa","options":{"url":"%s"}}}`, uaaEndpoint)), ), ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/deployments"), ghttp.VerifyHeader(http.Header{"Authorization": []string{"bearer the token"}}), ghttp.RespondWithJSONEncoded(200, deployments), ), ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/deployments/cf-warden-diego"), ghttp.VerifyHeader(http.Header{"Authorization": []string{"bearer the token"}}), ghttp.RespondWithJSONEncoded(200, diegoDeployment), ), ) return server }
func CreateServer(manifest string, deployments []models.IndexDeployment) *ghttp.Server { yaml, err := ioutil.ReadFile(manifest) Expect(err).ToNot(HaveOccurred()) diegoDeployment := models.ShowDeployment{ Manifest: string(yaml), } server := ghttp.NewServer() server.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/info"), ghttp.RespondWith(200, `{"user_authentication":{"type":"basic"}}`), ), ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/deployments"), ghttp.RespondWithJSONEncoded(200, deployments), ), ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/deployments/cf-warden-diego"), ghttp.RespondWithJSONEncoded(200, diegoDeployment), ), ) return server }
func Create401Server() *ghttp.Server { server := ghttp.NewServer() server.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/info"), ghttp.RespondWithJSONEncoded(200, `{"user_authentication":{"type":"basic"}}`), ), ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/deployments"), ghttp.RespondWith(401, "Not authorized"), ), ) return server }
flushEvents chan struct{} ) var getActualLRPGroups = func() []*models.ActualLRPGroup { actualLRPGroups, err := bbsClient.ActualLRPGroups(models.ActualLRPFilter{}) Expect(err).NotTo(HaveOccurred()) return actualLRPGroups } BeforeEach(func() { Eventually(getActualLRPGroups, 5*pollingInterval).Should(BeEmpty()) flushEvents = make(chan struct{}) fakeGarden = ghttp.NewUnstartedServer() // these tests only look for the start of a sequence of requests fakeGarden.AllowUnhandledRequests = false fakeGarden.RouteToHandler("GET", "/ping", ghttp.RespondWithJSONEncoded(http.StatusOK, struct{}{})) fakeGarden.RouteToHandler("GET", "/containers", ghttp.RespondWithJSONEncoded(http.StatusOK, struct{}{})) fakeGarden.RouteToHandler("GET", "/capacity", ghttp.RespondWithJSONEncoded(http.StatusOK, garden.Capacity{MemoryInBytes: 1024 * 1024 * 1024, DiskInBytes: 2048 * 1024 * 1024, MaxContainers: 4})) fakeGarden.RouteToHandler("GET", "/containers/bulk_info", ghttp.RespondWithJSONEncoded(http.StatusOK, struct{}{})) logger = lagertest.NewTestLogger("test") serviceClient = bbs.NewServiceClient(consulSession, clock.NewClock()) pollingInterval = 50 * time.Millisecond evacuationTimeout = 200 * time.Millisecond rootFSName = "the-rootfs" rootFSPath = "/path/to/rootfs" rootFSArg := fmt.Sprintf("%s:%s", rootFSName, rootFSPath)
token = uuid.NewUUID().String() responseBody := &token_fetcher.Token{ AccessToken: token, ExpireTime: 20, } authServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/oauth/token"), ghttp.VerifyBasicAuth("some-name", "some-secret"), ghttp.VerifyContentType("application/x-www-form-urlencoded; charset=UTF-8"), ghttp.VerifyHeader(http.Header{ "Accept": []string{"application/json; charset=utf-8"}, }), verifyBody("grant_type=client_credentials"), ghttp.RespondWithJSONEncoded(http.StatusOK, responseBody), )) server.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v1/routes"), ghttp.VerifyHeader(http.Header{ "Authorization": []string{"bearer " + token}, }), ghttp.RespondWithJSONEncoded(http.StatusOK, nil), ), ) flags = []string{ "-api", server.URL(), "-client-id", "some-name",
}) Context("when specifying a pipeline name", func() { var path string BeforeEach(func() { var err error path, err = atc.Routes.CreatePathForRoute(atc.GetConfig, rata.Params{"pipeline_name": "some-pipeline"}) Expect(err).NotTo(HaveOccurred()) }) Context("when atc returns valid config", func() { BeforeEach(func() { atcServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("GET", path), ghttp.RespondWithJSONEncoded(200, atc.ConfigResponse{Config: &config}, http.Header{atc.ConfigVersionHeader: {"42"}}), ), ) }) It("prints the config as yaml to stdout", func() { flyCmd := exec.Command(flyPath, "-t", targetName, "get-pipeline", "--pipeline", "some-pipeline") sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) <-sess.Exited Expect(sess.ExitCode()).To(Equal(0)) var printedConfig atc.Config err = yaml.Unmarshal(sess.Out.Contents(), &printedConfig)
err := os.RemoveAll(tmpdir) Expect(err).NotTo(HaveOccurred()) err = os.RemoveAll(outputDir) Expect(err).NotTo(HaveOccurred()) }) JustBeforeEach(func() { uploading := make(chan struct{}) uploadingBits = uploading atcServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/api/v1/pipes"), ghttp.RespondWithJSONEncoded(http.StatusCreated, atc.Pipe{ ID: "some-pipe-id", }), ), ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/api/v1/pipes"), ghttp.RespondWithJSONEncoded(http.StatusCreated, atc.Pipe{ ID: "some-other-pipe-id", }), ), ) atcServer.RouteToHandler("POST", "/api/v1/builds", ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/api/v1/builds"), ghttp.VerifyJSONRepresenting(expectedPlan), func(w http.ResponseWriter, r *http.Request) { http.SetCookie(w, &http.Cookie{
RecurrenceCount: recurrenceCount, DueDate: "1968-01-02", Starred: starred, Remove: []string{}, } }) JustBeforeEach(func() { server.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/tasks/1234"), ghttp.VerifyHeader(http.Header{ "X-Access-Token": []string{dummyAccessToken}, "X-Client-ID": []string{dummyClientID}, }), ghttp.RespondWithJSONEncoded(http.StatusOK, originalTask), ), ) server.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("PATCH", "/tasks/1234"), ghttp.VerifyHeader(http.Header{ "X-Access-Token": []string{dummyAccessToken}, "X-Client-ID": []string{dummyClientID}, }), ghttp.VerifyJSONRepresenting(expectedTaskUpdateConfig), ghttp.RespondWithJSONEncoded(http.StatusOK, expectedTask), ), ) })
}, }, } }) AfterEach(func() { err := os.RemoveAll(home) Ω(err).ShouldNot(HaveOccurred()) }) Context("when a pipeline name is not specified", func() { BeforeEach(func() { atcServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/api/v1/pipelines/some-pipeline/config"), ghttp.RespondWithJSONEncoded(200, config, http.Header{atc.ConfigVersionHeader: {"42"}}), ), ) }) It("prints the config as yaml to stdout", func() { flyCmd := exec.Command(flyPath, "-t", "target-name", "checklist", "some-pipeline") sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) Ω(err).ShouldNot(HaveOccurred()) <-sess.Exited Ω(sess.ExitCode()).Should(Equal(0)) Ω(string(sess.Out.Contents())).Should(Equal(fmt.Sprintf( `#- some-group
}) Context("when the request is valid", func() { It("returns successfully", func() { expectedNotes := []wl.Note{{ID: 2345}} // Marshal and unmarshal to ensure exact object is returned // - this avoids odd behavior with the time fields expectedBody, err := json.Marshal(expectedNotes) Expect(err).NotTo(HaveOccurred()) err = json.Unmarshal(expectedBody, &expectedNotes) Expect(err).NotTo(HaveOccurred()) server.AppendHandlers( ghttp.CombineHandlers( ghttp.RespondWithJSONEncoded(http.StatusOK, expectedNotes), ), ) notes, err := client.NotesForListID(listID) Expect(err).NotTo(HaveOccurred()) Expect(notes).To(Equal(expectedNotes)) }) }) Context("when ListID == 0", func() { BeforeEach(func() { listID = 0 })
It("returns the product returned by the server", func() { serverProd := resource.Product{ Releases: []resource.Release{ resource.Release{ Id: 12, Version: "some-version", }, }, } server.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/api/v2/products/my-prod/releases"), verifyHeaders, ghttp.RespondWithJSONEncoded(http.StatusOK, serverProd), ), ) prod, err := req.GetProduct("my-prod") Expect(server.ReceivedRequests()).To(HaveLen(1)) Expect(err).ToNot(HaveOccurred()) Expect(prod).To(Equal(&serverProd)) }) }) Context("GetProductFiles", func() { It("returns an error if the release doesn't have product_files", func() { delete(testRelease.Links, "product_files")
Expect(res).To(Equal("v3")) res = matchVersionFromAuthURL("http://example.com:5000/v3/") Expect(res).To(Equal("v3")) }) It("Should should match no version", func() { res := matchVersionFromAuthURL("http://example.com:5000/nonsense") Expect(res).To(Equal("")) }) }) Describe("Tenant ID <-> Tenant Name Mapper", func() { Context("Keystone v2", func() { BeforeEach(func() { server.AppendHandlers( ghttp.RespondWithJSONEncoded(200, getV2TokensResponse()), ) client, _ = NewKeystoneV2Client(server.URL()+"/v2.0", username, password, tenantName) }) It("Should map Tenant Name to Tenant ID successfully", func() { server.AppendHandlers( ghttp.RespondWithJSONEncoded(200, getV2TenantsResponse()), ghttp.RespondWithJSONEncoded(200, getV2TenantsResponse()), ) tenantID, err := client.GetTenantID("admin") Expect(err).ToNot(HaveOccurred()) Expect(tenantID).To(Equal("1234")) tenantID, err = client.GetTenantID("demo") Expect(err).ToNot(HaveOccurred())
State: receptor.ActualLRPStateRunning, }, } tasksResponse := []receptor.TaskResponse{ {TaskGuid: "task-guid"}, } BeforeEach(func() { outputBuffer = gbytes.NewBuffer() fakeServer = ghttp.NewServer() listenerAddr = fakeServer.HTTPTestServer.Listener.Addr().String() fakeServer.RouteToHandler("GET", "/v1/desired_lrps", ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/v1/desired_lrps"), ghttp.RespondWithJSONEncoded(http.StatusOK, desiredResponse), ), ) fakeServer.RouteToHandler("GET", "/v1/actual_lrps", ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/v1/actual_lrps"), ghttp.RespondWithJSONEncoded(http.StatusOK, actualResponse), ), ) fakeServer.RouteToHandler("GET", "/v1/tasks", ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/v1/tasks"), ghttp.RespondWithJSONEncoded(http.StatusOK, tasksResponse), ), )
}) It("Should show error - error parsing GOHAN_CACHE_TIMEOUT", func() { os.Setenv("GOHAN_CACHE_TIMEOUT", "this is not time") opts, err := NewOptsFromEnv() Expect(opts).To(BeNil()) Expect(err).To(HaveOccurred()) }) }) Describe("GohanClientCLI constructor", func() { BeforeEach(func() { server.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/v2.0/tokens"), ghttp.RespondWithJSONEncoded(200, getAuthResponse(server.URL())), ), ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/gohan/v0.1/schemas"), ghttp.RespondWithJSONEncoded(200, getSchemasResponse()), ), ) }) It("Should create GohanClientCLI instance successfully", func() { opts, _ := NewOptsFromEnv() gohanClientCLI, err := NewGohanClientCLI(opts) Expect(err).ToNot(HaveOccurred()) Expect(gohanClientCLI).ToNot(BeNil()) })
{ ID: "myid-1", PipelineName: "mypipeline-1", WorkingDirectory: "/tmp/build/some-guid", }, { ID: "myid-2", PipelineName: "mypipeline-2", WorkingDirectory: "/tmp/build/some-other-guid", }, } atcServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("GET", expectedURL), ghttp.RespondWithJSONEncoded(http.StatusOK, expectedContainers), ), ) }) It("returns all the containers", func() { containers, err := client.ListContainers(map[string]string{}) Expect(err).NotTo(HaveOccurred()) Expect(containers).To(Equal(expectedContainers)) }) }) Context("when passed a nonempty specification list", func() { var ( expectedContainers []atc.Container expectedQueryList map[string]string
client = github.NewClient() proxiedClient = &http.Client{ Transport: proxiedTransport{githubServer}, } }) Describe("CurrentUser", func() { Context("when getting the current user succeeds", func() { BeforeEach(func() { githubServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/user"), ghttp.RespondWithJSONEncoded(http.StatusOK, gogithub.User{ Login: gogithub.String("some-user"), }), ), ) }) It("returns the user's login", func() { user, err := client.CurrentUser(proxiedClient) Expect(err).NotTo(HaveOccurred()) Expect(user).To(Equal("some-user")) }) }) Context("when getting the current user fails", func() { BeforeEach(func() { githubServer.AppendHandlers(
}, }, }, }, }, } }) JustBeforeEach(func() { uploading = make(chan struct{}) atcServer.RouteToHandler("POST", "/api/v1/pipes", ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/api/v1/pipes"), ghttp.RespondWithJSONEncoded(http.StatusCreated, atc.Pipe{ ID: "some-pipe-id", }), ), ) atcServer.RouteToHandler("GET", "/api/v1/pipelines/some-pipeline/jobs/some-job/inputs", ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/api/v1/pipelines/some-pipeline/jobs/some-job/inputs"), ghttp.RespondWithJSONEncoded(http.StatusOK, []atc.BuildInput{ { Name: "some-input", Type: "git", Resource: "some-resource", Source: atc.Source{"uri": "https://internet.com"}, Params: atc.Params{"some": "params"}, Version: atc.Version{"some": "version"}, Tags: atc.Tags{"tag-1", "tag-2"},
Args: "FOO=BAR;ABC=123", ContainerNamespace: "/some/namespace/path", InterfaceName: "interface-name", ContainerID: "some-container-id", Network: models.NetworkPayload{ Properties: models.Properties{ AppID: "some-app-id", }, }, } server.AppendHandlers(ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/cni/add"), ghttp.VerifyJSONRepresenting(expectedCNIPayload), ghttp.VerifyHeaderKV("Content-type", "application/json"), ghttp.RespondWithJSONEncoded(http.StatusCreated, types.Result{}), )) }) It("passes it through", func() { _, err := c.CNIAdd(&skel.CmdArgs{ ContainerID: "some-container-id", Netns: "/some/namespace/path", IfName: "interface-name", Args: "FOO=BAR;ABC=123", StdinData: []byte(`{ "network": { "network_id": "", "properties": { "app_id": "some-app-id" }
}) Context("when the request is valid", func() { It("returns successfully", func() { expectedTaskPositions := []wl.Position{{ID: 2345}} // Marshal and unmarshal to ensure exact object is returned // - this avoids odd behavior with the time fields expectedBody, err := json.Marshal(expectedTaskPositions) Expect(err).NotTo(HaveOccurred()) err = json.Unmarshal(expectedBody, &expectedTaskPositions) Expect(err).NotTo(HaveOccurred()) server.AppendHandlers( ghttp.CombineHandlers( ghttp.RespondWithJSONEncoded(http.StatusOK, expectedTaskPositions), ), ) taskPositions, err := client.TaskPositionsForListID(listID) Expect(err).NotTo(HaveOccurred()) Expect(taskPositions).To(Equal(expectedTaskPositions)) }) }) Context("when listID == 0", func() { BeforeEach(func() { listID = 0 })
var ( atcServer *ghttp.Server ) Describe("login with no target name", func() { var ( flyCmd *exec.Cmd ) BeforeEach(func() { atcServer = ghttp.NewServer() atcServer.AppendHandlers( infoHandler(), ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/api/v1/auth/methods"), ghttp.RespondWithJSONEncoded(200, []atc.AuthMethod{}), ), ) flyCmd = exec.Command(flyPath, "login", "-c", atcServer.URL()) }) It("instructs the user to specify --target", func() { sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) <-sess.Exited Expect(sess.ExitCode()).To(Equal(1)) Expect(sess.Err).To(gbytes.Say(`name for the target must be specified \(--target/-t\)`)) }) })
ghttp.RespondWithJSONEncoded(200, []atc.Container{ { ID: "handle-1", WorkerName: "worker-name-1", PipelineName: "pipeline-name", StepType: "check", ResourceName: "git-repo", }, { ID: "early-handle", WorkerName: "worker-name-1", PipelineName: "pipeline-name", JobName: "job-name-1", BuildName: "3", BuildID: 123, StepType: "get", StepName: "git-repo", Attempts: []int{1, 5}, }, { ID: "other-handle", WorkerName: "worker-name-2", PipelineName: "pipeline-name", JobName: "job-name-2", BuildName: "2", BuildID: 122, StepType: "task", StepName: "unit-tests", }, { ID: "post-handle", WorkerName: "worker-name-3", BuildID: 142, StepType: "task", StepName: "one-off", }, }),
Eventually(sess.Out).Should(gbytes.Say("sup")) close(events) <-sess.Exited Ω(sess.ExitCode()).Should(Equal(0)) } Context("with no arguments", func() { BeforeEach(func() { atcServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/api/v1/builds"), ghttp.RespondWithJSONEncoded(200, []atc.Build{ {ID: 4, Name: "1", Status: "started", JobName: "some-job"}, {ID: 3, Name: "3", Status: "started"}, {ID: 2, Name: "2", Status: "started"}, {ID: 1, Name: "1", Status: "finished"}, }), ), eventsHandler(), ) }) It("watches the most recent one-off build", func() { watch() }) }) Context("with a specific job and pipeline", func() { Context("when the job has a next build", func() { BeforeEach(func() {
Describe("authenticating with the cf realm with a one time code", func() { BeforeEach(func() { clientConfig = &ssh.ClientConfig{ User: "******", Auth: []ssh.AuthMethod{ssh.Password("abc123")}, } fakeUAA.RouteToHandler("POST", "/oauth/token", ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/oauth/token"), ghttp.VerifyBasicAuth("amandaplease", "password1"), ghttp.VerifyContentType("application/x-www-form-urlencoded"), ghttp.VerifyFormKV("grant_type", "authorization_code"), ghttp.VerifyFormKV("code", "abc123"), ghttp.RespondWithJSONEncoded(http.StatusOK, authenticators.UAAAuthTokenResponse{ AccessToken: "proxy-token", TokenType: "bearer", }), )) fakeCC.RouteToHandler("GET", "/internal/apps/60f0f26e-86b3-4487-8f19-9e94f848f3d2/ssh_access/99", ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/internal/apps/60f0f26e-86b3-4487-8f19-9e94f848f3d2/ssh_access/99"), ghttp.VerifyHeader(http.Header{"Authorization": []string{"bearer proxy-token"}}), ghttp.RespondWithJSONEncoded(http.StatusOK, authenticators.AppSSHResponse{ ProcessGuid: processGuid, }), )) }) It("provides the access code to the UAA and and gets an access token", func() { client, err := ssh.Dial("tcp", address, clientConfig) Expect(err).NotTo(HaveOccurred())
}) Describe(".FetchToken", func() { Context("when OAuth server cannot be reached", func() { It("returns an error", func() { cfg.TokenEndpoint = "http://bogus.url" fetcher := NewTokenFetcher(cfg) _, err := fetcher.FetchToken() Expect(err).To(HaveOccurred()) }) }) Context("when the respose body is malformed", func() { It("returns an error", func() { server.AppendHandlers( ghttp.RespondWithJSONEncoded(http.StatusOK, "broken garbage response"), ) fetcher := NewTokenFetcher(cfg) _, err := fetcher.FetchToken() Expect(err).To(HaveOccurred()) Expect(server.ReceivedRequests()).Should(HaveLen(1)) }) }) Context("when a non 200 OK is returned", func() { It("returns an error", func() { server.AppendHandlers( ghttp.RespondWith(http.StatusBadRequest, "you messed up"), )
hijack := func(args ...string) { fly("hijack", args...) } Context("with only a step name specified", func() { BeforeEach(func() { didHijack := make(chan struct{}) hijacked = didHijack atcServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/api/v1/builds"), ghttp.RespondWithJSONEncoded(200, []atc.Build{ {ID: 4, Name: "1", Status: "started", JobName: "some-job"}, {ID: 3, Name: "3", Status: "started"}, {ID: 2, Name: "2", Status: "started"}, {ID: 1, Name: "1", Status: "finished"}, }), ), ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/api/v1/containers", "build-id=3&step_name=some-step"), ghttp.RespondWithJSONEncoded(200, []atc.Container{ {ID: "container-id-1", BuildID: 3, StepType: "task", StepName: "some-step", User: user}, }), ), hijackHandler("container-id-1", didHijack, nil), ) }) It("hijacks the most recent one-off build", func() { hijack("-s", "some-step")
command.Env = os.Environ() command.Env = append(command.Env, fmt.Sprintf("ES_HOST=%s", host)) command.Env = append(command.Env, fmt.Sprintf("ES_PORT=%s", port)) }) AfterEach(func() { server.Close() }) Context("no index exists", func() { BeforeEach(func() { server.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("GET", KibanaConfigPath), ghttp.RespondWithJSONEncoded(http.StatusNotFound, ConfigResponse{ Found: false, }), ), ghttp.CombineHandlers( ghttp.VerifyRequest("PUT", KibanaIndexPath), ghttp.RespondWithJSONEncoded(http.StatusCreated, EmptyResponse{}), ), ghttp.CombineHandlers( ghttp.VerifyRequest("PUT", KibanaConfigPath), ghttp.RespondWithJSONEncoded(http.StatusCreated, EmptyResponse{}), ), ) }) It("creates index and adds utc config", func() { session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
}) AfterEach(func() { os.RemoveAll(tmpdir) }) JustBeforeEach(func() { uploading := make(chan struct{}) uploadingBits = uploading atcServer.RouteToHandler("POST", "/api/v1/pipes", ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/api/v1/pipes"), ghttp.RespondWithJSONEncoded(http.StatusCreated, atc.Pipe{ ID: "some-pipe-id", ReadURL: atcServer.URL() + "/api/v1/pipes/some-pipe-id", WriteURL: atcServer.URL() + "/api/v1/pipes/some-pipe-id", }), ), ) atcServer.RouteToHandler("POST", "/api/v1/builds", ghttp.CombineHandlers( ghttp.VerifyRequest("POST", "/api/v1/builds"), VerifyPlan(expectedPlan), func(w http.ResponseWriter, r *http.Request) { http.SetCookie(w, &http.Cookie{ Name: "Some-Cookie", Value: "some-cookie-data", Path: "/", Expires: time.Now().Add(1 * time.Minute), })
} expectedTeam = atc.Team{ ID: 1, Name: "team venture", } team = client.Team("team venture") }) Context("when passed a properly constructed team", func() { BeforeEach(func() { atcServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("PUT", expectedURL), ghttp.VerifyJSONRepresenting(desiredTeam), ghttp.RespondWithJSONEncoded(http.StatusCreated, expectedTeam), ), ) }) It("returns back the team", func() { team, _, _, err := team.CreateOrUpdate(desiredTeam) Expect(err).NotTo(HaveOccurred()) Expect(team).To(Equal(expectedTeam)) }) }) Context("when passed a team that doesn't exist", func() { BeforeEach(func() { atcServer.AppendHandlers( ghttp.CombineHandlers(
atcServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/api/v1/containers"), ghttp.RespondWithJSONEncoded(200, []atc.Container{ { ID: "handle-1", PipelineName: "pipeline-name", Type: "check", Name: "git-repo", BuildID: 0, WorkerName: "worker-name-1", }, { ID: "early-handle", PipelineName: "pipeline-name", Type: "get", Name: "git-repo", BuildID: 123, WorkerName: "worker-name-1", }, { ID: "other-handle", PipelineName: "pipeline-name", Type: "task", Name: "unit-tests", BuildID: 122, WorkerName: "worker-name-2", }, }), ), ) })
. "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/ghttp" ) var _ = Describe("CheckResource", func() { Context("when ATC request succeeds", func() { BeforeEach(func() { expectedURL := "/api/v1/teams/some-team/pipelines/mypipeline/resources/myresource/check" atcServer.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("POST", expectedURL), ghttp.VerifyJSON(`{"from":{"ref":"fake-ref"}}`), ghttp.RespondWithJSONEncoded(http.StatusOK, ""), ), ) }) It("sends check resource request to ATC", func() { found, err := team.CheckResource("mypipeline", "myresource", atc.Version{"ref": "fake-ref"}) Expect(err).NotTo(HaveOccurred()) Expect(found).To(BeTrue()) Expect(atcServer.ReceivedRequests()).To(HaveLen(1)) }) }) Context("when pipeline or resource does not exist", func() { BeforeEach(func() {