utils_test.go 801 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package multipartestutils_test
  2. import (
  3. "io/ioutil"
  4. "testing"
  5. "github.com/qor5/web/multipartestutils"
  6. )
  7. func TestCreateMultipartFileHeader(t *testing.T) {
  8. f := multipartestutils.CreateMultipartFileHeader("test.txt", []byte("hello"))
  9. if f.Filename != "test.txt" {
  10. t.Error(f.Filename)
  11. }
  12. file, err := f.Open()
  13. if err != nil {
  14. t.Fatal(err)
  15. }
  16. content, err := ioutil.ReadAll(file)
  17. if err != nil {
  18. t.Fatal(err)
  19. }
  20. if string(content) != "hello" {
  21. t.Error(string(content))
  22. }
  23. }
  24. func TestBuilder_BuildEventFuncRequest(t *testing.T) {
  25. r := multipartestutils.NewMultipartBuilder().
  26. EventFunc("hello").
  27. Query("id", "123").
  28. Query("model", "Customer").
  29. BuildEventFuncRequest()
  30. if r.URL.String() != "/?__execute_event__=hello&id=123&model=Customer" {
  31. t.Error(r.URL.String())
  32. }
  33. }