mirror of https://github.com/rocboss/paopao-ce
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
878 B
45 lines
878 B
2 years ago
|
// Copyright 2023 ROC. All rights reserved.
|
||
2 years ago
|
// Use of this source code is governed by a MIT style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
2 years ago
|
package iploc_test
|
||
2 years ago
|
|
||
|
import (
|
||
2 years ago
|
. "github.com/onsi/ginkgo/v2"
|
||
|
. "github.com/onsi/gomega"
|
||
|
|
||
2 years ago
|
"github.com/rocboss/paopao-ce/pkg/utils/iploc"
|
||
2 years ago
|
)
|
||
|
|
||
2 years ago
|
var _ = Describe("Iploc", Ordered, func() {
|
||
|
type iplocCases []struct {
|
||
2 years ago
|
ip string
|
||
|
country string
|
||
|
city string
|
||
2 years ago
|
}
|
||
|
var samples iplocCases
|
||
|
|
||
|
BeforeAll(func() {
|
||
|
samples = iplocCases{
|
||
|
{
|
||
|
ip: "127.0.0.1",
|
||
|
country: "本机地址",
|
||
|
city: " CZ88.NET",
|
||
|
},
|
||
|
{
|
||
|
ip: "180.89.94.9",
|
||
|
country: "北京市",
|
||
|
city: "鹏博士宽带",
|
||
|
},
|
||
2 years ago
|
}
|
||
2 years ago
|
})
|
||
|
|
||
|
It("find country and city by ip", func() {
|
||
|
for _, t := range samples {
|
||
|
country, city := iploc.Find(t.ip)
|
||
|
Expect(country).To(Equal(t.country))
|
||
|
Expect(city).To(Equal(t.city))
|
||
2 years ago
|
}
|
||
2 years ago
|
})
|
||
|
})
|