Add feature testing

This commit is contained in:
guanguans 2021-01-12 15:02:21 +08:00
parent c9d9bc5125
commit 50b81aaf8a
3 changed files with 38 additions and 1 deletions

1
.gitignore vendored
View File

@ -20,3 +20,4 @@
.DS_Store .DS_Store
.history/ .history/
tests.go tests.go
coverage.xml

View File

@ -76,7 +76,7 @@ func main() {
## Testing ## Testing
``` bash ``` bash
$ make ... $ go test
``` ```
## Changelog ## Changelog

36
feature_test.go Normal file
View File

@ -0,0 +1,36 @@
package idvalidator
import "testing"
// go test -v -cover -coverprofile=cover.out
// go tool cover -func=cover.out
// go tool cover -html=cover.out
func TestFeature(t *testing.T) {
isValid1 := IsValid(FakeId())
if !isValid1 {
t.Errorf("`isValid1` must be true.")
}
isValid2 := IsValid(FakeRequireId(true, "江苏省", "200001", 1))
if !isValid2 {
t.Errorf("`isValid2` must be true.")
}
_, err1 := GetInfo(FakeRequireId(true, "江苏省", "200001", 1))
if err1 != nil {
t.Errorf("`err1` must be nil.")
}
_, err2 := GetInfo(FakeRequireId(true, "江苏省", "200001", 1))
if err2 != nil {
t.Errorf("`err2` must be nil.")
}
upgradedId, err3 := UpgradeId("610104620927690")
if err3 != nil {
t.Errorf("`err3` must be nil.")
}
if len(upgradedId) != 18 {
t.Errorf("`upgradedId` length must be 18.:%d", len(upgradedId))
}
}