add main test

This commit is contained in:
2022-01-07 21:47:28 +00:00
parent b6670cc921
commit ec14e26e83

30
main_test.go Normal file
View File

@@ -0,0 +1,30 @@
package main
import (
"testing"
"github.com/ryanehamil/lookupip/src/ipapi"
"github.com/ryanehamil/lookupip/src/utils"
)
// TestBuildURL
// Tests that the buildURL function returns a correct URL
func TestBuildURL(t *testing.T) {
var tests = []struct {
input string
want string
explain string
}{
{"nothing", "any ip address", "Valid Return"},
}
for _, test := range tests {
// Use the IP-API to lookup anything
got := ipapi.Lookup(ip, properties).String()
// use regex to check if got is a valid ipv4 address
if !utils.CheckValidIP(got) {
t.Errorf("ipapi.Lookup returned %s using input %s, want %s", got, test.input, test.want)
}
}
}