|
- package main
-
- import (
- "fmt"
- "log"
- "testing"
- "time"
-
- "github.com/stretchr/testify/assert"
- "github.com/udhos/equalfile"
- )
-
- func TestUploadImage(t *testing.T) {
-
- src := "media_for_test/640x480.jpg"
- mediaID := uploadImage(src)
- fmt.Printf("get MediaID: %s \n", mediaID)
- //200 OK
- //{"type":"image","media_id":"3wx8MSvsBYDubAqNi_QZSzNyCrOQ4eoOPslXzpOm6Kzv2Sfh2RngUFlDLfxcSdG2","created_at":1494140549}
- assert.NotEqual(t, mediaID, "", "MediaID should not be Empty")
-
- //download the media back using the media id
- filename, e := saveMedia2File(mediaID)
- log.Println("saved :" + filename)
- AssertEqual(t, e, nil, "mediaID should be saved without any error")
- //make sure two files are the same
- cmp := equalfile.New(nil, equalfile.Options{}) // compare using single mode
- equal, err := cmp.CompareFile(src, filename)
- AssertEqual(t, err, nil, "file should be equal ")
- AssertEqual(t, equal, true, "file should be equal ")
- }
-
- func TestUploadVideo(t *testing.T) {
-
- src := "media_for_test/video.mp4"
- mediaID := uploadVideo(src)
- fmt.Printf("get MediaID: %s \n", mediaID)
- //200 OK
- //{"type":"image","media_id":"3wx8MSvsBYDubAqNi_QZSzNyCrOQ4eoOPslXzpOm6Kzv2Sfh2RngUFlDLfxcSdG2","created_at":1494140549}
- assert.NotEqual(t, mediaID, "", "MediaID should not be Empty")
-
- //wait for a while for the video to be procssed
- time.Sleep(3 * time.Second)
-
- //download the media back using the media id
- filename, e := saveMedia2File(mediaID) // this is a json with video link, we should download it and compare it.
-
- //
- log.Println("saved :" + filename)
- AssertEqual(t, e, nil, "mediaID should be saved without any error")
- //make sure two files are the same
- cmp := equalfile.New(nil, equalfile.Options{}) // compare using single mode
- equal, err := cmp.CompareFile(src, filename)
- AssertEqual(t, err, nil, "error ro compare file should be nil ")
- AssertEqual(t, equal, true, "video file should be equal ")
- }
-
- func TestUploadVoice(t *testing.T) {
-
- src := "media_for_test/example.amr"
- mediaID := uploadVoice(src)
- log.Println(mediaID)
- }
-
- func TestUploadThumb(t *testing.T) {
-
- src := "media_for_test/music-thumb.jpg"
- mediaID := uploadThumb(src)
- log.Println(mediaID)
-
- //download the media back using the media id
- filename, e := saveMedia2File(mediaID)
- log.Println("saved :" + filename)
- AssertEqual(t, e, nil, "mediaID should be saved without any error")
- //make sure two files are the same
- cmp := equalfile.New(nil, equalfile.Options{}) // compare using single mode
- equal, err := cmp.CompareFile(src, filename)
- AssertEqual(t, err, nil, "file should be equal ")
- AssertEqual(t, equal, true, "file should be equal ")
-
- }
|