From 7500d04c6540274c38ac2fb0444c2a147ef99dba Mon Sep 17 00:00:00 2001 From: Guanran Wang Date: Sat, 26 Oct 2024 17:40:43 +0800 Subject: [PATCH] test(api): add basic tests for generateJSON() --- api/main_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 api/main_test.go diff --git a/api/main_test.go b/api/main_test.go new file mode 100644 index 0000000..b395be0 --- /dev/null +++ b/api/main_test.go @@ -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) + } +}