本文整理汇总了Golang中github.com/tsuru/tsuru/app.PlatformAdd函数的典型用法代码示例。如果您正苦于以下问题:Golang PlatformAdd函数的具体用法?Golang PlatformAdd怎么用?Golang PlatformAdd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PlatformAdd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: platformAdd
func platformAdd(w http.ResponseWriter, r *http.Request, t auth.Token) error {
defer r.Body.Close()
name := r.FormValue("name")
file, _, _ := r.FormFile("dockerfile_content")
if file != nil {
defer file.Close()
}
args := make(map[string]string)
for key, values := range r.Form {
args[key] = values[0]
}
canCreatePlatform := permission.Check(t, permission.PermPlatformCreate)
if !canCreatePlatform {
return permission.ErrUnauthorized
}
w.Header().Set("Content-Type", "text")
keepAliveWriter := io.NewKeepAliveWriter(w, 30*time.Second, "")
defer keepAliveWriter.Stop()
writer := &io.SimpleJsonMessageEncoderWriter{Encoder: json.NewEncoder(keepAliveWriter)}
err := app.PlatformAdd(provision.PlatformOptions{
Name: name,
Args: args,
Input: file,
Output: writer,
})
if err != nil {
writer.Encode(io.SimpleJsonMessage{Error: err.Error()})
writer.Write([]byte("Failed to add platform!\n"))
return nil
}
writer.Write([]byte("Platform successfully added!\n"))
return nil
}
示例2: TestPlatformUpdate
func (s *PlatformSuite) TestPlatformUpdate(c *check.C) {
provisioner := provisiontest.ExtensibleFakeProvisioner{
FakeProvisioner: provisiontest.NewFakeProvisioner(),
}
oldProvisioner := app.Provisioner
app.Provisioner = &provisioner
defer func() {
app.Provisioner = oldProvisioner
}()
err := app.PlatformAdd(provision.PlatformOptions{Name: "wat", Args: nil, Output: nil})
c.Assert(err, check.IsNil)
var buf bytes.Buffer
dockerfileURL := "http://localhost/Dockerfile"
writer := multipart.NewWriter(&buf)
writer.WriteField("dockerfile", dockerfileURL)
writer.Close()
request, _ := http.NewRequest("PUT", "/platforms/wat", &buf)
request.Header.Add("Content-Type", writer.FormDataContentType())
token := createToken(c)
request.Header.Set("Authorization", "b "+token.GetValue())
recorder := httptest.NewRecorder()
m := RunServer(true)
m.ServeHTTP(recorder, request)
var msg io.SimpleJsonMessage
json.Unmarshal(recorder.Body.Bytes(), &msg)
c.Assert(errors.New(msg.Error), check.ErrorMatches, "")
c.Assert(recorder.Header().Get("Content-Type"), check.Equals, "application/x-json-stream")
}
示例3: TestPlatformUpdate
func (p *PlatformSuite) TestPlatformUpdate(c *check.C) {
provisioner := provisiontest.ExtensibleFakeProvisioner{
FakeProvisioner: provisiontest.NewFakeProvisioner(),
}
oldProvisioner := app.Provisioner
app.Provisioner = &provisioner
defer func() {
app.Provisioner = oldProvisioner
}()
err := app.PlatformAdd(provision.PlatformOptions{Name: "wat", Args: nil, Output: nil})
c.Assert(err, check.IsNil)
var buf bytes.Buffer
dockerfileURL := "http://localhost/Dockerfile"
writer := multipart.NewWriter(&buf)
writer.WriteField("dockerfile", dockerfileURL)
writer.Close()
request, _ := http.NewRequest("PUT", "/platforms/wat?:name=wat", &buf)
request.Header.Add("Content-Type", writer.FormDataContentType())
recorder := httptest.NewRecorder()
token := createToken(c)
result := platformUpdate(recorder, request, token)
c.Assert(result, check.IsNil)
b, err := ioutil.ReadAll(recorder.Body)
c.Assert(err, check.IsNil)
var msg io.SimpleJsonMessage
json.Unmarshal(b, &msg)
c.Assert(errors.New(msg.Error), check.ErrorMatches, "")
}
示例4: TestPlatformUpdateDisableFalseAndDockerfile
func (p *PlatformSuite) TestPlatformUpdateDisableFalseAndDockerfile(c *check.C) {
provisioner := provisiontest.ExtensibleFakeProvisioner{
FakeProvisioner: provisiontest.NewFakeProvisioner(),
}
oldProvisioner := app.Provisioner
app.Provisioner = &provisioner
defer func() {
app.Provisioner = oldProvisioner
}()
err := app.PlatformAdd(provision.PlatformOptions{Name: "wat", Args: nil, Output: nil})
c.Assert(err, check.IsNil)
dockerfile_url := "http://localhost/Dockerfile"
body := fmt.Sprintf("dockerfile=%s", dockerfile_url)
request, _ := http.NewRequest("PUT", "/platforms/wat?:name=wat&disabled=false", strings.NewReader(body))
request.Header.Add("Content-Type", "multipart/form-data")
recorder := httptest.NewRecorder()
token := createToken(c)
result := platformUpdate(recorder, request, token)
c.Assert(result, check.IsNil)
b, err := ioutil.ReadAll(recorder.Body)
c.Assert(err, check.IsNil)
var msg io.SimpleJsonMessage
json.Unmarshal(b, &msg)
c.Assert(errors.New(msg.Error), check.ErrorMatches, "")
}
示例5: TestPlatformUpdateDisableTrueAndDockerfile
func (s *PlatformSuite) TestPlatformUpdateDisableTrueAndDockerfile(c *check.C) {
err := app.PlatformAdd(provision.PlatformOptions{Name: "wat", Args: nil, Output: nil})
c.Assert(err, check.IsNil)
dockerfileURL := "http://localhost/Dockerfile"
var buf bytes.Buffer
writer := multipart.NewWriter(&buf)
writer.WriteField("dockerfile", dockerfileURL)
writer.WriteField("disabled", "true")
writer.Close()
request, _ := http.NewRequest("PUT", "/platforms/wat?:name=wat", &buf)
request.Header.Add("Content-Type", writer.FormDataContentType())
recorder := httptest.NewRecorder()
token := createToken(c)
result := platformUpdate(recorder, request, token)
c.Assert(result, check.IsNil)
var msg io.SimpleJsonMessage
json.Unmarshal(recorder.Body.Bytes(), &msg)
c.Assert(errors.New(msg.Error), check.ErrorMatches, "")
c.Assert(eventtest.EventDesc{
Target: event.Target{Type: event.TargetTypePlatform, Value: "wat"},
Owner: token.GetUserName(),
Kind: "platform.update",
StartCustomData: []map[string]interface{}{
{"name": ":name", "value": "wat"},
{"name": "disabled", "value": "true"},
{"name": "dockerfile", "value": dockerfileURL},
},
}, eventtest.HasEvent)
}
示例6: TestPlatformUpdateOnlyDisableTrue
func (s *PlatformSuite) TestPlatformUpdateOnlyDisableTrue(c *check.C) {
provisioner := provisiontest.ExtensibleFakeProvisioner{
FakeProvisioner: provisiontest.NewFakeProvisioner(),
}
oldProvisioner := app.Provisioner
app.Provisioner = &provisioner
defer func() {
app.Provisioner = oldProvisioner
}()
err := app.PlatformAdd(provision.PlatformOptions{Name: "wat", Args: nil, Output: nil})
c.Assert(err, check.IsNil)
dockerfileURL := ""
body := fmt.Sprintf("dockerfile=%s", dockerfileURL)
request, err := http.NewRequest("PUT", "/platforms/wat?disabled=true", strings.NewReader(body))
c.Assert(err, check.IsNil)
token := createToken(c)
request.Header.Add("Authorization", "b "+token.GetValue())
request.Header.Add("Content-Type", "multipart/form-data")
recorder := httptest.NewRecorder()
m := RunServer(true)
m.ServeHTTP(recorder, request)
c.Assert(recorder.Code, check.Equals, http.StatusOK)
c.Assert(recorder.Header().Get("Content-Type"), check.Equals, "application/x-json-stream")
var msg io.SimpleJsonMessage
json.Unmarshal(recorder.Body.Bytes(), &msg)
c.Assert(errors.New(msg.Error), check.ErrorMatches, "")
}
示例7: TestPlatformUpdateOnlyDisableTrue
func (s *PlatformSuite) TestPlatformUpdateOnlyDisableTrue(c *check.C) {
err := app.PlatformAdd(provision.PlatformOptions{Name: "wat", Args: nil, Output: nil})
c.Assert(err, check.IsNil)
var buf bytes.Buffer
writer := multipart.NewWriter(&buf)
writer.WriteField("dockerfile", "")
writer.WriteField("disabled", "true")
writer.Close()
request, err := http.NewRequest("PUT", "/platforms/wat", &buf)
c.Assert(err, check.IsNil)
token := createToken(c)
request.Header.Add("Authorization", "b "+token.GetValue())
request.Header.Add("Content-Type", writer.FormDataContentType())
recorder := httptest.NewRecorder()
m := RunServer(true)
m.ServeHTTP(recorder, request)
c.Assert(recorder.Code, check.Equals, http.StatusOK)
c.Assert(recorder.Header().Get("Content-Type"), check.Equals, "application/x-json-stream")
var msg io.SimpleJsonMessage
json.Unmarshal(recorder.Body.Bytes(), &msg)
c.Assert(errors.New(msg.Error), check.ErrorMatches, "")
c.Assert(eventtest.EventDesc{
Target: event.Target{Type: event.TargetTypePlatform, Value: "wat"},
Owner: token.GetUserName(),
Kind: "platform.update",
StartCustomData: []map[string]interface{}{
{"name": ":name", "value": "wat"},
{"name": "disabled", "value": "true"},
},
}, eventtest.HasEvent)
}
示例8: platformAdd
func platformAdd(w http.ResponseWriter, r *http.Request, t auth.Token) error {
name := r.FormValue("name")
args := make(map[string]string)
for key, values := range r.Form {
args[key] = values[0]
}
w.Header().Set("Content-Type", "text")
return app.PlatformAdd(name, args, w)
}
示例9: platformAdd
func platformAdd(w http.ResponseWriter, r *http.Request, t *auth.Token) error {
name := r.FormValue("name")
dockerfile := r.FormValue("dockerfile")
err := app.PlatformAdd(name, dockerfile)
if err != nil {
return err
}
return nil
}
示例10: platformAdd
func platformAdd(w http.ResponseWriter, r *http.Request, t auth.Token) error {
name := r.FormValue("name")
args := make(map[string]string)
for key, values := range r.Form {
args[key] = values[0]
}
w.Header().Set("Content-Type", "text")
writer := io.NewKeepAliveWriter(w, 30*time.Second, "please wait...")
err := app.PlatformAdd(name, args, writer)
if err != nil {
return err
}
fmt.Fprintln(w, "\nOK!")
return nil
}
示例11: TestPlatformRemove
func (p *PlatformSuite) TestPlatformRemove(c *check.C) {
provisioner := provisiontest.ExtensibleFakeProvisioner{
FakeProvisioner: provisiontest.NewFakeProvisioner(),
}
oldProvisioner := app.Provisioner
app.Provisioner = &provisioner
defer func() {
app.Provisioner = oldProvisioner
}()
err := app.PlatformAdd("test", nil, nil)
c.Assert(err, check.IsNil)
request, _ := http.NewRequest("DELETE", "/platforms/test?:name=test", nil)
recorder := httptest.NewRecorder()
err = platformRemove(recorder, request, nil)
c.Assert(err, check.IsNil)
}
示例12: TestPlatformRemove
func (*PlatformSuite) TestPlatformRemove(c *check.C) {
err := app.PlatformAdd(provision.PlatformOptions{Name: "test", Args: nil, Output: nil})
c.Assert(err, check.IsNil)
request, _ := http.NewRequest("DELETE", "/platforms/test?:name=test", nil)
recorder := httptest.NewRecorder()
token := createToken(c)
err = platformRemove(recorder, request, token)
c.Assert(err, check.IsNil)
c.Assert(eventtest.EventDesc{
Target: event.Target{Type: event.TargetTypePlatform, Value: "test"},
Owner: token.GetUserName(),
Kind: "platform.delete",
StartCustomData: []map[string]interface{}{
{"name": ":name", "value": "test"},
},
}, eventtest.HasEvent)
}
示例13: TestPlatformRemove
func (p *PlatformSuite) TestPlatformRemove(c *check.C) {
provisioner := provisiontest.ExtensibleFakeProvisioner{
FakeProvisioner: provisiontest.NewFakeProvisioner(),
}
oldProvisioner := app.Provisioner
app.Provisioner = &provisioner
defer func() {
app.Provisioner = oldProvisioner
}()
err := app.PlatformAdd(provision.PlatformOptions{Name: "test", Args: nil, Output: nil})
c.Assert(err, check.IsNil)
request, _ := http.NewRequest("DELETE", "/platforms/test?:name=test", nil)
recorder := httptest.NewRecorder()
token := createToken(c)
err = platformRemove(recorder, request, token)
c.Assert(err, check.IsNil)
}
示例14: TestPlatformUpdate
func (p *PlatformSuite) TestPlatformUpdate(c *gocheck.C) {
provisioner := testing.ExtensibleFakeProvisioner{
FakeProvisioner: testing.NewFakeProvisioner(),
}
oldProvisioner := app.Provisioner
app.Provisioner = &provisioner
defer func() {
app.Provisioner = oldProvisioner
}()
err := app.PlatformAdd("wat", nil, nil)
c.Assert(err, gocheck.IsNil)
dockerfile_url := "http://localhost/Dockerfile"
body := fmt.Sprintf("dockerfile=%s", dockerfile_url)
request, _ := http.NewRequest("PUT", "/platforms/wat?:name=wat", strings.NewReader(body))
request.Header.Add("Content-Type", "application/x-www-form-urlencoded")
recorder := httptest.NewRecorder()
result := platformUpdate(recorder, request, nil)
c.Assert(result, gocheck.IsNil)
}
示例15: TestPlatformUpdateOnlyDisableFalse
func (s *PlatformSuite) TestPlatformUpdateOnlyDisableFalse(c *check.C) {
err := app.PlatformAdd(provision.PlatformOptions{Name: "wat", Args: nil, Output: nil})
c.Assert(err, check.IsNil)
dockerfileURL := ""
var buf bytes.Buffer
writer := multipart.NewWriter(&buf)
writer.WriteField("dockerfile", dockerfileURL)
writer.WriteField("disabled", "false")
writer.Close()
request, _ := http.NewRequest("PUT", "/platforms/wat?:name=wat", &buf)
request.Header.Add("Content-Type", writer.FormDataContentType())
recorder := httptest.NewRecorder()
token := createToken(c)
result := platformUpdate(recorder, request, token)
c.Assert(result, check.IsNil)
var msg io.SimpleJsonMessage
json.Unmarshal(recorder.Body.Bytes(), &msg)
c.Assert(msg.Error, check.Equals, "")
}