當前位置: 首頁>>代碼示例>>Golang>>正文


Golang empiretest.NewEmpire函數代碼示例

本文整理匯總了Golang中github.com/remind101/empire/empiretest.NewEmpire函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewEmpire函數的具體用法?Golang NewEmpire怎麽用?Golang NewEmpire使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewEmpire函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestDeployment

func TestDeployment(t *testing.T) {
	e := empiretest.NewEmpire(t)
	s := new(mockScheduler)
	s.image = make(chan string, 1)
	e.Scheduler = s

	c, sv := NewTestClient(t, e)
	defer sv.Close()

	var d events.Deployment
	d.Repository.FullName = "remind101/acme-inc"
	d.Deployment.ID = 1234
	d.Deployment.Ref = "master"
	d.Deployment.Sha = "827fecd2d36ebeaa2fd05aa8ef3eed1e56a8cd57"
	d.Deployment.Task = "deployment"
	d.Deployment.Environment = "test"
	d.Deployment.Description = "Deploying"
	d.Deployment.Creator.Login = "ejholmes"

	resp, err := c.Trigger("deployment", &d)
	assert.NoError(t, err)

	raw, err := ioutil.ReadAll(resp.Body)
	assert.NoError(t, err)
	assert.Equal(t, 202, resp.StatusCode)
	assert.Equal(t, "Ok\n", string(raw))
	assert.Equal(t, "remind101/acme-inc:827fecd2d36ebeaa2fd05aa8ef3eed1e56a8cd57", <-s.image)
}
開發者ID:carriercomm,項目名稱:empire,代碼行數:28,代碼來源:github_test.go

示例2: TestEmpire_Deploy_ImageNotFound

func TestEmpire_Deploy_ImageNotFound(t *testing.T) {
	e := empiretest.NewEmpire(t)
	s := new(mockScheduler)
	e.Scheduler = s
	e.ExtractProcfile = func(ctx context.Context, img image.Image, w io.Writer) (procfile.Procfile, error) {
		return nil, errors.New("image not found")
	}

	// Deploying an image to an app that doesn't exist will create a new
	// app.
	_, err := e.Deploy(context.Background(), empire.DeploymentsCreateOpts{
		User:   &empire.User{Name: "ejholmes"},
		Output: ioutil.Discard,
		Image:  image.Image{Repository: "remind101/acme-inc"},
	})
	assert.Error(t, err)

	// If there's an error deploying, then the transaction should be rolled
	// backed and no apps should exist.
	apps, err := e.Apps(empire.AppsQuery{})
	assert.NoError(t, err)
	assert.Equal(t, 0, len(apps))

	s.AssertExpectations(t)
}
開發者ID:frewsxcv,項目名稱:empire,代碼行數:25,代碼來源:empire_test.go

示例3: run

func run(t testing.TB, commands []Command) {
	e := empiretest.NewEmpire(t)
	s := empiretest.NewServer(t, e)
	defer s.Close()

	token, err := e.AccessTokensCreate(&empire.AccessToken{
		User: &empire.User{Name: "fake", GitHubToken: "token"},
	})
	if err != nil {
		t.Fatal(err)
	}

	for _, cmd := range commands {
		got := cli(t, token.Token, s.URL, cmd.Command)

		if want, ok := cmd.Output.(string); ok {
			if want != "" {
				want = want + "\n"
			}

			if got != want {
				t.Fatalf("%q != %q", got, want)
			}
		} else if regex, ok := cmd.Output.(*regexp.Regexp); ok {
			if !regex.MatchString(got) {
				t.Fatalf("%q != %q", got, regex.String())
			}
		}
	}
}
開發者ID:frewsxcv,項目名稱:empire,代碼行數:30,代碼來源:cli_test.go

示例4: TestEmpire_Deploy

func TestEmpire_Deploy(t *testing.T) {
	e := empiretest.NewEmpire(t)
	s := new(mockScheduler)
	e.Scheduler = s

	user := &empire.User{Name: "ejholmes"}

	app, err := e.Create(context.Background(), empire.CreateOpts{
		User: user,
		Name: "acme-inc",
	})
	assert.NoError(t, err)

	hostPort, containerPort := int64(9000), int64(8080)
	img := image.Image{Repository: "remind101/acme-inc"}
	s.On("Submit", &scheduler.App{
		ID:   app.ID,
		Name: "acme-inc",
		Processes: []*scheduler.Process{
			{
				Type:     "web",
				Image:    img,
				Command:  "./bin/web",
				Exposure: scheduler.ExposePrivate,
				Ports: []scheduler.PortMap{
					{Host: &hostPort, Container: &containerPort},
				},
				Instances:   1,
				MemoryLimit: 536870912,
				CPUShares:   256,
				SSLCert:     "",
				Env: map[string]string{
					"EMPIRE_APPID":      app.ID,
					"EMPIRE_APPNAME":    "acme-inc",
					"EMPIRE_PROCESS":    "web",
					"EMPIRE_RELEASE":    "v1",
					"SOURCE":            "acme-inc.web.v1",
					"PORT":              "8080",
					"EMPIRE_CREATED_AT": "2015-01-01T01:01:01Z",
				},
				Labels: map[string]string{
					"empire.app.name":    "acme-inc",
					"empire.app.id":      app.ID,
					"empire.app.process": "web",
					"empire.app.release": "v1",
				},
			},
		},
	}).Return(nil)

	_, err = e.Deploy(context.Background(), empire.DeploymentsCreateOpts{
		App:    app,
		User:   user,
		Output: ioutil.Discard,
		Image:  img,
	})
	assert.NoError(t, err)

	s.AssertExpectations(t)
}
開發者ID:frewsxcv,項目名稱:empire,代碼行數:60,代碼來源:empire_test.go

示例5: TestEmpire_Deploy_Concurrent

func TestEmpire_Deploy_Concurrent(t *testing.T) {
	e := empiretest.NewEmpire(t)
	s := new(mockScheduler)
	e.Scheduler = scheduler.NewFakeScheduler()
	e.ExtractProcfile = func(ctx context.Context, img image.Image, w io.Writer) (procfile.Procfile, error) {
		return nil, nil
	}

	user := &empire.User{Name: "ejholmes"}

	// Create the first release for this app.
	r, err := e.Deploy(context.Background(), empire.DeploymentsCreateOpts{
		User:   user,
		Output: ioutil.Discard,
		Image:  image.Image{Repository: "remind101/acme-inc"},
	})
	assert.NoError(t, err)
	assert.Equal(t, 1, r.Version)

	// We'll use the procfile extractor to synchronize two concurrent
	// deployments.
	v2Started, v3Started := make(chan struct{}), make(chan struct{})
	e.ExtractProcfile = func(ctx context.Context, img image.Image, w io.Writer) (procfile.Procfile, error) {
		switch img.Tag {
		case "v2":
			close(v2Started)
			<-v3Started
		case "v3":
			close(v3Started)
		}
		return nil, nil
	}

	v2Done := make(chan struct{})
	go func() {
		r, err = e.Deploy(context.Background(), empire.DeploymentsCreateOpts{
			User:   user,
			Output: ioutil.Discard,
			Image:  image.Image{Repository: "remind101/acme-inc", Tag: "v2"},
		})
		assert.NoError(t, err)
		assert.Equal(t, 2, r.Version)
		close(v2Done)
	}()

	<-v2Started

	r, err = e.Deploy(context.Background(), empire.DeploymentsCreateOpts{
		User:   user,
		Output: ioutil.Discard,
		Image:  image.Image{Repository: "remind101/acme-inc", Tag: "v3"},
	})
	assert.NoError(t, err)
	assert.Equal(t, 3, r.Version)

	<-v2Done

	s.AssertExpectations(t)
}
開發者ID:frewsxcv,項目名稱:empire,代碼行數:59,代碼來源:empire_test.go

示例6: TestPing

func TestPing(t *testing.T) {
	e := empiretest.NewEmpire(t)
	c, s := NewTestClient(t, e)
	defer s.Close()

	if _, err := c.Ping(hooker.DefaultPing); err != nil {
		t.Fatal(err)
	}
}
開發者ID:carriercomm,項目名稱:empire,代碼行數:9,代碼來源:github_test.go

示例7: NewTestClient

// NewTestClient will return a new heroku.Client that's configured to interact
// with a instance of the empire HTTP server.
func NewTestClient(t testing.TB) (*hooker.Client, *httptest.Server) {
	e := empiretest.NewEmpire(t)
	s := empiretest.NewServer(t, e)

	c := hooker.NewClient(nil)
	c.URL = s.URL
	c.Secret = "abcd"

	return c, s
}
開發者ID:frewsxcv,項目名稱:empire,代碼行數:12,代碼來源:github_test.go

示例8: NewTestClient

// NewTestClient will return a new heroku.Client that's configured to interact
// with a instance of the empire HTTP server.
func NewTestClient(t testing.TB) (*heroku.Client, *httptest.Server) {
	e := empiretest.NewEmpire(t)
	s := empiretest.NewServer(t, e)

	c := &heroku.Client{
		Username: "",
		Password: "",
	}
	c.URL = s.URL

	return c, s
}
開發者ID:frewsxcv,項目名稱:empire,代碼行數:14,代碼來源:api_test.go

示例9: newClient

// newClient will return a new heroku.Client that's configured to interact
// with a instance of the empire HTTP server.
func newClient(t testing.TB) *client {
	e := empiretest.NewEmpire(t)
	s := empiretest.NewServer(t, e)

	c := hooker.NewClient(nil)
	c.URL = s.URL
	c.Secret = "abcd"

	return &client{
		Server: s,
		Client: c,
	}
}
開發者ID:brianz,項目名稱:empire,代碼行數:15,代碼來源:github_test.go

示例10: NewTestClient

// NewTestClient will return a new heroku.Client that's configured to interact
// with a instance of the empire HTTP server.
func NewTestClient(t testing.TB) (*heroku.Client, *empiretest.Server) {
	e := empiretest.NewEmpire(t)
	s := empiretest.NewTestServer(t, e, server.Options{
		Authenticator: auth.Anyone(&empire.User{Name: "fake"}),
	})

	c := &heroku.Client{
		Username: "",
		Password: "",
	}
	c.URL = s.URL

	return c, s
}
開發者ID:brianz,項目名稱:empire,代碼行數:16,代碼來源:api_test.go

示例11: NewTestClient

// NewTestClient will return a new heroku.Client that's configured to interact
// with a instance of the empire HTTP server.
func NewTestClient(t testing.TB) (*heroku.Client, *httptest.Server) {
	e := empiretest.NewEmpire(t)
	s := empiretest.NewServer(t, e)

	token, err := e.AccessTokensCreate(&empire.AccessToken{
		User: &empire.User{Name: "fake", GitHubToken: "token"},
	})
	if err != nil {
		t.Fatal(err)
	}

	c := &heroku.Client{
		Username: "",
		Password: token.Token,
	}
	c.URL = s.URL

	return c, s
}
開發者ID:aaithal,項目名稱:empire,代碼行數:21,代碼來源:api_test.go

示例12: TestLogin

func TestLogin(t *testing.T) {
	e := empiretest.NewEmpire(t)
	s := empiretest.NewServer(t, e)
	defer s.Close()

	input := "fake\nbar\n"

	cmd := NewCmd(s.URL, "login")
	cmd.Stdin = strings.NewReader(input)

	out, err := cmd.CombinedOutput()
	if err != nil {
		t.Fatal(err)
	}

	if got, want := string(out), "Enter email: Logged in.\n"; got != want {
		t.Fatalf("%q", got)
	}
}
開發者ID:aaithal,項目名稱:empire,代碼行數:19,代碼來源:login_test.go

示例13: TestLoginUnauthorized

func TestLoginUnauthorized(t *testing.T) {
	e := empiretest.NewEmpire(t)
	s := empiretest.NewServer(t, e)
	defer s.Close()

	input := "foo\nbar\n"

	cmd := NewCmd(s.URL, "login")
	cmd.Stdin = strings.NewReader(input)

	out, err := cmd.CombinedOutput()
	if err == nil {
		t.Fatal("Expected an error")
	}

	if got, want := string(out), "Enter email: error: Request not authenticated, API token is missing, invalid or expired Log in with `emp login`.\n"; got != want {
		t.Fatalf("%q", got)
	}
}
開發者ID:aaithal,項目名稱:empire,代碼行數:19,代碼來源:login_test.go

示例14: TestLoginTwoFactor

func TestLoginTwoFactor(t *testing.T) {
	e := empiretest.NewEmpire(t)
	s := httptest.NewServer(server.New(e, server.Options{
		Authenticator: auth.StaticAuthenticator("twofactor", "bar", "code", &empire.User{Name: "fake"}),
	}))
	defer s.Close()

	input := "twofactor\nbar\ncode\n"

	cmd := NewCmd(s.URL, "login")
	cmd.Stdin = strings.NewReader(input)

	out, err := cmd.CombinedOutput()
	if err != nil {
		t.Fatal(err)
	}

	if got, want := string(out), "Enter email: Enter two-factor auth code: Logged in.\n"; got != want {
		t.Fatalf("%q", got)
	}
}
開發者ID:frewsxcv,項目名稱:empire,代碼行數:21,代碼來源:login_test.go

示例15: NewTestClient

// NewTestClient will return a new heroku.Client that's configured to interact
// with a instance of the empire HTTP server.
func NewTestClient(t testing.TB) (*heroku.Client, *empiretest.Server) {
	e := empiretest.NewEmpire(t)
	s := empiretest.NewServer(t, e)
	s.Heroku.Auth = &auth.Auth{
		Strategies: auth.Strategies{
			{
				Name:          auth.StrategyUsernamePassword,
				Authenticator: auth.Anyone(&empire.User{Name: "fake"}),
			},
		},
	}
	s.Start()

	c := &heroku.Client{
		Username: "",
		Password: "",
	}
	c.URL = s.URL()

	return c, s
}
開發者ID:iserko,項目名稱:empire,代碼行數:23,代碼來源:api_test.go


注:本文中的github.com/remind101/empire/empiretest.NewEmpire函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。