-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvalidator_test.go
36 lines (33 loc) · 943 Bytes
/
validator_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package magic
import (
"testing"
"io/ioutil"
"github.com/samcrosoft/magic/types"
"path/filepath"
)
// this will test the png file and it should pass
func TestPngData(t *testing.T){
sImagePath := "./corpus/image/png-sample.png"
if oBytes, err := ioutil.ReadFile(sImagePath); err == nil{
oType := types.PNGType{}
if bValid, oErr := IsBytesContentAValidType(oBytes, oType); bValid == false{
if oErr != nil{
t.Error("Image Has Less Than The Required Header Bytes")
}
}
}
}
// this will test the jpeg file
func TestJpegData(t *testing.T){
sImagePath := "./corpus/image/jpeg-sample.jpg"
sImagePath,_ = filepath.Abs(sImagePath)
if oBytes, err := ioutil.ReadFile(sImagePath); err == nil{
if bValid, oErr := IsBytesContentAValidType(oBytes, &types.JPEGType{}); bValid == false{
if oErr != nil{
t.Error("Image Has Less Than The Required Header Bytes")
}else{
t.Error("Image Is Not A Jpeg File")
}
}
}
}