From 3cb6c96115d841b8fb459841b1f4eff4c049ed79 Mon Sep 17 00:00:00 2001 From: Patrick Marschallek Date: Fri, 9 Sep 2016 10:54:57 +0200 Subject: [PATCH 1/3] this gives you the possibility to use different key for the files. --- frisby.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/frisby.go b/frisby.go index 84169fa..6ba967f 100644 --- a/frisby.go +++ b/frisby.go @@ -11,6 +11,8 @@ import ( var Global global_data +const defaultFileKey = "file" + type Frisby struct { Name string Url string @@ -191,12 +193,15 @@ func (F *Frisby) SetJson(json interface{}) *Frisby { } // Add a file to the Form data for the coming request -func (F *Frisby) AddFile(filename string) *Frisby { +func (F *Frisby) AddFile(key, filename string) *Frisby { file, err := os.Open(filename) if err != nil { F.Errs = append(F.Errs, err) } else { - fileField := request.FileField{"file", filename, file} + if len(key) == 0 { + key = defaultFileKey + } + fileField := request.FileField{key, filename, file} F.Req.Files = append(F.Req.Files, fileField) } return F From 83b2e7439b2d41a264a97506e451b9dd226c1a1b Mon Sep 17 00:00:00 2001 From: Patrick Marschallek Date: Fri, 9 Sep 2016 11:33:00 +0200 Subject: [PATCH 2/3] changed the filename which is send to the server. --- frisby.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frisby.go b/frisby.go index 6ba967f..50376c6 100644 --- a/frisby.go +++ b/frisby.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" "os" + "path/filepath" "github.com/mozillazg/request" ) @@ -201,7 +202,10 @@ func (F *Frisby) AddFile(key, filename string) *Frisby { if len(key) == 0 { key = defaultFileKey } - fileField := request.FileField{key, filename, file} + fileField := request.FileField{ + FieldName: key, + FileName: filepath.Base(filename), + File: file} F.Req.Files = append(F.Req.Files, fileField) } return F From ad2208ad4030e34790c8e4746e1ac9a02c430b0e Mon Sep 17 00:00:00 2001 From: Patrick Marschallek Date: Tue, 13 Sep 2016 11:15:57 +0200 Subject: [PATCH 3/3] adding a general function for assertions. --- expect.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/expect.go b/expect.go index b61f74e..7a6a2d9 100644 --- a/expect.go +++ b/expect.go @@ -9,6 +9,18 @@ import ( "github.com/bitly/go-simplejson" ) +// ExpectFunc function type used as argument to Expect() +type ExpectFunc func(F *Frisby) (bool, string) + +// Expect Checks according to the given function, which allows you to describe any kind of assertion. +func (F *Frisby) Expect(foo ExpectFunc) *Frisby { + Global.NumAsserts++ + if ok, err_str := foo(F); !ok { + F.AddError(err_str) + } + return F +} + // Checks the response status code func (F *Frisby) ExpectStatus(code int) *Frisby { Global.NumAsserts++