package main

import (
	"fmt"
	"testing"
)

func TestGetFileSize(t *testing.T) {

	var fileSize = map[string]int{
		"640x480.jpg":             50668,
		"3640x3480.jpg":           785190,
		"video.mp4":               75520,
		"example.amr":             56486,
		"wechat_incoming_msg.mp3": 14639,
	}
	for k, v := range fileSize {
		size, _ := getFileSize("media_for_test/" + k)
		msg := fmt.Sprintf("%s should have size %d, not %d", k, v, size)
		AssertEqual(t, size, int64(v), msg)
	}
}

func TestGetMimeType(t *testing.T) {
	var fileMime = map[string]string{
		"640x480.jpg":             "image/jpeg",
		"3640x3480.jpg":           "image/jpeg",
		"video.mp4":               "video/mp4",
		"example.amr":             "audio/amr",
		"wechat_incoming_msg.mp3": "audio/mpeg",
	}
	for k, v := range fileMime {
		mime, _, _ := getFileMime("media_for_test/" + k)
		msg := fmt.Sprintf("%s should be %s, not %s", k, v, mime)
		AssertEqual(t, mime, v, msg)
	}
}

func TestIsMP3(t *testing.T) {
	var mp3 = map[string]bool{
		"640x480.jpg":             false,
		"3640x3480.jpg":           false,
		"video.mp4":               false,
		"example.amr":             false,
		"wechat_incoming_msg.mp3": true,
	}
	for k, v := range mp3 {
		r := isMP3("media_for_test/" + k)
		msg := fmt.Sprintf("%s is mp3 = %t, not %t", k, v, r)
		AssertEqual(t, v, r, msg)
	}
}

func TestIsAMR(t *testing.T) {
	var amr = map[string]bool{
		"640x480.jpg":             false,
		"3640x3480.jpg":           false,
		"video.mp4":               false,
		"example.amr":             true,
		"wechat_incoming_msg.mp3": false,
	}
	for k, v := range amr {
		r := isAmr("media_for_test/" + k)
		msg := fmt.Sprintf("%s AMR = %t, not %t", k, v, r)
		AssertEqual(t, v, r, msg)
	}
}

func TestIsMP4(t *testing.T) {
	var mp4 = map[string]bool{
		"640x480.jpg":             false,
		"3640x3480.jpg":           false,
		"video.mp4":               true,
		"example.amr":             false,
		"wechat_incoming_msg.mp3": false,
	}
	for k, v := range mp4 {
		r := isMP4("media_for_test/" + k)
		msg := fmt.Sprintf("%s MP4 = %t, not %t", k, v, r)
		AssertEqual(t, v, r, msg)
	}
}

func TestIsJPG(t *testing.T) {
	var mp4 = map[string]bool{
		"640x480.jpg":             true,
		"3640x3480.jpg":           true,
		"video.mp4":               false,
		"example.amr":             false,
		"wechat_incoming_msg.mp3": false,
	}
	for k, v := range mp4 {
		r := isJPG("media_for_test/" + k)
		msg := fmt.Sprintf("%s JPG = %t, not %t", k, v, r)
		AssertEqual(t, v, r, msg)
	}
}
