提交 944ab6e1 编写于 作者: S shamsher31

Add test case to check image type

上级 14528524
...@@ -3,11 +3,12 @@ package imgtype // import "github.com/shamsher31/goimgtype" ...@@ -3,11 +3,12 @@ package imgtype // import "github.com/shamsher31/goimgtype"
import ( import (
"errors" "errors"
"github.com/shamsher31/goimgext"
"log" "log"
"net/http" "net/http"
"os" "os"
"strings" "strings"
"github.com/shamsher31/goimgext"
) )
// Get returns the type of Image // Get returns the type of Image
......
package imgtype package imgtype
import "testing" import (
"strings"
"testing"
"github.com/shamsher31/goimgext"
)
func TestGet(t *testing.T) { func TestGet(t *testing.T) {
imgType, err := Get("golang.png")
if err != nil {
t.Fatal(err)
}
if isImgTypeFromExt(imgType) == false {
t.Fatal("Not a valid image type")
}
}
func isImgTypeFromExt(p string) bool {
ext := imgext.Get()
for i := 0; i < len(ext); i++ {
if strings.Contains(ext[i], p[6:len(p)]) {
return true
}
}
return false
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册