From: naman.gupta Date: Tue, 6 Dec 2022 14:59:18 +0000 (+0530) Subject: UT for SetPolicyInstanceStatus X-Git-Tag: 3.0.0~12 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;ds=inline;h=be066665846fd9b7840f13a9cd13da62841d47ea;hp=53c0270966d180078358c23fa5e5aa465455c317;p=ric-plt%2Fa1.git UT for SetPolicyInstanceStatus UT for SetPolicyInstanceStatus Signed-off-by: naman.gupta Change-Id: Ibd6e6490d51f7516eac1d2aae01da38a73682bbd --- diff --git a/a1-go/Dockerfile b/a1-go/Dockerfile index 9db6bd6..1a4cfec 100644 --- a/a1-go/Dockerfile +++ b/a1-go/Dockerfile @@ -77,6 +77,7 @@ RUN GO111MODULE=on GO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o /go # Run unit tests RUN GO111MODULE=on GO_ENABLED=0 GOOS=linux go test -p 1 -cover ./pkg/resthooks/ RUN GO111MODULE=on GO_ENABLED=0 GOOS=linux go test -p 1 -cover ./pkg/a1/ +RUN GO111MODULE=on GO_ENABLED=0 GOOS=linux go test -p 1 -cover ./pkg/policyManager RUN gofmt -l $(find cmd/ pkg/ -name '*.go' -not -name '*_test.go') diff --git a/a1-go/pkg/policy/policyManager_test.go b/a1-go/pkg/policy/policyManager_test.go new file mode 100644 index 0000000..7714b81 --- /dev/null +++ b/a1-go/pkg/policy/policyManager_test.go @@ -0,0 +1,56 @@ +package policy + +import ( + "os" + "strconv" + "testing" + + "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/a1" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" +) + +type SdlMock struct { + mock.Mock +} + +var sdlInst *SdlMock +var pm *PolicyManager + +func TestMain(m *testing.M) { + sdlInst = new(SdlMock) + a1.Init() + pm = createPolicyManager(sdlInst) + code := m.Run() + os.Exit(code) +} +func TestSetPolicyInstance(t *testing.T) { + var policyTypeId int + policyTypeId = 20001 + var policyInstanceID int + policyInstanceID = 123456 + var status string + status = "OK" + instancehandlerKey := a1HandlerPrefix + strconv.FormatInt(20001, 10) + "." + strconv.FormatInt(int64(policyInstanceID), 10) + instancearr := []interface{}{instancehandlerKey, status} + sdlInst.On("Set", "A1m_ns", instancehandlerKey, instancearr).Return(nil) + errresp := pm.SetPolicyInstanceStatus(policyTypeId, policyInstanceID, status) + assert.NoError(t, errresp) + + sdlInst.AssertExpectations(t) +} + +func (s *SdlMock) Set(ns string, pairs ...interface{}) error { + args := s.MethodCalled("Set", ns, pairs) + return args.Error(0) +} + +func (s *SdlMock) Get(ns string, keys []string) (map[string]interface{}, error) { + a1.Logger.Error("Get Called ") + return map[string]interface{}{}, nil +} + +func (s *SdlMock) GetAll(ns string) ([]string, error) { + args := s.MethodCalled("GetAll", ns) + return args.Get(0).([]string), nil +}