53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package geoloc
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestGetCountry(t *testing.T) {
|
|
type args struct {
|
|
input string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *IPInfo
|
|
}{
|
|
{"GBR Test", args{input: "826"}, nil},
|
|
{"USA upper Test", args{input: "USA"}, nil},
|
|
{"Nothing Test", args{input: ""}, nil},
|
|
{"Åland Islands Test", args{input: "Aland Islands"}, nil},
|
|
{"Bahreïn Test", args{input: "Bahreïn"}, nil},
|
|
{"Bahreïn Test (FR)", args{input: "Bahrein"}, nil},
|
|
{"USA uppter Test", args{input: "US"}, GetCountry("US")},
|
|
{"USA lower Test", args{input: "us"}, GetCountry("US")},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := GetCountry(tt.args.input); !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("GetCountry() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetIPInfo(t *testing.T) {
|
|
type args struct {
|
|
input string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want uint
|
|
}{
|
|
{"IP address Test", args{input: "1.1.1.1"}, 16843008},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got, err := GetIPInfo(tt.args.input); err != nil || !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("GetIPInfo() - %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|