示例#1
0
文件: hijack.go 项目: mmb/fly
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
0
文件: hijack.go 项目: simonjjones/fly
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
0
文件: config_test.go 项目: ACPK/atc
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
	"github.com/tedsuo/rata"
	"gopkg.in/yaml.v2"
)

type RemoraConfig struct {
	atc.Config

	Extra string `json:"extra"`
}

var _ = Describe("Config API", func() {
	var (
		config           atc.Config
		requestGenerator *rata.RequestGenerator
	)

	BeforeEach(func() {
		requestGenerator = rata.NewRequestGenerator(server.URL, atc.Routes)

		config = atc.Config{
			Groups: atc.GroupConfigs{
				{
					Name:      "some-group",
					Jobs:      []string{"job-1", "job-2"},
					Resources: []string{"resource-1", "resource-2"},
				},
			},

			Resources: atc.ResourceConfigs{
示例#4
0
	"io/ioutil"
	"net/http"

	"github.com/cloudfoundry/hm9000/apiserver"
	"github.com/cloudfoundry/hm9000/testhelpers/appfixture"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/tedsuo/rata"
)

var _ = Describe("Serving API", func() {
	var (
		a                appfixture.AppFixture
		validRequest     string
		requestGenerator *rata.RequestGenerator
		httpClient       *http.Client
		apiServerAddr    string
		username         string
		password         string
	)

	Describe("POST /bulk_app_state", func() {
		var b appfixture.AppFixture

		BeforeEach(func() {
			apiServerAddr = fmt.Sprintf("http://%s:%d", cliRunner.config.APIServerAddress, cliRunner.config.APIServerPort)
			requestGenerator = rata.NewRequestGenerator(apiServerAddr, apiserver.Routes)
			httpClient = &http.Client{
				Transport: &http.Transport{},
			}
示例#5
0
	. "github.com/onsi/gomega"
	"github.com/tedsuo/ifrit"
	"github.com/tedsuo/ifrit/ginkgomon"
	"github.com/tedsuo/ifrit/http_server"
	"github.com/tedsuo/ifrit/sigmon"
	"github.com/tedsuo/rata"

	"github.com/cloudfoundry-incubator/bbs/models"
	"github.com/cloudfoundry-incubator/runtime-schema/cc_messages"
	"github.com/cloudfoundry-incubator/tps"
)

var _ = Describe("TPS-Listener", func() {
	var (
		httpClient       *http.Client
		requestGenerator *rata.RequestGenerator

		desiredLRP, desiredLRP2 *models.DesiredLRP
	)

	BeforeEach(func() {
		requestGenerator = rata.NewRequestGenerator(fmt.Sprintf("http://%s", listenerAddr), tps.Routes)
		httpClient = &http.Client{
			Transport: &http.Transport{},
		}
	})

	JustBeforeEach(func() {
		listener = ginkgomon.Invoke(runner)

		desiredLRP = &models.DesiredLRP{
			Domain:      "some-domain",
示例#6
0
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)
		}

		buildsResp, err := client.Do(buildsReq)
		if err != nil {
			log.Fatalln("failed to get builds:", err)
		}

		if buildsResp.StatusCode != http.StatusOK {
			log.Println("bad response when getting builds:")
			buildsResp.Body.Close()
			buildsResp.Write(os.Stderr)
			os.Exit(1)
		}

		var builds []atc.Build
		err = json.NewDecoder(buildsResp.Body).Decode(&builds)
		if err != nil {
			log.Fatalln("failed to decode builds:", err)
		}

		for _, build := range builds {
			if build.JobName == "" {
				return build
			}
		}

		println("no builds")
		os.Exit(1)
	}

	panic("unreachable")
}
示例#7
0
	"github.com/cloudfoundry-incubator/stager/cmd/stager/testrunner"
	"github.com/gogo/protobuf/proto"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
	"github.com/onsi/gomega/gexec"
	"github.com/onsi/gomega/ghttp"
	"github.com/tedsuo/rata"
)

var _ = Describe("Stager", func() {
	var (
		fakeBBS *ghttp.Server
		fakeCC  *ghttp.Server

		requestGenerator *rata.RequestGenerator
		httpClient       *http.Client

		callbackURL string
	)

	BeforeEach(func() {
		stagerPort := 8888 + GinkgoParallelNode()
		stagerURL := fmt.Sprintf("http://127.0.0.1:%d", stagerPort)
		callbackURL = stagerURL + "/v1/staging/my-task-guid/completed"

		fakeBBS = ghttp.NewServer()
		fakeCC = ghttp.NewServer()

		runner = testrunner.New(testrunner.Config{
			StagerBin:          stagerPath,
示例#8
0
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gbytes"
	"github.com/onsi/gomega/gexec"
	"github.com/tedsuo/ifrit"
	"github.com/tedsuo/ifrit/ginkgomon"
	"github.com/tedsuo/rata"
)

var _ = Describe("Nsync Listener", func() {
	const exitDuration = 3 * time.Second

	var (
		nsyncPort int

		requestGenerator *rata.RequestGenerator
		httpClient       *http.Client
		response         *http.Response
		err              error

		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)+`,