示例#1
0
	"github.com/cloudfoundry-incubator/bbs/models"
	"github.com/cloudfoundry-incubator/cf_http"
	"github.com/cloudfoundry-incubator/rep"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/ghttp"
)

var _ = Describe("Client", func() {
	var fakeServer *ghttp.Server
	var client rep.Client

	BeforeEach(func() {
		fakeServer = ghttp.NewServer()
		client = rep.NewClient(cf_http.NewClient(), fakeServer.URL())
	})

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

	Describe("StopLRPInstance", func() {
		const cellAddr = "cell.example.com"
		var stopErr error
		var actualLRP = models.ActualLRP{
			ActualLRPKey:         models.NewActualLRPKey("some-process-guid", 2, "test-domain"),
			ActualLRPInstanceKey: models.NewActualLRPInstanceKey("some-instance-guid", "some-cell-id"),
		}

		JustBeforeEach(func() {
示例#2
0
	bbsURL = &url.URL{
		Scheme: "http",
		Host:   bbsAddress,
	}

	bbsClient = bbs.NewClient(bbsURL.String())

	auctioneerServer = ghttp.NewServer()
	auctioneerServer.UnhandledRequestStatusCode = http.StatusAccepted
	auctioneerServer.AllowUnhandledRequests = true

	bbsArgs = bbstestrunner.Args{
		Address:           bbsAddress,
		AdvertiseURL:      bbsURL.String(),
		AuctioneerAddress: auctioneerServer.URL(),
		EtcdCluster:       strings.Join(etcdRunner.NodeURLS(), ","),
		ConsulCluster:     consulRunner.ConsulCluster(),

		EncryptionKeys: []string{"label:key"},
		ActiveKeyLabel: "label",
	}
})

var _ = BeforeEach(func() {
	etcdRunner.Start()
	consulRunner.Start()
	consulRunner.WaitUntilReady()

	bbsRunner = bbstestrunner.New(bbsPath, bbsArgs)
	bbsProcess = ginkgomon.Invoke(bbsRunner)
示例#3
0
		bulkerLockName    = "nsync_bulker_lock"
		pollingInterval   time.Duration
		heartbeatInterval time.Duration

		logger lager.Logger
	)

	startBulker := func(check bool) ifrit.Process {
		runner := ginkgomon.New(ginkgomon.Config{
			Name:          "nsync-bulker",
			AnsiColorCode: "97m",
			StartCheck:    "nsync.bulker.started",
			Command: exec.Command(
				bulkerPath,
				"-ccBaseURL", fakeCC.URL(),
				"-pollingInterval", pollingInterval.String(),
				"-domainTTL", domainTTL.String(),
				"-bulkBatchSize", "10",
				"-lifecycle", "buildpack/some-stack:some-health-check.tar.gz",
				"-lifecycle", "docker:the/docker/lifecycle/path.tgz",
				"-fileServerURL", "http://file-server.com",
				"-lockRetryInterval", "1s",
				"-consulCluster", consulRunner.ConsulCluster(),
				"-bbsAddress", fakeBBS.URL(),
				"-privilegedContainers", "false",
			),
		})

		if !check {
			runner.StartCheck = ""
示例#4
0
	AfterEach(func() {
		server.Close()
	})

	Describe("Post/PostCustomized", func() {
		It("makes a POST request with given payload", func() {
			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/path"),
					ghttp.VerifyBody([]byte("post-request")),
					ghttp.RespondWith(http.StatusOK, []byte("post-response")),
				),
			)

			url := server.URL() + "/path"

			response, err := httpClient.Post(url, []byte("post-request"))
			Expect(err).ToNot(HaveOccurred())

			defer response.Body.Close()

			responseBody, err := ioutil.ReadAll(response.Body)
			Expect(err).ToNot(HaveOccurred())

			Expect(responseBody).To(Equal([]byte("post-response")))
			Expect(response.StatusCode).To(Equal(200))

			Expect(server.ReceivedRequests()).To(HaveLen(1))
		})
示例#5
0
)

var _ = Describe("Testing misc requests", func() {

	var server *ghttp.Server
	var listener net.Listener
	var wstunsrv *WSTunnelServer
	var wstuncli *WSTunnelClient
	var wstunUrl string
	var wstunToken string

	BeforeEach(func() {
		// start ghttp to simulate target server
		wstunToken = "test567890123456-" + strconv.Itoa(rand.Int()%1000000)
		server = ghttp.NewServer()
		log15.Info("ghttp started", "url", server.URL())

		// start wstunsrv
		listener, _ = net.Listen("tcp", "127.0.0.1:0")
		wstunsrv = NewWSTunnelServer([]string{})
		wstunsrv.Start(listener)

		// start wstuncli
		wstuncli = NewWSTunnelClient([]string{
			"-token", wstunToken,
			"-tunnel", "ws://" + listener.Addr().String(),
			"-server", server.URL(),
			"-timeout", "3",
		})
		wstuncli.Start()
		wstunUrl = "http://" + listener.Addr().String()
示例#6
0
					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",
				"-client-secret", "some-secret",
				"-oauth-url", authServer.URL(),
			}
		})

		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,
示例#7
0
				path, err = atc.Routes.CreatePathForRoute(atc.PausePipeline, rata.Params{"pipeline_name": "awesome-pipeline"})
				Expect(err).NotTo(HaveOccurred())
			})

			Context("when the pipeline exists", func() {
				BeforeEach(func() {
					atcServer.AppendHandlers(
						ghttp.CombineHandlers(
							ghttp.VerifyRequest("PUT", path),
							ghttp.RespondWith(http.StatusOK, nil),
						),
					)
				})

				It("pauses the pipeline", func() {
					flyCmd := exec.Command(flyPath, "-t", atcServer.URL(), "pause-pipeline", "-p", "awesome-pipeline")

					sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
					Expect(err).NotTo(HaveOccurred())

					Eventually(sess).Should(gbytes.Say(`paused 'awesome-pipeline'`))

					<-sess.Exited
					Expect(sess.ExitCode()).To(Equal(0))
					Expect(atcServer.ReceivedRequests()).To(HaveLen(1))
				})
			})

			Context("when the pipeline doesn't exist", func() {
				BeforeEach(func() {
					atcServer.AppendHandlers(
示例#8
0
	"github.com/onsi/gomega/ghttp"
)

var _ = Describe("Testing xhost requests", func() {

	var server *ghttp.Server
	var wstuncli *WSTunnelClient
	var wstunsrv *WSTunnelServer
	var wstunUrl string
	var wstunToken string
	var cliStart func(server, regexp string) *WSTunnelClient

	BeforeEach(func() {
		wstunToken = "test567890123456-" + strconv.Itoa(rand.Int()%1000000)
		server = ghttp.NewServer()
		fmt.Fprintf(os.Stderr, "ghttp started on %s\n", server.URL())

		l, _ := net.Listen("tcp", "127.0.0.1:0")
		wstunsrv = NewWSTunnelServer([]string{})
		wstunsrv.Start(l)
		fmt.Fprintf(os.Stderr, "Server started\n")
		wstunUrl = "http://" + l.Addr().String()
		cliStart = func(server, regexp string) *WSTunnelClient {
			wstuncli = NewWSTunnelClient([]string{
				"-token", wstunToken, "-tunnel", "ws://" + l.Addr().String(),
				"-server", server, "-regexp", regexp,
			})
			wstuncli.Start()
			return wstuncli
		}
	})
示例#9
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/ghttp"
)

var _ = Describe("Flipkart", func() {
	var f *Flipkart
	var server *ghttp.Server

	BeforeEach(func() {
		server = ghttp.NewServer()
		f = &Flipkart{
			AffiliateId:   "fk-id",
			AffliateToken: "fk-secret",
			Host:          server.URL()[7:],
			Scheme:        "http",
		}
	})

	Context("TopOffers", func() {
		BeforeEach(func() {
			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("GET", "/affiliate/offers/v1/top/json"),
					ghttp.VerifyHeaderKV("Fk-Affiliate-Id", "fk-id"),
					ghttp.VerifyHeaderKV("Fk-Affiliate-Token", "fk-secret"),
					ghttp.RespondWith(200, topResult),
				))
		})
		It("retrieves the top offers", func() {
示例#10
0
		processGuid  string
		clientConfig *ssh.ClientConfig
	)

	BeforeEach(func() {
		fakeBBS = ghttp.NewServer()
		fakeUAA = ghttp.NewTLSServer()
		fakeCC = ghttp.NewTLSServer()

		privateKey, err := ssh.ParsePrivateKey([]byte(hostKeyPem))
		Expect(err).NotTo(HaveOccurred())
		hostKeyFingerprint = helpers.MD5Fingerprint(privateKey.PublicKey())

		address = fmt.Sprintf("127.0.0.1:%d", sshProxyPort)
		bbsAddress = fakeBBS.URL()
		ccAPIURL = fakeCC.URL()
		diegoCredentials = "some-creds"
		enableCFAuth = true
		enableDiegoAuth = true
		hostKey = hostKeyPem
		skipCertVerify = true
		processGuid = "app-guid-app-version"

		u, err := url.Parse(fakeUAA.URL())
		Expect(err).NotTo(HaveOccurred())

		u.Path = "/oauth/token"
		uaaTokenURL = u.String()
		uaaPassword = "******"
		uaaUsername = "******"
var _ = Describe("HTTPProxyConfReader", func() {
	var (
		proxyConfReader *droplet_runner.HTTPProxyConfReader
		fakeServer      *ghttp.Server
		badURL          string
	)

	BeforeEach(func() {
		fakeServer = ghttp.NewServer()

		badServer := ghttp.NewServer()
		badURL = badServer.URL()
		badServer.Close()

		proxyConfReader = &droplet_runner.HTTPProxyConfReader{
			URL: fakeServer.URL() + "/pc.json",
		}
	})

	AfterEach(func() {
		if fakeServer != nil {
			fakeServer.Close()
		}
	})

	Context("#ProxyConf", func() {
		It("should parse JSON on 200", func() {
			fakeServer.RouteToHandler("GET", "/pc.json", ghttp.CombineHandlers(
				ghttp.RespondWith(200,
					`{"http_proxy": "http://proxy", "https_proxy": "https://proxy", "no_proxy": "no-proxy"}`,
					http.Header{"Content-Type": []string{"application/json"}},
示例#12
0
var _ = Describe("PivnetClient - product", func() {
	var (
		server     *ghttp.Server
		client     pivnet.Client
		token      string
		apiAddress string
		userAgent  string

		newClientConfig pivnet.NewClientConfig
		fakeLogger      logger.Logger
	)

	BeforeEach(func() {
		server = ghttp.NewServer()
		apiAddress = server.URL() + apiPrefix
		token = "my-auth-token"
		userAgent = "pivnet-resource/0.1.0 (some-url)"

		fakeLogger = &logger_fakes.FakeLogger{}
		newClientConfig = pivnet.NewClientConfig{
			URL:       apiAddress,
			Token:     token,
			UserAgent: userAgent,
		}
		client = pivnet.NewClient(newClientConfig, fakeLogger)
	})

	AfterEach(func() {
		server.Close()
	})
示例#13
0
	"github.com/cloudfoundry-incubator/bbs/models"
	"github.com/cloudfoundry-incubator/ltc/blob_store/blob"
	"github.com/cloudfoundry-incubator/ltc/blob_store/dav_blob_store"
	config_package "github.com/cloudfoundry-incubator/ltc/config"
)

var _ = Describe("BlobStore", func() {
	var (
		blobStore      *dav_blob_store.BlobStore
		fakeServer     *ghttp.Server
		blobTargetInfo config_package.BlobStoreConfig
	)

	BeforeEach(func() {
		fakeServer = ghttp.NewServer()
		fakeServerURL, err := url.Parse(fakeServer.URL())
		Expect(err).NotTo(HaveOccurred())

		serverHost, serverPort, err := net.SplitHostPort(fakeServerURL.Host)
		Expect(err).NotTo(HaveOccurred())

		blobTargetInfo = config_package.BlobStoreConfig{
			Host:     serverHost,
			Port:     serverPort,
			Username: "******",
			Password: "******",
		}

		blobStore = dav_blob_store.New(blobTargetInfo)
	})
示例#14
0
		expectedPlan = atc.Plan{
			OnSuccess: &atc.OnSuccessPlan{
				Step: atc.Plan{
					Aggregate: &atc.AggregatePlan{
						atc.Plan{
							Location: &atc.Location{
								ParallelGroup: 1,
								ParentID:      0,
								ID:            2,
							},
							Get: &atc.GetPlan{
								Name: filepath.Base(buildDir),
								Type: "archive",
								Source: atc.Source{
									"uri": atcServer.URL() + "/api/v1/pipes/some-pipe-id",
								},
							},
						},
					},
				},
				Next: atc.Plan{
					Ensure: &atc.EnsurePlan{
						Step: atc.Plan{
							Location: &atc.Location{
								ParallelGroup: 0,
								ParentID:      0,
								ID:            3,
							},
							Task: &atc.TaskPlan{
								Name: "one-off",
示例#15
0
				request, apiErr = ccGateway.NewRequestForFile("PUT", "https://example.com/v2/apps", "BEARER my-access-token", f)
				Expect(apiErr).NotTo(HaveOccurred())
			})

			It("Uses a ProgressReader as the SeekableBody", func() {
				Expect(reflect.TypeOf(request.SeekableBody).String()).To(ContainSubstring("ProgressReader"))
			})

		})

	})

	Describe("PerformRequestForJSONResponse()", func() {
		BeforeEach(func() {
			ccServer = ghttp.NewServer()
			config.SetAPIEndpoint(ccServer.URL())
		})

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

		Context("When CC response with an api error", func() {
			BeforeEach(func() {
				ccServer.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("GET", "/v2/some-endpoint"),
						ghttp.VerifyHeader(http.Header{
							"accept": []string{"application/json"},
						}),
						ghttp.RespondWith(http.StatusUnauthorized, `{
示例#16
0
	"time"

	"github.com/onsi/gomega/ghttp"
)

var _ = Describe("backend", func() {
	var server *ghttp.Server
	var dotNetBackend garden.Backend
	var serverUri *url.URL
	var logger *lagertest.TestLogger
	var client *dotnet.Client

	BeforeEach(func() {
		server = ghttp.NewServer()
		logger = lagertest.NewTestLogger("backend")
		serverUri, _ = url.Parse(server.URL())
		client = dotnet.NewClient(logger, serverUri)
		dotNetBackend, _ = backend.NewDotNetBackend(client, logger)
	})

	AfterEach(func() {
		//shut down the server between tests
		if server.HTTPTestServer != nil {
			server.Close()
		}
	})

	Describe("Capacity", func() {
		BeforeEach(func() {
			server.AppendHandlers(
				ghttp.CombineHandlers(
示例#17
0
			})
		})
	})

	Describe("Authorize", func() {
		var (
			uaaServer *ghttp.Server
			gateway   net.Gateway
			config    core_config.ReadWriter
			authRepo  AuthenticationRepository
		)

		BeforeEach(func() {
			uaaServer = ghttp.NewServer()
			config = testconfig.NewRepository()
			config.SetAuthenticationEndpoint(uaaServer.URL())
			config.SetSSHOAuthClient("ssh-oauth-client")

			gateway = net.NewUAAGateway(config, &testterm.FakeUI{})
			authRepo = NewUAAAuthenticationRepository(gateway, config)

			uaaServer.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyHeader(http.Header{"authorization": []string{"auth-token"}}),
					ghttp.VerifyRequest("GET", "/oauth/authorize",
						"response_type=code&grant_type=authorization_code&client_id=ssh-oauth-client",
					),
					ghttp.RespondWith(http.StatusFound, ``, http.Header{
						"Location": []string{"https://www.cloudfoundry.example.com?code=F45jH"},
					}),
				),
func TestApi(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Concourse Client Suite")
}

var (
	atcServer *ghttp.Server
	client    concourse.Client
	team      concourse.Team
)

var _ = BeforeEach(func() {
	atcServer = ghttp.NewServer()

	client = concourse.NewClient(
		atcServer.URL(),
		&http.Client{},
	)

	team = client.Team("some-team")
})

var _ = AfterEach(func() {
	atcServer.Close()
})

func Change(fn func() int) *changeMatcher {
	return &changeMatcher{
		fn: fn,
	}
}
		JustBeforeEach(func() {
			var err error

			response, err = client.Do(request)
			Expect(err).NotTo(HaveOccurred())
		})

		Context("to a known provider", func() {
			BeforeEach(func() {
				request.URL.Path = "/auth/b"
				request.URL.RawQuery = url.Values{
					"redirect": {"/some-path"},
				}.Encode()

				fakeProviderB.AuthCodeURLReturns(redirectTarget.URL())
			})

			It("redirects to the auth code URL", func() {
				Expect(response.StatusCode).To(Equal(http.StatusOK))
				Expect(ioutil.ReadAll(response.Body)).To(Equal([]byte("sup")))
			})

			It("generates the auth code with a base64-encoded redirect URI as the state", func() {
				Expect(fakeProviderB.AuthCodeURLCallCount()).To(Equal(1))

				state, _ := fakeProviderB.AuthCodeURLArgsForCall(0)

				decoded, err := base64.RawURLEncoding.DecodeString(state)
				Expect(err).ToNot(HaveOccurred())
		session   *gexec.Session
		server    *ghttp.Server

		containerID string

		containerNSPath string

		ipamResult types.Result
	)

	BeforeEach(func() {
		containerID = "guid-1"
		containerNSPath = "/some/container/namespace/path"

		server = ghttp.NewServer()
		serverURL := server.URL()

		network := Network{
			ID: "some-network-id",
		}

		netConfig = Config{
			Name:          "test-network",
			Type:          "vxlan",
			Network:       network,
			DaemonBaseURL: serverURL,
		}

		ipamResult = types.Result{
			IP4: &types.IPConfig{
				IP: net.IPNet{
	"github.com/rackhd/rackhd-cpi/bosh"
	"github.com/rackhd/rackhd-cpi/config"
	"github.com/rackhd/rackhd-cpi/cpi"
	"github.com/rackhd/rackhd-cpi/helpers"
)

var _ = Describe("Setting VM Metadata", func() {
	Context("When called with metadata", func() {
		var server *ghttp.Server
		var jsonReader *strings.Reader
		var cpiConfig config.Cpi
		var request bosh.CpiRequest

		BeforeEach(func() {
			server = ghttp.NewServer()
			serverURL, err := url.Parse(server.URL())
			Expect(err).ToNot(HaveOccurred())
			jsonReader = strings.NewReader(fmt.Sprintf(`{"apiserver":"%s", "agent":{"blobstore": {"provider":"local","some": "options"}, "mbus":"localhost"}, "max_create_vm_attempts":1}`, serverURL.Host))
			request = bosh.CpiRequest{Method: bosh.SET_VM_METADATA}
			cpiConfig, err = config.New(jsonReader, request)
			Expect(err).ToNot(HaveOccurred())
		})

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

		It("Sends a request to set metadata to the RackHD API", func() {

			id := "55e79ea54e66816f6152fff9"
			cid := "vm-5678"
	var graph *fake_graph.FakeGraph
	var fetcher RepositoryFetcher

	var server *ghttp.Server
	var endpoint1 *ghttp.Server
	var endpoint2 *ghttp.Server

	BeforeEach(func() {
		graph = fake_graph.New()

		server = ghttp.NewServer()

		endpoint1 = ghttp.NewServer()
		endpoint2 = ghttp.NewServer()

		registry, err := registry.NewRegistry(nil, nil, server.URL()+"/v1/")
		Ω(err).ShouldNot(HaveOccurred())

		fetcher = New(registry, graph)
	})

	setupSuccessfulFetch := func(endpoint *ghttp.Server) {
		endpoint.AppendHandlers(
			ghttp.CombineHandlers(
				ghttp.VerifyRequest("GET", "/v1/images/layer-3/json"),
				http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
					w.Header().Add("X-Docker-Size", "123")
					w.Write([]byte(`{"id":"layer-3","parent":"parent-3"}`))
				}),
			),
			ghttp.CombineHandlers(
示例#23
0
		server        *ghttp.Server
		c             *client.JSONClient
		serverHandler http.HandlerFunc

		route string

		responseStruct struct {
			SomeResponseField string `json:"SomeResponseField"`
		}
	)

	BeforeEach(func() {
		server = ghttp.NewServer()

		c = &client.JSONClient{
			BaseURL: server.URL(),
		}

		route = "/some/route"
	})
	AfterEach(func() {
		server.Close()
	})

	Describe("Get", func() {
		BeforeEach(func() {
			serverHandler = ghttp.CombineHandlers(
				ghttp.VerifyRequest("GET", route),
				ghttp.RespondWith(http.StatusOK, `{ "SomeResponseField": "some value" }`),
			)
			server.AppendHandlers(serverHandler)
	var (
		fakeFileSwapper           *fake_file_swapper.FakeFileSwapper
		fakeServer                *ghttp.Server
		config                    *config_package.Config
		versionManager            version.VersionManager
		fakeReceptorClientCreator *fake_receptor_client_creator.FakeCreator
		fakeReceptorClient        *fake_receptor.FakeClient

		ltcTempFile *os.File
	)

	BeforeEach(func() {
		fakeFileSwapper = &fake_file_swapper.FakeFileSwapper{}

		fakeServer = ghttp.NewServer()
		fakeServerURL, err := url.Parse(fakeServer.URL())
		Expect(err).NotTo(HaveOccurred())

		fakeServerHost, fakeServerPort, err := net.SplitHostPort(fakeServerURL.Host)
		Expect(err).NotTo(HaveOccurred())

		ltcTempFile, err = ioutil.TempFile("", "fake-ltc")
		Expect(err).NotTo(HaveOccurred())

		fakeReceptorClient = &fake_receptor.FakeClient{}
		fakeReceptorClientCreator = &fake_receptor_client_creator.FakeCreator{}
		fakeReceptorClientCreator.CreateReceptorClientReturns(fakeReceptorClient)

		config = config_package.New(nil)
		config.SetTarget(fakeServerHost + ".xip.io:" + fakeServerPort)
		versionManager = version.NewVersionManager(fakeReceptorClientCreator, fakeFileSwapper, "")
示例#25
0
	. "github.com/onsi/gomega"
)

var _ = Describe("Service Keys Repo", func() {
	var (
		ccServer   *ghttp.Server
		configRepo core_config.ReadWriter
		repo       ServiceKeyRepository
	)

	BeforeEach(func() {
		configRepo = testconfig.NewRepositoryWithDefaults()
		configRepo.SetAccessToken("BEARER my_access_token")

		ccServer = ghttp.NewServer()
		configRepo.SetApiEndpoint(ccServer.URL())

		gateway := net.NewCloudControllerGateway(configRepo, time.Now, &testterm.FakeUI{})
		repo = NewCloudControllerServiceKeyRepository(configRepo, gateway)
	})

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

	Describe("CreateServiceKey", func() {
		It("tries to create the service key", func() {
			ccServer.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/v2/service_keys"),
					ghttp.RespondWith(http.StatusCreated, nil),
示例#26
0
	"gopkg.in/inconshreveable/log15.v2"
)

var _ = Describe("Testing xhost requests", func() {

	var server *ghttp.Server
	var wstuncli *WSTunnelClient
	var wstunsrv *WSTunnelServer
	var wstunUrl string
	var wstunToken string
	var cliStart func(server, regexp string) *WSTunnelClient

	BeforeEach(func() {
		wstunToken = "test567890123456-" + strconv.Itoa(rand.Int()%1000000)
		server = ghttp.NewServer()
		log15.Info("ghttp started", "url", server.URL())

		l, _ := net.Listen("tcp", "127.0.0.1:0")
		wstunsrv = NewWSTunnelServer([]string{})
		wstunsrv.Start(l)
		wstunUrl = "http://" + l.Addr().String()
		cliStart = func(server, regexp string) *WSTunnelClient {
			wstuncli = NewWSTunnelClient([]string{
				"-token", wstunToken, "-tunnel", "ws://" + l.Addr().String(),
				"-server", server, "-regexp", regexp,
			})
			wstuncli.Start()
			// wait for client to connect so we don't get a "tunnel never seen" response
			for !wstuncli.Connected {
				time.Sleep(10 * time.Millisecond)
			}
示例#27
0
				Expect(err).NotTo(HaveOccurred())

				Eventually(session.Out).Should(Say("Setting api endpoint to %s...", getAPI()))
				Eventually(session.Out).Should(Say("OK"))
				Eventually(session.Out).Should(Say("API endpoint:\\s+https://%s", getAPI()))
				Eventually(session.Out).Should(Say("API version: \\d+\\.\\d+\\.\\d+"))
				Eventually(session).Should(Exit(0))
			})
		})

		Context("api does not have SSL", func() {
			var server *ghttp.Server

			BeforeEach(func() {
				server = ghttp.NewServer()
				serverAPIURL := server.URL()[7:]

				response := `{
					"name":"",
					"build":"",
					"support":"http://support.cloudfoundry.com",
					"version":0,
					"description":"",
					"authorization_endpoint":"https://login.APISERVER",
					"token_endpoint":"https://uaa.APISERVER",
					"min_cli_version":null,
					"min_recommended_cli_version":null,
					"api_version":"2.59.0",
					"app_ssh_endpoint":"ssh.APISERVER",
					"app_ssh_host_key_fingerprint":"a6:d1:08:0b:b0:cb:9b:5f:c4:ba:44:2a:97:26:19:8a",
					"app_ssh_oauth_client":"ssh-proxy",
示例#28
0
			reqCount    chan struct{}
			task        *models.Task

			httpClient *http.Client
		)

		BeforeEach(func() {
			httpClient = cf_http.NewClient()
			statusCodes = make(chan int)
			reqCount = make(chan struct{})

			fakeServer.RouteToHandler("POST", "/the-callback/url", func(w http.ResponseWriter, req *http.Request) {
				w.WriteHeader(<-statusCodes)
			})

			callbackURL = fakeServer.URL() + "/the-callback/url"
			taskDB = new(dbfakes.FakeTaskDB)
			taskDB.ResolvingTaskReturns(nil)
			taskDB.DeleteTaskReturns(nil)
		})

		simulateTaskCompleting := func(signals <-chan os.Signal, ready chan<- struct{}) error {
			close(ready)
			task = model_helpers.NewValidTask("the-task-guid")
			task.CompletionCallbackUrl = callbackURL
			taskworkpool.HandleCompletedTask(logger, httpClient, taskDB, task)
			return nil
		}

		var process ifrit.Process
		JustBeforeEach(func() {
示例#29
0
	"github.com/onsi/gomega/ghttp"
)

var _ = Describe("Fly CLI", func() {
	var (
		atcServer *ghttp.Server
	)

	Describe("containers", func() {
		var (
			flyCmd *exec.Cmd
		)

		BeforeEach(func() {
			atcServer = ghttp.NewServer()
			flyCmd = exec.Command(flyPath, "-t", atcServer.URL(), "containers")
		})

		Context("when containers are returned from the API", func() {
			BeforeEach(func() {
				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",
示例#30
0
文件: main_test.go 项目: lopaka/rsc
	}

	// Override default writter to capture scripts content
	writeFile = func(outputFile string, bytes []byte, perm os.FileMode) {
		written = bytes
	}

	BeforeEach(func() {
		server = ghttp.NewServer()
		var err error
		tmpFile, err = ioutil.TempFile("", "rsc_rsssh_test")
		tmpFile.WriteString(config)
		tmpFile.Close()
		Ω(err).ShouldNot(HaveOccurred())
		os.Args = []string{"rsssh", "-insecure", "-c=" + tmpFile.Name(),
			"-e=dummy", "-p=dummy", "-h=" + server.URL()[7:]}
	})

	AfterEach(func() {
		server.Close()
		Ω(os.Remove(tmpFile.Name())).Should(Succeed())
	})

	It("creates SSH scripts", func() {
		server.AppendHandlers(
			ghttp.CombineHandlers(
				ghttp.VerifyRequest("POST", "/api/sessions"),
				ghttp.RespondWith(204, ""),
			),
			ghttp.CombineHandlers(
				ghttp.VerifyRequest("GET", "/api/sessions"),