Merge "NONRTRIC-946: Servicemanager - add Kong data plane and control plane"
[nonrtric/plt/sme.git] / servicemanager / internal / publishservice / publishservice_test.go
index 7bec335..c42cba7 100644 (file)
@@ -45,17 +45,17 @@ import (
        publishapi "oransc.org/nonrtric/servicemanager/internal/publishserviceapi"
 
        "oransc.org/nonrtric/capifcore"
-       "oransc.org/nonrtric/servicemanager/mockkong"
+       mockKong "oransc.org/nonrtric/servicemanager/mockkong"
 )
 
 var (
-       eServiceManager          *echo.Echo
-       eCapifWeb                *echo.Echo
-       eKong                    *echo.Echo
-       mockConfigReader         *envreader.MockConfigReader
+       eServiceManager      *echo.Echo
+       eCapifWeb            *echo.Echo
+       eKong                *echo.Echo
+       mockConfigReader     *envreader.MockConfigReader
        serviceManagerServer *httptest.Server
-       capifServer              *httptest.Server
-       mockKongServer           *httptest.Server
+       capifServer          *httptest.Server
+       mockKongServer       *httptest.Server
 )
 
 func TestMain(m *testing.M) {
@@ -108,9 +108,10 @@ func setupTest() error {
                MockedConfig: map[string]string{
                        "KONG_DOMAIN":             "kong",
                        "KONG_PROTOCOL":           "http",
-                       "KONG_IPV4":               mockKongHost,
-                       "KONG_DATA_PLANE_PORT":    "32080",
+                       "KONG_CONTROL_PLANE_IPV4": mockKongHost,
                        "KONG_CONTROL_PLANE_PORT": mockKongControlPlanePort,
+                       "KONG_DATA_PLANE_IPV4":    "10.101.1.101",
+                       "KONG_DATA_PLANE_PORT":    "32080",
                        "CAPIF_PROTOCOL":          "http",
                        "CAPIF_IPV4":              capifHost,
                        "CAPIF_PORT":              capifPort,
@@ -168,7 +169,7 @@ func getProvider() provapi.APIProviderEnrolmentDetails {
        }
 }
 
-func capifCleanUp()  {
+func capifCleanUp() {
        t := new(testing.T) // Create a new testing.T instance for capifCleanUp
 
        // Delete the invoker
@@ -364,13 +365,13 @@ func TestPublishUnpublishService(t *testing.T) {
        resultServiceIpv4 := *interfaceDescription.Ipv4Addr
        resultServicePort := *interfaceDescription.Port
 
-       kongIPv4 := common29122.Ipv4Addr(myEnv["KONG_IPV4"])
+       kongDataPlaneIPv4 := common29122.Ipv4Addr(myEnv["KONG_DATA_PLANE_IPV4"])
        kongDataPlanePort := common29122.Port(myPorts["KONG_DATA_PLANE_PORT"])
 
-       assert.NotEmpty(t, kongIPv4, "KONG_IPV4 is required in .env file for unit testing")
+       assert.NotEmpty(t, kongDataPlaneIPv4, "KONG_DATA_PLANE_IPV4 is required in .env file for unit testing")
        assert.NotZero(t, kongDataPlanePort, "KONG_DATA_PLANE_PORT is required in .env file for unit testing")
 
-       assert.Equal(t, kongIPv4, resultServiceIpv4)
+       assert.Equal(t, kongDataPlaneIPv4, resultServiceIpv4)
        assert.Equal(t, kongDataPlanePort, resultServicePort)
 
        // Publish the same service again should result in Forbidden
@@ -406,9 +407,10 @@ func registerHandlers(e *echo.Echo, myEnv map[string]string, myPorts map[string]
        capifPort := common29122.Port(myPorts["CAPIF_PORT"])
        kongDomain := myEnv["KONG_DOMAIN"]
        kongProtocol := myEnv["KONG_PROTOCOL"]
-       kongIPv4 := common29122.Ipv4Addr(myEnv["KONG_IPV4"])
-       kongDataPlanePort := common29122.Port(myPorts["KONG_DATA_PLANE_PORT"])
+       kongControlPlaneIPv4 := common29122.Ipv4Addr(myEnv["KONG_CONTROL_PLANE_IPV4"])
        kongControlPlanePort := common29122.Port(myPorts["KONG_CONTROL_PLANE_PORT"])
+       kongDataPlaneIPv4 := common29122.Ipv4Addr(myEnv["KONG_DATA_PLANE_IPV4"])
+       kongDataPlanePort := common29122.Port(myPorts["KONG_DATA_PLANE_PORT"])
 
        // Register ProviderManagement
        providerManagerSwagger, err := provapi.GetSwagger()
@@ -433,7 +435,11 @@ func registerHandlers(e *echo.Echo, myEnv map[string]string, myPorts map[string]
 
        publishServiceSwagger.Servers = nil
 
-       ps := NewPublishService(kongDomain, kongProtocol, kongIPv4, kongDataPlanePort, kongControlPlanePort, capifProtocol, capifIPv4, capifPort)
+       ps := NewPublishService(
+               kongDomain, kongProtocol,
+               kongControlPlaneIPv4, kongControlPlanePort,
+               kongDataPlaneIPv4, kongDataPlanePort,
+               capifProtocol, capifIPv4, capifPort)
 
        group = e.Group("/published-apis/v1")
        group.Use(echomiddleware.Logger())