예제 #1
0
func (c *client) ListRoutes(parentRef string) ([]*router.Route, error) {
	path := "/routes"
	if parentRef != "" {
		q := make(url.Values)
		q.Set("parent_ref", parentRef)
		path += "?" + q.Encode()
	}
	var res []*router.Route
	err := c.Get(path, &res)
	return res, err
}
예제 #2
0
func runEtcdServer(t *testing.T) func() {
	killCh := make(chan struct{})
	doneCh := make(chan struct{})
	name := "etcd-test." + strconv.Itoa(rand.Int())
	dataDir, err := ioutil.TempDir("", "")
	if err != nil {
		t.Fatal("tempdir failed:", err)
	}
	go func() {
		cmd := exec.Command("etcd", "-name", name, "-data-dir", dataDir)
		stdout, _ := cmd.StdoutPipe()
		stderr, _ := cmd.StderrPipe()
		if err := cmd.Start(); err != nil {
			t.Fatal("etcd start failed:", err)
			return
		}
		cmdDone := make(chan error)
		go func() {
			if os.Getenv("DEBUG") != "" {
				logOutput("etcd", stdout, stderr)
			}
			cmdDone <- cmd.Wait()
		}()
		select {
		case <-killCh:
			if err := cmd.Process.Kill(); err != nil {
				t.Fatal("failed to kill etcd:", err)
				return
			}
			<-cmdDone
		case err := <-cmdDone:
			t.Fatal("etcd failed:", err)
			return
		}
		if err := os.RemoveAll(dataDir); err != nil {
			t.Fatal("etcd cleanup failed:", err)
			return
		}
		doneCh <- struct{}{}
	}()

	// wait for etcd to come up
	client := etcd.NewClient(nil)
	err = Attempts.Run(func() (err error) {
		_, err = client.Get("/", false, false)
		return
	})
	if err != nil {
		t.Fatalf("Failed to connect to etcd: %q", err)
	}

	return func() {
		close(killCh)
		<-doneCh
	}
}
예제 #3
0
func captureSchedulerState(gist *Gist) error {
	leader, err := discoverd.NewService("controller-scheduler").Leader()
	if err != nil {
		return err
	}
	client := &http.Client{Timeout: 10 * time.Second}
	res, err := client.Get(fmt.Sprintf("http://%s/debug/state", leader.Addr))
	if err != nil {
		return err
	}
	defer res.Body.Close()
	if res.StatusCode != http.StatusOK {
		return fmt.Errorf("unexpected HTTP status: %s", res.Status)
	}
	body, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return err
	}
	gist.AddFile("scheduler-state.json", string(body))
	return nil
}
예제 #4
0
파일: client.go 프로젝트: justintung/flynn
func NewClient(endpoint string) (*Client, error) {
	authKey := os.Getenv("TEST_RUNNER_AUTH_KEY")
	if authKey == "" {
		return nil, errors.New("missing TEST_RUNNER_AUTH_KEY environment variable")
	}

	httpClient := &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{ServerName: "ci.flynn.io"}}}
	client := &Client{
		Client: &httpclient.Client{
			ErrNotFound: ErrNotFound,
			URL:         endpoint,
			Key:         authKey,
			HTTP:        httpClient,
		},
	}
	var cluster tc.Cluster
	if err := client.Get("", &cluster); err != nil {
		return nil, err
	}
	client.cluster = &cluster
	client.size = cluster.Size()
	return client, nil
}
예제 #5
0
func (c *client) GetRoute(id string) (*router.Route, error) {
	res := &router.Route{}
	err := c.Get("/routes/"+id, res)
	return res, err
}