package main import ( "fmt" "log" "testing" "github.com/stretchr/testify/assert" "github.com/udhos/equalfile" ) func TestUploadImage(t *testing.T) { SetupConfig() 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) { SetupConfig() 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(3000 * time.Millisecond) //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 ") }