本文整理汇总了Golang中github.com/tsuru/tsuru/cmd.JoinWithUserDir函数的典型用法代码示例。如果您正苦于以下问题:Golang JoinWithUserDir函数的具体用法?Golang JoinWithUserDir怎么用?Golang JoinWithUserDir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JoinWithUserDir函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Run
func (c *pluginInstall) Run(context *cmd.Context, client *cmd.Client) error {
pluginsDir := cmd.JoinWithUserDir(".tsuru", "plugins")
err := filesystem().MkdirAll(pluginsDir, 0755)
if err != nil {
return err
}
pluginName := context.Args[0]
pluginUrl := context.Args[1]
pluginPath := cmd.JoinWithUserDir(".tsuru", "plugins", pluginName)
file, err := filesystem().OpenFile(pluginPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755)
if err != nil {
return err
}
resp, err := http.Get(pluginUrl)
if err != nil {
return err
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
n, err := file.Write(data)
if err != nil {
return err
}
if n != len(data) {
return errors.New("Failed to install plugin.")
}
fmt.Fprintf(context.Stdout, `Plugin "%s" successfully installed!`+"\n", pluginName)
return nil
}
示例2: TestPluginInstall
func (s *S) TestPluginInstall(c *gocheck.C) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "fakeplugin")
}))
defer ts.Close()
rfs := ftesting.RecordingFs{}
fsystem = &rfs
defer func() {
fsystem = nil
}()
var stdout bytes.Buffer
context := cmd.Context{
Args: []string{"myplugin", ts.URL},
Stdout: &stdout,
}
client := cmd.NewClient(nil, nil, manager)
command := pluginInstall{}
err := command.Run(&context, client)
c.Assert(err, gocheck.IsNil)
pluginsPath := cmd.JoinWithUserDir(".tsuru", "plugins")
hasAction := rfs.HasAction(fmt.Sprintf("mkdirall %s with mode 0755", pluginsPath))
c.Assert(hasAction, gocheck.Equals, true)
pluginPath := cmd.JoinWithUserDir(".tsuru", "plugins", "myplugin")
hasAction = rfs.HasAction(fmt.Sprintf("openfile %s with mode 0755", pluginPath))
c.Assert(hasAction, gocheck.Equals, true)
f, err := rfs.Open(pluginPath)
c.Assert(err, gocheck.IsNil)
data, err := ioutil.ReadAll(f)
c.Assert(err, gocheck.IsNil)
c.Assert("fakeplugin\n", gocheck.Equals, string(data))
expected := `Plugin "myplugin" successfully installed!` + "\n"
c.Assert(expected, gocheck.Equals, stdout.String())
}
示例3: TestUserRemoveWithArgs
func (s *S) TestUserRemoveWithArgs(c *check.C) {
rfs := &fstest.RecordingFs{}
f, _ := rfs.Create(cmd.JoinWithUserDir(".tsuru_target"))
f.Write([]byte("http://tsuru.io"))
f.Close()
fsystem = rfs
defer func() {
fsystem = nil
}()
var (
buf bytes.Buffer
called bool
)
context := cmd.Context{
Stdout: &buf,
Stdin: strings.NewReader("y\n"),
Args: []string{"[email protected]"},
}
trans := cmdtest.ConditionalTransport{
Transport: cmdtest.Transport{Message: "", Status: http.StatusOK},
CondFunc: func(req *http.Request) bool {
called = true
return req.Method == "DELETE" && req.URL.Path == "/users" && req.URL.Query().Get("user") == context.Args[0]
},
}
client := cmd.NewClient(&http.Client{Transport: &trans}, nil, manager)
command := userRemove{}
err := command.Run(&context, client)
c.Assert(err, check.IsNil)
c.Assert(called, check.Equals, true)
c.Assert(buf.String(), check.Equals, "Are you sure you want to remove the user \"[email protected]\" from tsuru? (y/n) User \"[email protected]\" successfully removed.\n")
c.Assert(rfs.HasAction("remove "+cmd.JoinWithUserDir(".tsuru_token")), check.Equals, true)
}
示例4: Run
func (c *plugin) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
pluginName := context.Args[0]
pluginPath := cmd.JoinWithUserDir(".tsuru", "plugins", pluginName)
target, err := cmd.GetURL("/")
if err != nil {
return err
}
token, err := cmd.ReadToken()
if err != nil {
return err
}
envs := os.Environ()
tsuruEnvs := []string{
"TSURU_TARGET=" + target,
"TSURU_TOKEN=" + token,
"TSURU_PLUGIN_NAME=" + pluginName,
}
envs = append(envs, tsuruEnvs...)
opts := exec.ExecuteOptions{
Cmd: pluginPath,
Args: context.Args[1:],
Stdout: context.Stdout,
Stderr: context.Stderr,
Stdin: context.Stdin,
Envs: envs,
}
return executor().Execute(opts)
}
示例5: Run
func (c *plugin) Run(context *cmd.Context, client *cmd.Client) error {
pluginName := context.Args[0]
pluginPath := cmd.JoinWithUserDir(".tsuru", "plugins", pluginName)
err := executor().Execute(pluginPath, context.Args[1:], nil, context.Stdout, context.Stderr)
if err != nil {
return err
}
return nil
}
示例6: TestPluginLookup
func (s *S) TestPluginLookup(c *check.C) {
fexec := exectest.FakeExecutor{}
execut = &fexec
defer func() {
execut = nil
}()
manager := buildManager("tsuru")
manager.Run([]string{"myplugin"})
pluginPath := cmd.JoinWithUserDir(".tsuru", "plugins", "myplugin")
c.Assert(fexec.ExecutedCmd(pluginPath, []string{}), check.Equals, true)
}
示例7: TestUserRemove
func (s *S) TestUserRemove(c *check.C) {
rfs := &fstest.RecordingFs{}
f, _ := rfs.Create(cmd.JoinWithUserDir(".tsuru_target"))
f.Write([]byte("http://tsuru.io"))
f.Close()
fsystem = rfs
defer func() {
fsystem = nil
}()
var (
buf bytes.Buffer
called bool
)
context := cmd.Context{
Stdout: &buf,
Stdin: strings.NewReader("y\n"),
}
transport := transportFunc(func(req *http.Request) (*http.Response, error) {
var body string
if req.URL.Path == "/users/info" && req.Method == "GET" {
body = `{"Email":"[email protected]","Teams":[]}`
} else if req.URL.Path == "/users" && req.Method == "DELETE" {
called = true
}
return &http.Response{
Body: ioutil.NopCloser(bytes.NewBufferString(body)),
StatusCode: http.StatusOK,
}, nil
})
client := cmd.NewClient(&http.Client{Transport: transport}, nil, manager)
command := userRemove{}
err := command.Run(&context, client)
c.Assert(err, check.IsNil)
c.Assert(called, check.Equals, true)
c.Assert(buf.String(), check.Equals, "Are you sure you want to remove the user \"[email protected]\" from tsuru? (y/n) User \"[email protected]\" successfully removed.\n")
c.Assert(rfs.HasAction("remove "+cmd.JoinWithUserDir(".tsuru_token")), check.Equals, true)
}
示例8: TestPluginWithArgs
func (s *S) TestPluginWithArgs(c *gocheck.C) {
fexec := etesting.FakeExecutor{}
execut = &fexec
defer func() {
execut = nil
}()
context := cmd.Context{
Args: []string{"myplugin", "ble", "bla"},
}
client := cmd.NewClient(nil, nil, manager)
command := plugin{}
err := command.Run(&context, client)
c.Assert(err, gocheck.IsNil)
pluginPath := cmd.JoinWithUserDir(".tsuru", "plugins", "myplugin")
c.Assert(fexec.ExecutedCmd(pluginPath, []string{"ble", "bla"}), gocheck.Equals, true)
}
示例9: TestPluginRemove
func (s *S) TestPluginRemove(c *gocheck.C) {
rfs := ftesting.RecordingFs{}
fsystem = &rfs
defer func() {
fsystem = nil
}()
var stdout bytes.Buffer
context := cmd.Context{
Args: []string{"myplugin"},
Stdout: &stdout,
}
client := cmd.NewClient(nil, nil, manager)
command := pluginRemove{}
err := command.Run(&context, client)
c.Assert(err, gocheck.IsNil)
pluginPath := cmd.JoinWithUserDir(".tsuru", "plugins", "myplugin")
hasAction := rfs.HasAction(fmt.Sprintf("remove %s", pluginPath))
c.Assert(hasAction, gocheck.Equals, true)
expected := `Plugin "myplugin" successfully removed!` + "\n"
c.Assert(expected, gocheck.Equals, stdout.String())
}
示例10: Run
func (c *userRemove) Run(context *cmd.Context, client *cmd.Client) error {
var (
answer string
email string
err error
)
if len(context.Args) > 0 {
email = context.Args[0]
} else {
email, err = c.currentUserEmail(client)
if err != nil {
return err
}
}
fmt.Fprintf(context.Stdout, `Are you sure you want to remove the user %q from tsuru? (y/n) `, email)
fmt.Fscanf(context.Stdin, "%s", &answer)
if answer != "y" {
fmt.Fprintln(context.Stdout, "Abort.")
return nil
}
url, err := cmd.GetURL("/users")
if err != nil {
return err
}
var qs string
if email != "" {
qs = "?user=" + email
}
request, err := http.NewRequest("DELETE", url+qs, nil)
if err != nil {
return err
}
_, err = client.Do(request)
if err != nil {
return err
}
filesystem().Remove(cmd.JoinWithUserDir(".tsuru_token"))
fmt.Fprintf(context.Stdout, "User %q successfully removed.\n", email)
return nil
}
示例11: TestPlugin
func (s *S) TestPlugin(c *check.C) {
fexec := exectest.FakeExecutor{
Output: map[string][][]byte{
"a b": {[]byte("hello world")},
},
}
execut = &fexec
defer func() {
execut = nil
}()
var buf bytes.Buffer
context := cmd.Context{
Args: []string{"myplugin", "a", "b"},
Stdout: &buf,
Stderr: &buf,
}
client := cmd.NewClient(nil, nil, manager)
command := plugin{}
err := command.Run(&context, client)
c.Assert(err, check.IsNil)
pluginPath := cmd.JoinWithUserDir(".tsuru", "plugins", "myplugin")
c.Assert(fexec.ExecutedCmd(pluginPath, []string{"a", "b"}), check.Equals, true)
c.Assert(buf.String(), check.Equals, "hello world")
commands := fexec.GetCommands(pluginPath)
c.Assert(commands, check.HasLen, 1)
target, err := cmd.ReadTarget()
c.Assert(err, check.IsNil)
token, err := cmd.ReadToken()
c.Assert(err, check.IsNil)
envs := os.Environ()
tsuruEnvs := []string{
fmt.Sprintf("TSURU_TARGET=%s/", target),
fmt.Sprintf("TSURU_TOKEN=%s", token),
"TSURU_PLUGIN_NAME=myplugin",
}
envs = append(envs, tsuruEnvs...)
c.Assert(commands[0].GetEnvs(), check.DeepEquals, envs)
}
示例12: TestUserCreateShouldNotDependOnTsuruTokenFile
func (s *S) TestUserCreateShouldNotDependOnTsuruTokenFile(c *check.C) {
rfs := &fstest.RecordingFs{}
f, _ := rfs.Create(cmd.JoinWithUserDir(".tsuru_target"))
f.Write([]byte("http://localhost"))
f.Close()
fsystem = rfs
defer func() {
fsystem = nil
}()
expected := "Password: \nConfirm: \n" + `User "[email protected]" successfully created!` + "\n"
reader := strings.NewReader("foo123\nfoo123\n")
var stdout, stderr bytes.Buffer
context := cmd.Context{
Args: []string{"[email protected]"},
Stdout: &stdout,
Stderr: &stderr,
Stdin: reader,
}
client := cmd.NewClient(&http.Client{Transport: &cmdtest.Transport{Message: "", Status: http.StatusCreated}}, nil, manager)
command := userCreate{}
err := command.Run(&context, client)
c.Assert(err, check.IsNil)
c.Assert(stdout.String(), check.Equals, expected)
}
示例13: TestPlugin
func (s *S) TestPlugin(c *gocheck.C) {
fexec := etesting.FakeExecutor{
Output: map[string][][]byte{
"a b": {[]byte("hello world")},
},
}
execut = &fexec
defer func() {
execut = nil
}()
var buf bytes.Buffer
context := cmd.Context{
Args: []string{"myplugin", "a", "b"},
Stdout: &buf,
Stderr: &buf,
}
client := cmd.NewClient(nil, nil, manager)
command := plugin{}
err := command.Run(&context, client)
c.Assert(err, gocheck.IsNil)
pluginPath := cmd.JoinWithUserDir(".tsuru", "plugins", "myplugin")
c.Assert(fexec.ExecutedCmd(pluginPath, []string{"a", "b"}), gocheck.Equals, true)
c.Assert(buf.String(), gocheck.Equals, "hello world")
}