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


Golang cmd.NewManager函數代碼示例

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


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

示例1: TestRebalanceContainersRunAskingForConfirmation

func (s *S) TestRebalanceContainersRunAskingForConfirmation(c *check.C) {
	var stdout, stderr bytes.Buffer
	context := cmd.Context{
		Stdout: &stdout,
		Stderr: &stderr,
		Stdin:  bytes.NewBufferString("y"),
	}
	msg, _ := json.Marshal(tsuruIo.SimpleJsonMessage{Message: "progress msg"})
	result := string(msg)
	trans := &cmdtest.ConditionalTransport{
		Transport: cmdtest.Transport{Message: result, Status: http.StatusOK},
		CondFunc: func(req *http.Request) bool {
			defer req.Body.Close()
			body, err := ioutil.ReadAll(req.Body)
			c.Assert(err, check.IsNil)
			expected := map[string]string{
				"dry": "false",
			}
			result := map[string]string{}
			err = json.Unmarshal(body, &result)
			c.Assert(expected, check.DeepEquals, result)
			return req.URL.Path == "/docker/containers/rebalance" && req.Method == "POST"
		},
	}
	manager := cmd.NewManager("admin", "0.1", "admin-ver", &stdout, &stderr, nil, nil)
	client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager)
	cmd := rebalanceContainersCmd{}
	err := cmd.Run(&context, client)
	c.Assert(err, check.IsNil)
	c.Assert(stdout.String(), check.Equals, "Are you sure you want to rebalance containers? (y/n) progress msg")
	cmd2 := rebalanceContainersCmd{}
	err = cmd2.Run(&context, client)
	c.Assert(err, check.IsNil)
}
開發者ID:maxwhale,項目名稱:tsuru,代碼行數:34,代碼來源:admin_test.go

示例2: TestBsEnvSetRunForPool

func (s *S) TestBsEnvSetRunForPool(c *check.C) {
	var stdout, stderr bytes.Buffer
	context := cmd.Context{
		Stdout: &stdout,
		Stderr: &stderr,
		Args:   []string{"A=1", "B=2"},
	}
	trans := &cmdtest.ConditionalTransport{
		Transport: cmdtest.Transport{Message: "", Status: http.StatusNoContent},
		CondFunc: func(req *http.Request) bool {
			defer req.Body.Close()
			body, err := ioutil.ReadAll(req.Body)
			c.Assert(err, check.IsNil)
			expected := Config{
				Pools: []PoolEnvs{{
					Name: "pool1",
					Envs: []Env{{Name: "A", Value: "1"}, {Name: "B", Value: "2"}},
				}},
			}
			var conf Config
			err = json.Unmarshal(body, &conf)
			c.Assert(conf, check.DeepEquals, expected)
			return req.URL.Path == "/docker/bs/env" && req.Method == "POST"
		},
	}
	manager := cmd.NewManager("admin", "0.1", "admin-ver", &stdout, &stderr, nil, nil)
	client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager)
	cmd := EnvSetCmd{}
	err := cmd.Flags().Parse(true, []string{"--pool", "pool1"})
	c.Assert(err, check.IsNil)
	err = cmd.Run(&context, client)
	c.Assert(err, check.IsNil)
	c.Assert(stdout.String(), check.Equals, "Variables successfully set.\n")
}
開發者ID:nicolas2bonfils,項目名稱:tsuru,代碼行數:34,代碼來源:cmd_test.go

示例3: TestTokenGenWithExportOn

func (s *S) TestTokenGenWithExportOn(c *gocheck.C) {
	var stdout, stderr bytes.Buffer
	context := cmd.Context{
		Args:   []string{"myapp"},
		Stdout: &stdout,
		Stderr: &stderr,
	}
	manager := cmd.NewManager("glb", "0.2", "ad-ver", &stdout, &stderr, nil, nil)
	result := `{"token":"secret123"}`
	trans := testing.ConditionalTransport{
		Transport: testing.Transport{Message: result, Status: http.StatusOK},
		CondFunc: func(req *http.Request) bool {
			defer req.Body.Close()
			body, err := ioutil.ReadAll(req.Body)
			c.Assert(err, gocheck.IsNil)
			c.Assert(string(body), gocheck.Equals, `{"client":"myapp","export":true}`)
			return req.Method == "POST" && req.URL.Path == "/tokens"
		},
	}
	expected := `Application token: "secret123".` + "\n"
	client := cmd.NewClient(&http.Client{Transport: &trans}, nil, manager)
	command := tokenGen{}
	command.Flags().Parse(true, []string{"-e"})
	err := command.Run(&context, client)
	c.Assert(err, gocheck.IsNil)
	c.Assert(stdout.String(), gocheck.Equals, expected)
}
開發者ID:ningjh,項目名稱:tsuru,代碼行數:27,代碼來源:auth_test.go

示例4: TestListUsersRun

func (s *S) TestListUsersRun(c *check.C) {
	var stdout, stderr bytes.Buffer
	context := cmd.Context{
		Stdout: &stdout,
		Stderr: &stderr,
	}
	manager := cmd.NewManager("glb", "0.2", "ad-ver", &stdout, &stderr, nil, nil)
	result := `[{"email": "[email protected]","teams":["team1", "team2", "team3"]}]`
	trans := cmdtest.ConditionalTransport{
		Transport: cmdtest.Transport{Message: result, Status: http.StatusOK},
		CondFunc: func(req *http.Request) bool {
			return req.Method == "GET" && req.URL.Path == "/users"
		},
	}
	expected := `+---------------+---------------------+
| User          | Teams               |
+---------------+---------------------+
| [email protected] | team1, team2, team3 |
+---------------+---------------------+
`
	client := cmd.NewClient(&http.Client{Transport: &trans}, nil, manager)
	command := listUsers{}
	err := command.Run(&context, client)
	c.Assert(err, check.IsNil)
	c.Assert(stdout.String(), check.Equals, expected)
}
開發者ID:combor,項目名稱:tsuru-admin,代碼行數:26,代碼來源:auth_test.go

示例5: TestListUsersRunWithoutFlags

func (s *S) TestListUsersRunWithoutFlags(c *check.C) {
	var stdout, stderr bytes.Buffer
	context := cmd.Context{
		Stdout: &stdout,
		Stderr: &stderr,
	}
	manager := cmd.NewManager("glb", "0.2", "ad-ver", &stdout, &stderr, nil, nil)
	result := `[{"email": "[email protected]",
"roles":[
	{"name": "role1", "contexttype": "team", "contextvalue": "a"},
	{"name": "role2", "contexttype": "app", "contextvalue": "x"}
]
}]`
	trans := cmdtest.ConditionalTransport{
		Transport: cmdtest.Transport{Message: result, Status: http.StatusOK},
		CondFunc: func(req *http.Request) bool {
			return req.Method == "GET" && req.URL.Path == "/users"
		},
	}
	expected := `+---------------+---------------+
| User          | Roles         |
+---------------+---------------+
| [email protected] | role1(team a) |
|               | role2(app x)  |
+---------------+---------------+
`
	client := cmd.NewClient(&http.Client{Transport: &trans}, nil, manager)
	command := listUsers{}
	err := command.Run(&context, client)
	c.Assert(err, check.IsNil)
	c.Assert(stdout.String(), check.Equals, expected)
}
開發者ID:pauloalem,項目名稱:tsuru-client,代碼行數:32,代碼來源:auth_test.go

示例6: TestListUsersRunWithMoreThanOneFlagReturnsError

func (s *S) TestListUsersRunWithMoreThanOneFlagReturnsError(c *check.C) {
	var stdout, stderr bytes.Buffer
	context := cmd.Context{
		Stdout: &stdout,
		Stderr: &stderr,
	}
	manager := cmd.NewManager("glb", "0.2", "ad-ver", &stdout, &stderr, nil, nil)
	result := `[{"email": "[email protected]",
		"roles":[
			{"name": "role1", "contexttype": "team", "contextvalue": "a"},
			{"name": "role2", "contexttype": "app", "contextvalue": "x"}
		],
		"permissions":[
			{"name": "app.create", "contexttype": "team", "contextvalue": "a"},
			{"name": "app.deploy", "contexttype": "app", "contextvalue": "x"}
		]
		}]`
	trans := cmdtest.ConditionalTransport{
		Transport: cmdtest.Transport{Message: result, Status: http.StatusOK},
		CondFunc: func(req *http.Request) bool {
			return req.Method == "GET" && req.URL.Path == "/users" &&
				req.URL.RawQuery == "[email protected]&role=role2"
		},
	}
	client := cmd.NewClient(&http.Client{Transport: &trans}, nil, manager)
	command := listUsers{}
	command.Flags().Parse(true, []string{"-u", "[email protected]", "-r", "role2"})
	err := command.Run(&context, client)
	c.Assert(err, check.ErrorMatches, "You cannot set more than one flag. Enter <tsuru user-list --help> for more information.")
}
開發者ID:pauloalem,項目名稱:tsuru-client,代碼行數:30,代碼來源:auth_test.go

示例7: TestChangeUserQuotaRun

func (s *S) TestChangeUserQuotaRun(c *check.C) {
	var called bool
	var stdout, stderr bytes.Buffer
	context := cmd.Context{
		Args:   []string{"[email protected]", "5"},
		Stdout: &stdout,
		Stderr: &stderr,
	}
	manager := cmd.NewManager("tsuru", "0.5", "ad-ver", &stdout, &stderr, nil, nil)
	trans := cmdtest.ConditionalTransport{
		Transport: cmdtest.Transport{Message: "", Status: http.StatusOK},
		CondFunc: func(req *http.Request) bool {
			called = true
			defer req.Body.Close()
			body, err := ioutil.ReadAll(req.Body)
			c.Assert(err, check.IsNil)
			c.Assert(string(body), check.Equals, `limit=5`)
			return req.Method == "POST" && req.URL.Path == "/users/[email protected]/quota"
		},
	}
	client := cmd.NewClient(&http.Client{Transport: &trans}, nil, manager)
	command := changeUserQuota{}
	err := command.Run(&context, client)
	c.Assert(err, check.IsNil)
	c.Assert(stdout.String(), check.Equals, "Quota successfully updated.\n")
	c.Assert(called, check.Equals, true)
}
開發者ID:combor,項目名稱:tsuru-admin,代碼行數:27,代碼來源:quota_test.go

示例8: TestChangeAppQuotaRunUnlimited

func (s *S) TestChangeAppQuotaRunUnlimited(c *check.C) {
	var called bool
	var stdout, stderr bytes.Buffer
	context := cmd.Context{
		Args:   []string{"myapp", "unlimited"},
		Stdout: &stdout,
		Stderr: &stderr,
	}
	manager := cmd.NewManager("tsuru", "0.5", "ad-ver", &stdout, &stderr, nil, nil)
	trans := cmdtest.ConditionalTransport{
		Transport: cmdtest.Transport{Message: "", Status: http.StatusOK},
		CondFunc: func(req *http.Request) bool {
			called = true
			defer req.Body.Close()
			body, err := ioutil.ReadAll(req.Body)
			c.Assert(err, check.IsNil)
			c.Assert(string(body), check.Equals, "limit=-1")
			c.Assert(req.Header.Get("Content-Type"), check.Equals, "application/x-www-form-urlencoded")
			return req.Method == "POST" && req.URL.Path == "/apps/myapp/quota"
		},
	}
	client := cmd.NewClient(&http.Client{Transport: &trans}, nil, manager)
	command := changeAppQuota{}
	err := command.Run(&context, client)
	c.Assert(err, check.IsNil)
	c.Assert(stdout.String(), check.Equals, "Quota successfully updated.\n")
	c.Assert(called, check.Equals, true)
}
開發者ID:combor,項目名稱:tsuru-admin,代碼行數:28,代碼來源:quota_test.go

示例9: TestBsUpgradeRun

func (s *S) TestBsUpgradeRun(c *check.C) {
	var called bool
	var stdout, stderr bytes.Buffer
	context := cmd.Context{
		Stdout: &stdout,
		Stderr: &stderr,
		Args:   []string{"A=1", "B=2"},
	}
	msg := io.SimpleJsonMessage{Message: "it worked!"}
	result, err := json.Marshal(msg)
	trans := &cmdtest.ConditionalTransport{
		Transport: cmdtest.Transport{Message: string(result), Status: http.StatusNoContent},
		CondFunc: func(req *http.Request) bool {
			called = true
			return req.URL.Path == "/docker/bs/upgrade" && req.Method == "POST"
		},
	}
	manager := cmd.NewManager("admin", "0.1", "admin-ver", &stdout, &stderr, nil, nil)
	client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager)
	cmd := UpgradeCmd{}
	err = cmd.Run(&context, client)
	c.Assert(err, check.IsNil)
	c.Assert(stdout.String(), check.Equals, "it worked!")
	c.Assert(called, check.Equals, true)
}
開發者ID:nikolasmagno,項目名稱:tsuru,代碼行數:25,代碼來源:cmd_test.go

示例10: TestDockerLogUpdateRun

func (s *S) TestDockerLogUpdateRun(c *check.C) {
	var stdout, stderr bytes.Buffer
	context := cmd.Context{
		Stdout: &stdout,
		Stderr: &stderr,
	}
	msg := tsuruIo.SimpleJsonMessage{Message: "success!!!"}
	result, _ := json.Marshal(msg)
	trans := &cmdtest.ConditionalTransport{
		Transport: cmdtest.Transport{Message: string(result), Status: http.StatusNoContent},
		CondFunc: func(req *http.Request) bool {
			defer req.Body.Close()
			body, err := ioutil.ReadAll(req.Body)
			c.Assert(err, check.IsNil)
			expected := provision.ScopedConfig{
				Envs: []provision.Entry{{Name: "a", Value: "1"}, {Name: "b", Value: "2"}, {Name: "log-driver", Value: "x"}},
			}
			var data logsSetData
			err = json.Unmarshal(body, &data)
			c.Assert(err, check.IsNil)
			sort.Sort(provision.ConfigEntryList(data.Config.Envs))
			c.Assert(data.Config, check.DeepEquals, expected)
			return req.URL.Path == "/1.0/docker/logs" && req.Method == "POST"
		},
	}
	manager := cmd.NewManager("admin", "0.1", "admin-ver", &stdout, &stderr, nil, nil)
	client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager)
	cmd := dockerLogUpdate{}
	err := cmd.Flags().Parse(true, []string{"--log-driver", "x", "--log-opt", "a=1", "--log-opt", "b=2"})
	c.Assert(err, check.IsNil)
	err = cmd.Run(&context, client)
	c.Assert(err, check.IsNil)
	c.Assert(stdout.String(), check.Equals, "success!!!")
}
開發者ID:ggarnier,項目名稱:tsuru,代碼行數:34,代碼來源:cmd_test.go

示例11: TestBsEnvSetRun

func (s *S) TestBsEnvSetRun(c *check.C) {
	var stdout, stderr bytes.Buffer
	context := cmd.Context{
		Stdout: &stdout,
		Stderr: &stderr,
		Args:   []string{"A=1", "B=2"},
	}
	msg := io.SimpleJsonMessage{Message: "env-set success"}
	result, _ := json.Marshal(msg)
	trans := &cmdtest.ConditionalTransport{
		Transport: cmdtest.Transport{Message: string(result), Status: http.StatusNoContent},
		CondFunc: func(req *http.Request) bool {
			defer req.Body.Close()
			body, err := ioutil.ReadAll(req.Body)
			c.Assert(err, check.IsNil)
			expected := Config{
				Envs: []Env{{Name: "A", Value: "1"}, {Name: "B", Value: "2"}},
			}
			var conf Config
			err = json.Unmarshal(body, &conf)
			c.Assert(conf, check.DeepEquals, expected)
			return req.URL.Path == "/docker/bs/env" && req.Method == "POST"
		},
	}
	manager := cmd.NewManager("admin", "0.1", "admin-ver", &stdout, &stderr, nil, nil)
	client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager)
	cmd := EnvSetCmd{}
	err := cmd.Run(&context, client)
	c.Assert(err, check.IsNil)
	c.Assert(stdout.String(), check.Equals, "env-set success")
}
開發者ID:nikolasmagno,項目名稱:tsuru,代碼行數:31,代碼來源:cmd_test.go

示例12: TestDockerLogUpdateForPoolRun

func (s *S) TestDockerLogUpdateForPoolRun(c *check.C) {
	var stdout, stderr bytes.Buffer
	context := cmd.Context{
		Stdout: &stdout,
		Stderr: &stderr,
	}
	msg := tsuruIo.SimpleJsonMessage{Message: "success!!!"}
	result, _ := json.Marshal(msg)
	trans := &cmdtest.ConditionalTransport{
		Transport: cmdtest.Transport{Message: string(result), Status: http.StatusNoContent},
		CondFunc: func(req *http.Request) bool {
			err := req.ParseForm()
			c.Assert(err, check.IsNil)
			c.Assert(req.Form, check.DeepEquals, url.Values{
				"restart":   []string{"false"},
				"pool":      []string{"p1"},
				"Driver":    []string{"x"},
				"LogOpts.a": []string{"1"},
				"LogOpts.b": []string{"2"},
			})
			return req.URL.Path == "/1.0/docker/logs" && req.Method == "POST"
		},
	}
	manager := cmd.NewManager("admin", "0.1", "admin-ver", &stdout, &stderr, nil, nil)
	client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager)
	cmd := dockerLogUpdate{}
	err := cmd.Flags().Parse(true, []string{"--pool", "p1", "--log-driver", "x", "--log-opt", "a=1", "--log-opt", "b=2"})
	c.Assert(err, check.IsNil)
	err = cmd.Run(&context, client)
	c.Assert(err, check.IsNil)
	c.Assert(stdout.String(), check.Equals, "success!!!")
}
開發者ID:tsuru,項目名稱:tsuru,代碼行數:32,代碼來源:cmd_test.go

示例13: TestMoveContainerRun

func (s *S) TestMoveContainerRun(c *check.C) {
	var stdout, stderr bytes.Buffer
	context := cmd.Context{
		Stdout: &stdout,
		Stderr: &stderr,
		Args:   []string{"contId", "toHost"},
	}
	msg, _ := json.Marshal(tsuruIo.SimpleJsonMessage{Message: "progress msg"})
	result := string(msg)
	trans := &cmdtest.ConditionalTransport{
		Transport: cmdtest.Transport{Message: result, Status: http.StatusOK},
		CondFunc: func(req *http.Request) bool {
			path := req.URL.Path == "/1.0/docker/container/contId/move"
			method := req.Method == "POST"
			to := req.FormValue("to") == "toHost"
			return path && method && to
		},
	}
	manager := cmd.NewManager("admin", "0.1", "admin-ver", &stdout, &stderr, nil, nil)
	client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager)
	cmd := moveContainerCmd{}
	err := cmd.Run(&context, client)
	c.Assert(err, check.IsNil)
	expected := "progress msg"
	c.Assert(stdout.String(), check.Equals, expected)
}
開發者ID:tsuru,項目名稱:tsuru,代碼行數:26,代碼來源:admin_test.go

示例14: TestRebalanceContainersRunAskingForConfirmation

func (s *S) TestRebalanceContainersRunAskingForConfirmation(c *check.C) {
	var stdout, stderr bytes.Buffer
	context := cmd.Context{
		Stdout: &stdout,
		Stderr: &stderr,
		Stdin:  bytes.NewBufferString("y"),
	}
	msg, _ := json.Marshal(tsuruIo.SimpleJsonMessage{Message: "progress msg"})
	result := string(msg)
	trans := &cmdtest.ConditionalTransport{
		Transport: cmdtest.Transport{Message: result, Status: http.StatusOK},
		CondFunc: func(req *http.Request) bool {
			req.ParseForm()
			var params rebalanceOptions
			dec := form.NewDecoder(nil)
			dec.IgnoreUnknownKeys(true)
			err := dec.DecodeValues(&params, req.Form)
			c.Assert(err, check.IsNil)
			c.Assert(params.Dry, check.Equals, false)
			path := req.URL.Path == "/1.0/docker/containers/rebalance"
			method := req.Method == "POST"
			return path && method
		},
	}
	manager := cmd.NewManager("admin", "0.1", "admin-ver", &stdout, &stderr, nil, nil)
	client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager)
	cmd := rebalanceContainersCmd{}
	err := cmd.Run(&context, client)
	c.Assert(err, check.IsNil)
	c.Assert(stdout.String(), check.Equals, "Are you sure you want to rebalance containers? (y/n) progress msg")
	cmd2 := rebalanceContainersCmd{}
	err = cmd2.Run(&context, client)
	c.Assert(err, check.IsNil)
}
開發者ID:tsuru,項目名稱:tsuru,代碼行數:34,代碼來源:admin_test.go

示例15: TestMoveContainerRun

func (s *S) TestMoveContainerRun(c *check.C) {
	var stdout, stderr bytes.Buffer
	context := cmd.Context{
		Stdout: &stdout,
		Stderr: &stderr,
		Args:   []string{"contId", "toHost"},
	}
	msg, _ := json.Marshal(tsuruIo.SimpleJsonMessage{Message: "progress msg"})
	result := string(msg)
	trans := &cmdtest.ConditionalTransport{
		Transport: cmdtest.Transport{Message: result, Status: http.StatusOK},
		CondFunc: func(req *http.Request) bool {
			defer req.Body.Close()
			body, err := ioutil.ReadAll(req.Body)
			c.Assert(err, check.IsNil)
			expected := map[string]string{
				"to": "toHost",
			}
			result := map[string]string{}
			err = json.Unmarshal(body, &result)
			c.Assert(expected, check.DeepEquals, result)
			return req.URL.Path == "/docker/container/contId/move" && req.Method == "POST"
		},
	}
	manager := cmd.NewManager("admin", "0.1", "admin-ver", &stdout, &stderr, nil, nil)
	client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager)
	cmd := moveContainerCmd{}
	err := cmd.Run(&context, client)
	c.Assert(err, check.IsNil)
	expected := "progress msg"
	c.Assert(stdout.String(), check.Equals, expected)
}
開發者ID:maxwhale,項目名稱:tsuru,代碼行數:32,代碼來源:admin_test.go


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