utility: Added tests.

pull/3/head
Dustin Oprea 2018-05-04 05:09:27 -04:00
parent a9c16ec9ef
commit b46d138022
1 changed files with 53 additions and 0 deletions

View File

@ -2,8 +2,61 @@ package exif
import (
"testing"
"os"
"io/ioutil"
"github.com/dsoprea/go-logging"
)
func TestDumpBytes(t *testing.T) {
f, err := ioutil.TempFile(os.TempDir(), "utilitytest")
log.PanicIf(err)
defer os.Remove(f.Name())
originalStdout := os.Stdout
os.Stdout = f
DumpBytes([]byte { 0x11, 0x22 })
os.Stdout = originalStdout
_, err = f.Seek(0, 0)
log.PanicIf(err)
content, err := ioutil.ReadAll(f)
log.PanicIf(err)
if string(content) != "DUMP: 11 22 \n" {
t.Fatalf("content not correct: [%s]", string(content))
}
}
func TestDumpBytesClause(t *testing.T) {
f, err := ioutil.TempFile(os.TempDir(), "utilitytest")
log.PanicIf(err)
defer os.Remove(f.Name())
originalStdout := os.Stdout
os.Stdout = f
DumpBytesClause([]byte { 0x11, 0x22 })
os.Stdout = originalStdout
_, err = f.Seek(0, 0)
log.PanicIf(err)
content, err := ioutil.ReadAll(f)
log.PanicIf(err)
if string(content) != "DUMP: []byte { 0x11, 0x22 }\n" {
t.Fatalf("content not correct: [%s]", string(content))
}
}
func TestDumpBytesToString(t *testing.T) {
s := DumpBytesToString([]byte { 0x12, 0x34, 0x56 })