test(api): add basic tests for generateJSON()

This commit is contained in:
Guanran Wang 2024-10-26 17:40:43 +08:00
parent 36fe7b5e15
commit 7500d04c65
Signed by: nyancat
GPG key ID: 91F97D9ED12639CF

21
api/main_test.go Normal file
View file

@ -0,0 +1,21 @@
package main
import (
"testing"
)
func TestInvalidIP(t *testing.T) {
_, err := generateJSON("foo")
errwant := "invalid IP"
if err.Error() != errwant {
t.Fatalf(`generateJSON("foo") == "%v", wants "%s"`, err, errwant)
}
}
func TestInaccessibleIP(t *testing.T) {
_, err := generateJSON("0.0.0.0")
errwant := "unspecified IP"
if err.Error() != errwant {
t.Fatalf(`generateJSON("0.0.0.0") == "%v", wants "%s"`, err, errwant)
}
}