diff options
Diffstat (limited to 'pkg/kafkacomm/handler/pdp_message_handler_test.go')
-rw-r--r-- | pkg/kafkacomm/handler/pdp_message_handler_test.go | 61 |
1 files changed, 55 insertions, 6 deletions
diff --git a/pkg/kafkacomm/handler/pdp_message_handler_test.go b/pkg/kafkacomm/handler/pdp_message_handler_test.go index 3764c9e..8ba1e0e 100644 --- a/pkg/kafkacomm/handler/pdp_message_handler_test.go +++ b/pkg/kafkacomm/handler/pdp_message_handler_test.go @@ -1,6 +1,6 @@ // - // ========================LICENSE_START================================= -// Copyright (C) 2024: Deutsche Telecom +// Copyright (C) 2024: Deutsche Telekom // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +// SPDX-License-Identifier: Apache-2.0 // ========================LICENSE_END=================================== // @@ -20,8 +21,13 @@ package handler import ( "github.com/stretchr/testify/assert" + "policy-opa-pdp/consts" "policy-opa-pdp/pkg/pdpattributes" "testing" + // "context" + // "encoding/json" + // "errors" + // "policy-opa-pdp/pkg/kafkacomm/mocks" ) /* @@ -36,7 +42,7 @@ func TestCheckIfMessageIsForOpaPdp_Check(t *testing.T) { opapdpMessage.Name = "opa-3a318049-813f-4172-b4d3-7d4f466e5b80" opapdpMessage.MessageType = "PDP_STATUS" - opapdpMessage.PdpGroup = "defaultGroup" + opapdpMessage.PdpGroup = "opaGroup" opapdpMessage.PdpSubgroup = "opa" assert.False(t, checkIfMessageIsForOpaPdp(opapdpMessage), "Its a valid Opa Pdp Message") @@ -55,7 +61,7 @@ func TestCheckIfMessageIsForOpaPdp_Check_Message_Name(t *testing.T) { opapdpMessage.Name = "" opapdpMessage.MessageType = "PDP_STATUS" - opapdpMessage.PdpGroup = "defaultGroup" + opapdpMessage.PdpGroup = "opaGroup" opapdpMessage.PdpSubgroup = "opa" assert.False(t, checkIfMessageIsForOpaPdp(opapdpMessage), "Not a valid Opa Pdp Message") @@ -74,7 +80,7 @@ func TestCheckIfMessageIsForOpaPdp_Check_PdpGroup(t *testing.T) { opapdpMessage.Name = "" opapdpMessage.MessageType = "PDP_STATUS" - opapdpMessage.PdpGroup = "defaultGroup" + opapdpMessage.PdpGroup = "opaGroup" opapdpMessage.PdpSubgroup = "opa" pdpattributes.PdpSubgroup = "opa" @@ -113,7 +119,7 @@ func TestCheckIfMessageIsForOpaPdp_Check_PdpSubgroup(t *testing.T) { opapdpMessage.Name = "" opapdpMessage.MessageType = "PDP_STATUS" - opapdpMessage.PdpGroup = "defaultGroup" + opapdpMessage.PdpGroup = "opaGroup" opapdpMessage.PdpSubgroup = "opa" pdpattributes.PdpSubgroup = "opa" @@ -133,10 +139,53 @@ func TestCheckIfMessageIsForOpaPdp_Check_IncorrectPdpSubgroup(t *testing.T) { opapdpMessage.Name = "" opapdpMessage.MessageType = "PDP_STATUS" - opapdpMessage.PdpGroup = "defaultGroup" + opapdpMessage.PdpGroup = "opaGroup" opapdpMessage.PdpSubgroup = "o" pdpattributes.PdpSubgroup = "opa" assert.False(t, checkIfMessageIsForOpaPdp(opapdpMessage), "Not a valid Opa Pdp Message") } + +func TestCheckIfMessageIsForOpaPdp_EmptyPdpSubgroupAndGroup(t *testing.T) { + var opapdpMessage OpaPdpMessage + opapdpMessage.Name = "" + opapdpMessage.MessageType = "PDP_STATUS" + opapdpMessage.PdpGroup = "" + opapdpMessage.PdpSubgroup = "" + + assert.False(t, checkIfMessageIsForOpaPdp(opapdpMessage), "Message should be invalid when PdpGroup and PdpSubgroup are empty") +} + +func TestCheckIfMessageIsForOpaPdp_ValidBroadcastMessage(t *testing.T) { + var opapdpMessage OpaPdpMessage + opapdpMessage.Name = "" + opapdpMessage.MessageType = "PDP_UPDATE" + opapdpMessage.PdpGroup = "opaGroup" + opapdpMessage.PdpSubgroup = "" + + pdpattributes.PdpSubgroup = "opa" + consts.PdpGroup = "opaGroup" + + assert.True(t, checkIfMessageIsForOpaPdp(opapdpMessage), "Valid broadcast message should pass the check") +} + +func TestCheckIfMessageIsForOpaPdp_InvalidGroupMismatch(t *testing.T) { + var opapdpMessage OpaPdpMessage + opapdpMessage.Name = "" + opapdpMessage.MessageType = "PDP_STATUS" + opapdpMessage.PdpGroup = "wrongGroup" + opapdpMessage.PdpSubgroup = "" + + consts.PdpGroup = "opaGroup" + + assert.False(t, checkIfMessageIsForOpaPdp(opapdpMessage), "Message with mismatched PdpGroup should fail") +} + +// Test SetShutdownFlag and IsShutdown +func TestSetAndCheckShutdownFlag(t *testing.T) { + assert.False(t, IsShutdown(), "Shutdown flag should be false initially") + + SetShutdownFlag() + assert.True(t, IsShutdown(), "Shutdown flag should be true after calling SetShutdownFlag") +} |