func (s *S) TestPluginInstall(c *check.C) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "fakeplugin") })) defer ts.Close() rfs := fstest.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, check.IsNil) pluginsPath := cmd.JoinWithUserDir(".tsuru", "plugins") hasAction := rfs.HasAction(fmt.Sprintf("mkdirall %s with mode 0755", pluginsPath)) c.Assert(hasAction, check.Equals, true) pluginPath := cmd.JoinWithUserDir(".tsuru", "plugins", "myplugin") hasAction = rfs.HasAction(fmt.Sprintf("openfile %s with mode 0755", pluginPath)) c.Assert(hasAction, check.Equals, true) f, err := rfs.Open(pluginPath) c.Assert(err, check.IsNil) data, err := ioutil.ReadAll(f) c.Assert(err, check.IsNil) c.Assert("fakeplugin\n", check.Equals, string(data)) expected := `Plugin "myplugin" successfully installed!` + "\n" c.Assert(expected, check.Equals, stdout.String()) }
func (s *S) TestReadTargetLegacy(c *check.C) { os.Unsetenv("TSURU_TARGET") var rfs fstest.RecordingFs fsystem = &rfs defer func() { fsystem = nil }() f, err := fsystem.Create(JoinWithUserDir(".tsuru_target")) c.Assert(err, check.IsNil) f.WriteString("http://tsuru.google.com") f.Close() target, err := ReadTarget() c.Assert(err, check.IsNil) c.Assert(target, check.Equals, "http://tsuru.google.com") target, err = readTarget(JoinWithUserDir(".tsuru", "target")) c.Assert(err, check.IsNil) c.Assert(target, check.Equals, "http://tsuru.google.com") dir := JoinWithUserDir(".tsuru") c.Assert(rfs.HasAction("mkdirall "+dir+" with mode 0700"), check.Equals, true) }
func (s *S) TestPluginRemove(c *check.C) { rfs := fstest.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, check.IsNil) pluginPath := cmd.JoinWithUserDir(".tsuru", "plugins", "myplugin") hasAction := rfs.HasAction(fmt.Sprintf("remove %s", pluginPath)) c.Assert(hasAction, check.Equals, true) expected := `Plugin "myplugin" successfully removed!` + "\n" c.Assert(expected, check.Equals, stdout.String()) }