Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

56 Zeilen
1.9KB

  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. //wait for a while for the video to be procssed
  36. //time.Sleep(3000 * time.Millisecond)
  37. //download the media back using the media id
  38. filename, e := saveMedia2File(mediaID) // this is a json with video link, we should download it and compare it.
  39. //
  40. log.Println("saved :" + filename)
  41. AssertEqual(t, e, nil, "mediaID should be saved without any error")
  42. //make sure two files are the same
  43. cmp := equalfile.New(nil, equalfile.Options{}) // compare using single mode
  44. equal, err := cmp.CompareFile(src, filename)
  45. AssertEqual(t, err, nil, "error ro compare file should be nil ")
  46. AssertEqual(t, equal, true, "video file should be equal ")
  47. }