X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=a1-go%2Fpkg%2Fresthooks%2Fresthooks_test.go;h=ac3dc25ddf63e54cb4f17c87b99282ee54bab1af;hb=9f4fe4d725c9ad77ea1c2ab565ce5759e8a932a6;hp=8c6b59ad846520549773beeb2e7942b7a6463f53;hpb=159ddb7dd65305d364743d4728af35f84a6e1557;p=ric-plt%2Fa1.git diff --git a/a1-go/pkg/resthooks/resthooks_test.go b/a1-go/pkg/resthooks/resthooks_test.go index 8c6b59a..ac3dc25 100644 --- a/a1-go/pkg/resthooks/resthooks_test.go +++ b/a1-go/pkg/resthooks/resthooks_test.go @@ -51,13 +51,24 @@ func TestMain(m *testing.M) { "a1.policy_type.20000", "a1.policy_inst_metadata.1006001.qos", }, nil) - RMRclient = new(RMRClientMock) + rmrSenderInst = new(RmrSenderMock) a1.Init() - rh = createResthook(sdlInst, RMRclient) + rh = createResthook(sdlInst, rmrSenderInst) code := m.Run() os.Exit(code) } +func TestHealth(t *testing.T) { + resp := rh.GetA1Health() + if resp == true { + a1.Logger.Debug("A1 is healthy ") + assert.Equal(t, true, resp) + } else { + a1.Logger.Debug("A1 is unhealthy") + assert.Equal(t, false, resp) + } +} + func TestGetAllPolicyType(t *testing.T) { resp := rh.GetAllPolicyType() assert.Equal(t, 2, len(resp)) @@ -219,8 +230,9 @@ func TestGetPolicyInstanceStatus(t *testing.T) { keys[0] = instancekey sdlInst.On("Get", a1MediatorNs, keys[:]).Return(httpBody) - resp := rh.GetPolicyInstanceStatus(policyTypeId, policyInstanceID) + resp, errresp := rh.GetPolicyInstanceStatus(policyTypeId, policyInstanceID) + assert.Nil(t, errresp) assert.NotNil(t, resp) sdlInst.AssertExpectations(t) } @@ -313,6 +325,31 @@ func TestDataDelivery(t *testing.T) { sdlInst.AssertExpectations(t) } +func TestGetMetaData(t *testing.T) { + var policyTypeId models.PolicyTypeID + policyTypeId = 20001 + var policyInstanceID models.PolicyInstanceID + policyInstanceID = "123456" + instanceMetadataKey := a1InstanceMetadataPrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + string(policyInstanceID) + a1.Logger.Debug("key : %+v", instanceMetadataKey) + + var keys [1]string + keys[0] = instanceMetadataKey + + policySchemaString := `{ + "created_at":"2022-11-02 10:30:20", + "instance_status":"NOT IN EFFECT" + }` + + sdlInst.On("Get", a1MediatorNs, keys[:]).Return(map[string]interface{}{instanceMetadataKey: policySchemaString}, nil) + + resp, errresp := rh.getMetaData(policyTypeId, policyInstanceID) + + assert.Nil(t, errresp) + assert.NotNil(t, resp) + sdlInst.AssertExpectations(t) +} + type SdlMock struct { mock.Mock }