Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

51 line
1.8KB

  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/udhos/equalfile"
  8. )
  9. func TestUploadImage(t *testing.T) {
  10. SetupConfig()
  11. src := "media_for_test/640x480.jpg"
  12. mediaID := uploadImage(src)
  13. fmt.Printf("get MediaID: %s \n", mediaID)
  14. //200 OK
  15. //{"type":"image","media_id":"3wx8MSvsBYDubAqNi_QZSzNyCrOQ4eoOPslXzpOm6Kzv2Sfh2RngUFlDLfxcSdG2","created_at":1494140549}
  16. assert.NotEqual(t, mediaID, "", "MediaID should not be Empty")
  17. //download the media back using the media id
  18. filename, e := saveMedia2File(mediaID)
  19. log.Println("saved :" + filename)
  20. AssertEqual(t, e, nil, "mediaID should be saved without any error")
  21. //make sure two files are the same
  22. cmp := equalfile.New(nil, equalfile.Options{}) // compare using single mode
  23. equal, err := cmp.CompareFile(src, filename)
  24. AssertEqual(t, err, nil, "file should be equal ")
  25. AssertEqual(t, equal, true, "file should be equal ")
  26. }
  27. func TestUploadVideo(t *testing.T) {
  28. SetupConfig()
  29. src := "media_for_test/video.mp4"
  30. mediaID := uploadVideo(src)
  31. fmt.Printf("get MediaID: %s \n", mediaID)
  32. //200 OK
  33. //{"type":"image","media_id":"3wx8MSvsBYDubAqNi_QZSzNyCrOQ4eoOPslXzpOm6Kzv2Sfh2RngUFlDLfxcSdG2","created_at":1494140549}
  34. assert.NotEqual(t, mediaID, "", "MediaID should not be Empty")
  35. //download the media back using the media id
  36. filename, e := saveMedia2File(mediaID) // this isi a json with video link, we should download it and compare it.
  37. log.Println("saved :" + filename)
  38. AssertEqual(t, e, nil, "mediaID should be saved without any error")
  39. //make sure two files are the same
  40. cmp := equalfile.New(nil, equalfile.Options{}) // compare using single mode
  41. equal, err := cmp.CompareFile(src, filename)
  42. AssertEqual(t, err, nil, "file should be equal ")
  43. AssertEqual(t, equal, true, "file should be equal ")
  44. }