From 0fabde251024391bc4f9ff9e86dbca8016dc4173 Mon Sep 17 00:00:00 2001 From: wanfeng Date: Thu, 25 Sep 2025 09:22:29 +0800 Subject: [PATCH] Add address formatting unit test cases --- graffiti/service/address_test.go | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 graffiti/service/address_test.go diff --git a/graffiti/service/address_test.go b/graffiti/service/address_test.go new file mode 100644 index 0000000..9eb9161 --- /dev/null +++ b/graffiti/service/address_test.go @@ -0,0 +1,36 @@ +package service + +import ( + "testing" +) + +func TestServiceAddress(t *testing.T) { + _, err := AddressFromString("aaa") + if err == nil { + t.Fatalf("should return an error") + } + + sa, err := AddressFromString("8080") + if err != nil { + t.Errorf("should not return an error: %s", err) + } + if (sa.Addr != "[::1]" && sa.Addr != "127.0.0.1" && sa.Addr != "localhost") || sa.Port != 8080 { + t.Errorf("expected not found, got: %s", sa) + } + + sa, err = AddressFromString("0.0.0.0:8080") + if err != nil { + t.Errorf("should not return an error: %s", err) + } + if sa.Addr != "0.0.0.0" || sa.Port != 8080 { + t.Errorf("expected not found, got: %s", sa) + } + + sa, err = AddressFromString("skydive.network:8080") + if err != nil { + t.Errorf("should not return an error: %s", err) + } + if sa.Addr != "skydive.network" { + t.Errorf("Expected domain, got: %s", sa.Addr) + } +} -- Gitee