Ejemplo n.º 1
0
			fakeserver.AppendHandlers(ghttp.CombineHandlers(
				ghttp.VerifyRequest("POST", "/modules/"),
				ghttp.RespondWithJSONEncodedPtr(&statusCode, &module),
			))
			err := dataplane.Init(fakeserver.URL())
			Expect(err).NotTo(HaveOccurred())
			Expect(dataplane.Id()).To(Equal("some-module-id"))
		})
		It("Adds a policy to the server", func() {
			entry = models.TableEntry{
				Key:   fmt.Sprintf("{ %s %s %s %s %s [ 0 0 0 ]}", "200", "200", "0", "0", "20"),
				Value: "0",
			}
			fakeserver.AppendHandlers(ghttp.CombineHandlers(
				ghttp.VerifyRequest("POST", "/modules/"+dataplane.Id()+"/tables/rules/entries/"),
				ghttp.VerifyJSONRepresenting(&entry),
				ghttp.RespondWithJSONEncodedPtr(&statusCode, &entry),
			))
			err := dataplane.AddPolicy("200", "", "200", "", "20", "allow")
			Expect(err).NotTo(HaveOccurred())
		})
		Context("when adding a policy to the server fails", func() {
			BeforeEach(func() {
				statusCode = http.StatusInternalServerError
				fakeserver.AppendHandlers(ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/modules/"+dataplane.Id()+"/tables/rules/entries/"),
					ghttp.RespondWithJSONEncodedPtr(&statusCode, models.TableEntry{}),
				))
			})
			It("Returns an error", func() {
				err := dataplane.AddPolicy("200", "", "200", "", "20", "allow")
Ejemplo n.º 2
0
					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),
				),
			)
		})

		Context("when recurrenceType is not provided", func() {
			BeforeEach(func() {
				task.RecurrenceType = ""
			})

			It("does not allow recurrenceCount to be non-zero", func() {
				task.RecurrenceCount = 1
				_, err := client.UpdateTask(task)

				Expect(err).To(HaveOccurred())
Ejemplo n.º 3
0
			})
		})
	})

	Context("DeleteRoutes", func() {
		var err error
		JustBeforeEach(func() {
			err = client.DeleteRoutes([]db.Route{route1, route2})
		})

		Context("when the server returns a valid response", func() {
			BeforeEach(func() {
				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("DELETE", "/v1/routes"),
						ghttp.VerifyJSONRepresenting([]db.Route{route1, route2}),
					),
				)
			})

			It("sends a Delete request to the server", func() {
				Expect(server.ReceivedRequests()).Should(HaveLen(1))
			})

			It("does not receive an error", func() {
				Expect(err).NotTo(HaveOccurred())
			})

			It("logs the request and response", func() {
				expectedBody, _ := json.Marshal([]db.Route{route1, route2})
Ejemplo n.º 4
0
				},
			}
			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(
		BeforeEach(func() {
			ranB = false
			parallelNode, parallelTotal = 1, 3
		})

		Context("as the first node, it runs A", func() {
			var expectedState types.RemoteBeforeSuiteData

			BeforeEach(func() {
				parallelNode, parallelTotal = 1, 3
			})

			JustBeforeEach(func() {
				server.AppendHandlers(ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/BeforeSuiteState"),
					ghttp.VerifyJSONRepresenting(expectedState),
				))

				outcome = node.Run(parallelNode, parallelTotal, server.URL())
			})

			Context("when A succeeds", func() {
				BeforeEach(func() {
					expectedState = types.RemoteBeforeSuiteData{[]byte("my data"), types.RemoteBeforeSuiteStatePassed}

					node = newNode(func() []byte {
						return []byte("my data")
					}, func([]byte) {
						ranB = true
					})
				})
			BeforeEach(func() {
				expectedCNIPayload = models.CNIAddPayload{
					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": {
Ejemplo n.º 7
0
		BeforeEach(func() {
			listPosition = wl.Position{
				ID: 1234,
			}
		})

		It("performs PATCH requests with correct headers to /list_positions/:id", func() {
			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("PATCH", "/list_positions/1234"),
					ghttp.VerifyHeader(http.Header{
						"X-Access-Token": []string{dummyAccessToken},
						"X-Client-ID":    []string{dummyClientID},
					}),
					ghttp.VerifyJSONRepresenting(listPosition),
				),
			)

			client.UpdateListPosition(listPosition)

			Expect(server.ReceivedRequests()).Should(HaveLen(1))
		})

		Context("when the request is valid", func() {
			It("returns successfully", func() {
				expectedListPosition := wl.Position{
					ID: listPosition.ID,
				}

				server.AppendHandlers(
Ejemplo n.º 8
0
		AfterEach(func() {
			authServer.Close()
			server.Close()
		})

		It("registers a route to the routing api", func() {
			command := buildCommand("register", flags, []string{`[{"route":"zak.com","port":3,"ip":"4"}]`})

			server.SetHandler(0,
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/v1/routes"),
					ghttp.VerifyJSONRepresenting([]map[string]interface{}{
						{
							"route":    "zak.com",
							"port":     3,
							"ip":       "4",
							"ttl":      0,
							"log_guid": "",
						},
					}),
					ghttp.RespondWithJSONEncoded(http.StatusOK, nil),
				),
			)

			session := routeRegistrar(command...)

			Eventually(session, "2s").Should(Exit(0))
			Expect(server.ReceivedRequests()).To(HaveLen(1))
		})

		It("registers multiple routes to the routing api", func() {
Ejemplo n.º 9
0
			expectedBuild = atc.Build{
				ID:      123,
				Name:    "mybuild",
				Status:  "succeeded",
				JobName: "myjob",
				URL:     "/builds/123",
				APIURL:  "/api/v1/builds/123",
			}

			expectedURL := "/api/v1/builds"

			atcServer.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", expectedURL),
					ghttp.VerifyJSONRepresenting(plan),
					ghttp.RespondWithJSONEncoded(http.StatusCreated, expectedBuild),
				),
			)
		})

		It("takes a plan and creates the build", func() {
			build, err := client.CreateBuild(plan)
			Expect(err).NotTo(HaveOccurred())
			Expect(build).To(Equal(expectedBuild))
		})
	})

	Describe("CreateJobBuild", func() {
		var (
			pipelineName  string
Ejemplo n.º 10
0
		BeforeEach(func() {
			list = wl.List{
				ID: 1234,
			}
		})

		It("performs PATCH requests with correct headers to /lists/:id", func() {
			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("PATCH", "/lists/1234"),
					ghttp.VerifyHeader(http.Header{
						"X-Access-Token": []string{dummyAccessToken},
						"X-Client-ID":    []string{dummyClientID},
					}),
					ghttp.VerifyJSONRepresenting(list),
				),
			)

			client.UpdateList(list)

			Expect(server.ReceivedRequests()).Should(HaveLen(1))
		})

		Context("when the request is valid", func() {
			It("returns successfully", func() {
				expectedList := wl.List{ID: list.ID}

				// Marshal and unmarshal to ensure exact object is returned
				// - this avoids odd behavior with the time fields
				expectedBody, err := json.Marshal(expectedList)
Ejemplo n.º 11
0
			reminder wl.Reminder
		)

		BeforeEach(func() {
			reminder = wl.Reminder{ID: 1234}
		})

		It("performs GET requests with correct headers to /reminders/:id", func() {
			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("PATCH", "/reminders/1234"),
					ghttp.VerifyHeader(http.Header{
						"X-Access-Token": []string{dummyAccessToken},
						"X-Client-ID":    []string{dummyClientID},
					}),
					ghttp.VerifyJSONRepresenting(reminder),
				),
			)

			client.UpdateReminder(reminder)

			Expect(server.ReceivedRequests()).Should(HaveLen(1))
		})

		Context("when the request is valid", func() {
			It("returns successfully", func() {
				expectedReminder := wl.Reminder{ID: 2345}

				// Marshal and unmarshal to ensure exact object is returned
				// - this avoids odd behavior with the time fields
				expectedBody, err := json.Marshal(expectedReminder)
Ejemplo n.º 12
0
			membership = wl.Membership{ID: 1234}
		})

		It("performs POST requests with correct headers to /memberships/:userID", func() {
			expectedMembership := wl.Membership{
				ID:    membership.ID,
				State: "accepted",
			}
			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("PATCH", "/memberships/1234"),
					ghttp.VerifyHeader(http.Header{
						"X-Access-Token": []string{dummyAccessToken},
						"X-Client-ID":    []string{dummyClientID},
					}),
					ghttp.VerifyJSONRepresenting(expectedMembership),
				),
			)

			client.AcceptMember(membership)

			Expect(server.ReceivedRequests()).Should(HaveLen(1))
		})

		Context("when the request is valid", func() {
			It("returns successfully", func() {
				expectedMembership := wl.Membership{
					ID: membership.ID,
				}

				server.AppendHandlers(
Ejemplo n.º 13
0
		server = ghttp.NewServer()
		os.Args = []string{"basic", "-insecure", "-e=dummy", "-p=dummy", "-a=42", "-h=" + server.URL()[7:]}
		osStdout = &out
	})

	AfterEach(func() {
		server.Close()
	})

	It("lists executions", func() {
		server.AppendHandlers(
			ghttp.CombineHandlers(
				ghttp.VerifyRequest("POST", "/api/sessions"),
				ghttp.VerifyJSONRepresenting(map[string]interface{}{
					"email":        "dummy",
					"password":     "******",
					"account_href": "/api/accounts/42",
				}),
				ghttp.RespondWith(204, ""),
			),
			ghttp.CombineHandlers(
				ghttp.VerifyRequest("GET", "/api/sessions"),
				ghttp.RespondWith(200, ""),
			),
			ghttp.CombineHandlers(
				ghttp.VerifyRequest("GET", "/api/clouds"),
				ghttp.RespondWith(200, responseBody),
			),
		)
		main()
		Ω(out.String()).Should(Equal(output))
Ejemplo n.º 14
0
				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{
						Name:    "Some-Cookie",
						Value:   "some-cookie-data",
						Path:    "/",
						Expires: time.Now().Add(1 * time.Minute),
					})
				},
				ghttp.RespondWith(201, `{"id":128}`),
			),
		)
		atcServer.RouteToHandler("GET", "/api/v1/builds/128/events",
			ghttp.CombineHandlers(
				ghttp.VerifyRequest("GET", "/api/v1/builds/128/events"),
				func(w http.ResponseWriter, r *http.Request) {
Ejemplo n.º 15
0
			file, _ := ioutil.TempDir(os.TempDir(), "gohan_test")
			os.Setenv("GOHAN_CACHE_SCHEMAS", "true")
			os.Setenv("GOHAN_CACHE_PATH", file)
			opts, _ := NewOptsFromEnv()
			gohanClientCLI, err := NewGohanClientCLI(opts)
			Expect(gohanClientCLI).To(BeNil())
			Expect(err).To(HaveOccurred())
		})
	})

	Describe("Keystone interaction", func() {
		Describe("Authentication", func() {
			It("Should authenticate successfully", func() {
				server.AppendHandlers(ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/v2.0/tokens"),
					ghttp.VerifyJSONRepresenting(getAuthRequest()),
					ghttp.RespondWithJSONEncoded(200, getAuthResponse(server.URL())),
				))
				provider, err = getProviderClient()
				Expect(err).ToNot(HaveOccurred())
				Expect(provider.IdentityBase).To(Equal(server.URL() + "/"))
				Expect(provider.IdentityEndpoint).To(Equal(server.URL() + "/v2.0/"))
				Expect(provider.TokenID).To(Equal("admin_token"))
			})

			It("Should show error - OS_AUTH_URL not set", func() {
				os.Unsetenv("OS_AUTH_URL")
				provider, err = getProviderClient()
				Expect(provider).To(BeNil())
				Expect(err).To(MatchError("Environment variable OS_AUTH_URL needs to be set."))
			})
Ejemplo n.º 16
0
		var testContainer garden.ContainerSpec

		BeforeEach(func() {
			testContainer = garden.ContainerSpec{
				Handle:     "Fred",
				GraceTime:  1 * time.Second,
				RootFSPath: "/stuff",
				Env: []string{
					"jim",
					"jane",
				},
			}
			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/api/containers"),
					ghttp.VerifyJSONRepresenting(testContainer),
					ghttp.RespondWith(200, `{"handle":"ServerChangedHandle"}`),
				),
			)
		})

		It("makes a call out to an external service", func() {
			_, err := dotNetBackend.Create(testContainer)
			Expect(err).NotTo(HaveOccurred())
			Expect(server.ReceivedRequests()).Should(HaveLen(1))
		})

		It("sets the container's handle from the response", func() {
			container, err := dotNetBackend.Create(testContainer)
			Expect(err).NotTo(HaveOccurred())
			Expect(container.Handle()).To(Equal("ServerChangedHandle"))
Ejemplo n.º 17
0
				expectedRequestBody = requestBody{
					ProductFile: pivnet.ProductFile{
						FileType:     "Software",
						FileVersion:  createProductFileConfig.FileVersion,
						Name:         createProductFileConfig.Name,
						MD5:          "not-supported-yet",
						AWSObjectKey: createProductFileConfig.AWSObjectKey,
					},
				}
			})

			It("creates the release with the minimum required fields", func() {
				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("POST", apiPrefix+"/products/"+productSlug+"/product_files"),
						ghttp.VerifyJSONRepresenting(&expectedRequestBody),
						ghttp.RespondWith(http.StatusCreated, validResponse),
					),
				)

				release, err := client.CreateProductFile(createProductFileConfig)
				Expect(err).NotTo(HaveOccurred())
				Expect(release.ID).To(Equal(1234))
			})
		})

		Context("when the server responds with a non-201 status code", func() {
			It("returns an error", func() {
				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("POST", apiPrefix+"/products/"+productSlug+"/product_files"),
Ejemplo n.º 18
0
		Context("when streaming succeeds to completion", func() {
			BeforeEach(func() {
				spec = garden.ProcessSpec{
					Path:   "lol",
					Args:   []string{"arg1", "arg2"},
					Dir:    "/some/dir",
					User:   "******",
					Limits: resourceLimits,
				}
				stdInContent = make(chan string)

				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("POST", "/containers/foo-handle/processes"),
						ghttp.VerifyJSONRepresenting(spec),
						func(w http.ResponseWriter, r *http.Request) {
							w.WriteHeader(http.StatusOK)

							conn, br, err := w.(http.Hijacker).Hijack()
							Ω(err).ShouldNot(HaveOccurred())

							defer conn.Close()

							decoder := json.NewDecoder(br)

							transport.WriteMessage(conn, map[string]interface{}{
								"process_id": 42,
								"stream_id":  "123",
							})
Ejemplo n.º 19
0
			})
		})
	})

	Context("DeleteRoutes", func() {
		var err error
		JustBeforeEach(func() {
			err = client.DeleteRoutes([]models.Route{route1, route2})
		})

		Context("when the server returns a valid response", func() {
			BeforeEach(func() {
				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("DELETE", ROUTES_API_URL),
						ghttp.VerifyJSONRepresenting([]models.Route{route1, route2}),
					),
				)
			})

			It("sends a Delete request to the server", func() {
				Expect(server.ReceivedRequests()).Should(HaveLen(1))
			})

			It("does not receive an error", func() {
				Expect(err).NotTo(HaveOccurred())
			})

			It("logs the request and response", func() {
				expectedBody, _ := json.Marshal([]models.Route{route1, route2})