X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Ftypes_test.go;h=424021b89f3c31a4e4f10ff05676146a419efef8;hb=d708a43badb0742684b22866977f14cc1c03a1ba;hp=eade2aadbe8a724addc9394ed6ddcd626e512927;hpb=8b979ab74153ad8c120743e0f6d868baedcb3b32;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/types_test.go b/pkg/control/types_test.go index eade2aa..424021b 100644 --- a/pkg/control/types_test.go +++ b/pkg/control/types_test.go @@ -20,11 +20,14 @@ package control import ( + "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststub" "testing" ) func TestRmrEndpoint(t *testing.T) { + tent := teststub.NewTestWrapper("TestRmrEndpoint") + testEp := func(t *testing.T, val string, expect *RmrEndpoint) { res := NewRmrEndpoint(val) @@ -32,14 +35,14 @@ func TestRmrEndpoint(t *testing.T) { return } if res == nil { - testError(t, "Endpoint elems for value %s expected addr %s port %d got nil", val, expect.GetAddr(), expect.GetPort()) + tent.TestError(t, "Endpoint elems for value %s expected addr %s port %d got nil", val, expect.GetAddr(), expect.GetPort()) return } if expect.GetAddr() != res.GetAddr() || expect.GetPort() != res.GetPort() { - testError(t, "Endpoint elems for value %s expected addr %s port %d got addr %s port %d", val, expect.GetAddr(), expect.GetPort(), res.GetAddr(), res.GetPort()) + tent.TestError(t, "Endpoint elems for value %s expected addr %s port %d got addr %s port %d", val, expect.GetAddr(), expect.GetPort(), res.GetAddr(), res.GetPort()) } if expect.String() != res.String() { - testError(t, "Endpoint string for value %s expected %s got %s", val, expect.String(), res.Get()) + tent.TestError(t, "Endpoint string for value %s expected %s got %s", val, expect.String(), res.String()) } } @@ -52,20 +55,74 @@ func TestRmrEndpoint(t *testing.T) { testEp(t, "", nil) } -func TestAction(t *testing.T) { +func TestRmrEndpointList(t *testing.T) { - testActionString := func(t *testing.T, val int, str string) { - if Action(val).String() != str { - testError(t, "String for value %d expected %s got %s", val, str, Action(val).String()) - } + tent := teststub.NewTestWrapper("TestRmrEndpointList") + + epl := &RmrEndpointList{} + + // Simple add / has / delete + if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false { + tent.TestError(t, "RmrEndpointList: 8080 add failed") + } + if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == true { + tent.TestError(t, "RmrEndpointList: 8080 duplicate add success") + } + if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false { + tent.TestError(t, "RmrEndpointList: 8081 add failed") + } + if epl.HasEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false { + tent.TestError(t, "RmrEndpointList: 8081 has failed") + } + if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false { + tent.TestError(t, "RmrEndpointList: 8081 del failed") + } + if epl.HasEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == true { + tent.TestError(t, "RmrEndpointList: 8081 has non existing success") + } + if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == true { + tent.TestError(t, "RmrEndpointList: 8081 del non existing success") + } + if epl.DelEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false { + tent.TestError(t, "RmrEndpointList: 8080 del failed") + } + + // list delete + if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false { + tent.TestError(t, "RmrEndpointList: 8080 add failed") + } + if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false { + tent.TestError(t, "RmrEndpointList: 8081 add failed") + } + if epl.AddEndpoint(NewRmrEndpoint("127.0.0.1:8082")) == false { + tent.TestError(t, "RmrEndpointList: 8082 add failed") + } + + epl2 := &RmrEndpointList{} + if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:9080")) == false { + tent.TestError(t, "RmrEndpointList: othlist add 9080 failed") + } + + if epl.DelEndpoints(epl2) == true { + tent.TestError(t, "RmrEndpointList: delete list not existing successs") + } + + if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8080")) == false { + tent.TestError(t, "RmrEndpointList: othlist add 8080 failed") + } + if epl.DelEndpoints(epl2) == false { + tent.TestError(t, "RmrEndpointList: delete list 8080,9080 failed") + } + + if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8081")) == false { + tent.TestError(t, "RmrEndpointList: othlist add 8081 failed") + } + if epl2.AddEndpoint(NewRmrEndpoint("127.0.0.1:8082")) == false { + tent.TestError(t, "RmrEndpointList: othlist add 8082 failed") + } + + if epl.DelEndpoints(epl2) == false { + tent.TestError(t, "RmrEndpointList: delete list 8080,8081,8082,9080 failed") } - testActionString(t, 0, "CREATE") - testActionString(t, 1, "MERGE") - testActionString(t, 2, "NONE") - testActionString(t, 3, "DELETE") - testActionString(t, 5, "UNKNOWN") - testActionString(t, 6, "UNKNOWN") - testActionString(t, 7, "UNKNOWN") - testActionString(t, 10, "UNKNOWN") }