--- /dev/null
+/*
+==================================================================================
+Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+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.
+==================================================================================
+*/
+package mme_mocks
+
+import (
+ "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/core"
+ "github.com/stretchr/testify/mock"
+)
+
+type DbMgrMock struct {
+ mock.Mock
+ core.DBMgr
+}
+
+func (d *DbMgrMock) CreateBucket(bucketName string) (err error) {
+ args := d.Called(bucketName)
+ return args.Error(0)
+}
+
+func (d *DbMgrMock) UploadFile(dataBytes []byte, file_name string, bucketName string) error {
+ args := d.Called()
+ // If error is passed, return the error
+ if _, ok := args.Get(0).(error); ok {
+ return args.Get(0).(error)
+ }
+
+ return nil
+}
+
+func (d *DbMgrMock) ListBucket(bucketObjPostfix string) ([]core.Bucket, error) {
+ args := d.Called()
+ return args.Get(0).([]core.Bucket), args.Error(1)
+}
--- /dev/null
+/*
+==================================================================================
+Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+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.
+==================================================================================
+*/
+package mme_mocks
+
+import (
+ "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/db"
+ "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/models"
+ "github.com/stretchr/testify/mock"
+)
+
+type IDBMock struct {
+ mock.Mock
+ db.IDB
+}
+
+func (i *IDBMock) Create(modelInfo models.ModelRelatedInformation) error {
+ args := i.Called(modelInfo)
+ return args.Error(0)
+}
+
+func (i *IDBMock) GetByID(id string) (*models.ModelRelatedInformation, error) {
+ return nil, nil
+}
+
+func (i *IDBMock) GetAll() ([]models.ModelRelatedInformation, error) {
+ args := i.Called()
+ if _, ok := args.Get(1).(error); !ok {
+ return args.Get(0).([]models.ModelRelatedInformation), nil
+ } else {
+ var emptyModelInfo []models.ModelRelatedInformation
+ return emptyModelInfo, args.Error(1)
+ }
+}
+
+func (i *IDBMock) Update(modelInfo models.ModelRelatedInformation) error {
+ return nil
+}
+
+func (i *IDBMock) Delete(id string) (int64, error) {
+ return 1, nil
+}
+
+func (i *IDBMock) GetModelInfoByName(modelName string) ([]models.ModelRelatedInformation, error) {
+ args := i.Called()
+ if _, ok := args.Get(1).(error); !ok {
+ return args.Get(0).([]models.ModelRelatedInformation), nil
+ } else {
+ var emptyModelInfo []models.ModelRelatedInformation
+ return emptyModelInfo, args.Error(1)
+ }
+}
+
+func (i *IDBMock) GetModelInfoByNameAndVer(modelName string, modelVersion string) (*models.ModelRelatedInformation, error) {
+ args := i.Called()
+
+ if _, ok := args.Get(1).(error); !ok {
+ return args.Get(0).(*models.ModelRelatedInformation), nil
+ } else {
+ var emptyModelInfo *models.ModelRelatedInformation
+ return emptyModelInfo, args.Error(1)
+ }
+}
"testing"
"gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/apis"
- "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/core"
- "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/db"
+ "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/apis_test/mme_mocks"
"gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/logging"
"gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/models"
"gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/routers"
}
}`
-type dbMgrMock struct {
- mock.Mock
- core.DBMgr
-}
-
-func (d *dbMgrMock) CreateBucket(bucketName string) (err error) {
- args := d.Called(bucketName)
- return args.Error(0)
-}
-
-func (d *dbMgrMock) UploadFile(dataBytes []byte, file_name string, bucketName string) {
-}
-
-func (d *dbMgrMock) ListBucket(bucketObjPostfix string) ([]core.Bucket, error) {
- args := d.Called()
- return args.Get(0).([]core.Bucket), args.Error(1)
-}
-
-type iDBMock struct {
- mock.Mock
- db.IDB
-}
-
-func (i *iDBMock) Create(modelInfo models.ModelRelatedInformation) error {
- args := i.Called(modelInfo)
- return args.Error(0)
-}
-func (i *iDBMock) GetByID(id string) (*models.ModelRelatedInformation, error) {
- return nil, nil
-}
-func (i *iDBMock) GetAll() ([]models.ModelRelatedInformation, error) {
- args := i.Called()
- if _, ok := args.Get(1).(error); !ok {
- return args.Get(0).([]models.ModelRelatedInformation), nil
- } else {
- var emptyModelInfo []models.ModelRelatedInformation
- return emptyModelInfo, args.Error(1)
- }
-}
-func (i *iDBMock) Update(modelInfo models.ModelRelatedInformation) error {
- return nil
-}
-func (i *iDBMock) Delete(id string) (int64, error) {
- return 1, nil
-}
-
-func (i *iDBMock) GetModelInfoByName(modelName string) ([]models.ModelRelatedInformation, error) {
- args := i.Called()
- if _, ok := args.Get(1).(error); !ok {
- return args.Get(0).([]models.ModelRelatedInformation), nil
- } else {
- var emptyModelInfo []models.ModelRelatedInformation
- return emptyModelInfo, args.Error(1)
- }
-}
-
-func (i *iDBMock) GetModelInfoByNameAndVer(modelName string, modelVersion string) (*models.ModelRelatedInformation, error) {
- args := i.Called()
-
- if _, ok := args.Get(1).(error); !ok {
- return args.Get(0).(*models.ModelRelatedInformation), nil
- } else {
- var emptyModelInfo *models.ModelRelatedInformation
- return emptyModelInfo, args.Error(1)
- }
-}
-
func TestRegisterModel(t *testing.T) {
os.Setenv("LOG_FILE_NAME", "testing")
- iDBMockInst := new(iDBMock)
+ iDBMockInst := new(mme_mocks.IDBMock)
iDBMockInst.On("Create", mock.Anything).Return(nil)
handler := apis.NewMmeApiHandler(nil, iDBMockInst)
router := routers.InitRouter(handler)
func TestRegisterModelFailInvalidJson(t *testing.T) {
os.Setenv("LOG_FILE_NAME", "testing")
- iDBMockInst := new(iDBMock)
+ iDBMockInst := new(mme_mocks.IDBMock)
handler := apis.NewMmeApiHandler(nil, iDBMockInst)
router := routers.InitRouter(handler)
w := httptest.NewRecorder()
func TestRegisterModelFailInvalidRequest(t *testing.T) {
os.Setenv("LOG_FILE_NAME", "testing")
- iDBMockInst := new(iDBMock)
+ iDBMockInst := new(mme_mocks.IDBMock)
handler := apis.NewMmeApiHandler(nil, iDBMockInst)
router := routers.InitRouter(handler)
w := httptest.NewRecorder()
func TestRegisterModelFailCreateDuplicateModel(t *testing.T) {
os.Setenv("LOG_FILE_NAME", "testing")
- iDBMockInst := new(iDBMock)
+ iDBMockInst := new(mme_mocks.IDBMock)
iDBMockInst.On("Create", mock.Anything).Return(&pq.Error{Code: pgerrcode.UniqueViolation})
handler := apis.NewMmeApiHandler(nil, iDBMockInst)
router := routers.InitRouter(handler)
func TestRegisterModelFailCreate(t *testing.T) {
os.Setenv("LOG_FILE_NAME", "testing")
- iDBMockInst := new(iDBMock)
+ iDBMockInst := new(mme_mocks.IDBMock)
iDBMockInst.On("Create", mock.Anything).Return(&pq.Error{Code: pgerrcode.SQLClientUnableToEstablishSQLConnection})
handler := apis.NewMmeApiHandler(nil, iDBMockInst)
router := routers.InitRouter(handler)
func TestWhenSuccessGetModelInfoList(t *testing.T) {
os.Setenv("LOG_FILE_NAME", "testing")
- iDBmockInst := new(iDBMock)
+ iDBmockInst := new(mme_mocks.IDBMock)
iDBmockInst.On("GetAll").Return([]models.ModelRelatedInformation{
{
Id: "1234",
func TestWhenFailGetModelInfoList(t *testing.T) {
os.Setenv("LOG_FILE_NAME", "testing")
- iDBmockInst2 := new(iDBMock)
+ iDBmockInst2 := new(mme_mocks.IDBMock)
iDBmockInst2.On("GetAll").Return([]models.ModelRelatedInformation{}, fmt.Errorf("db not available"))
handler := apis.NewMmeApiHandler(nil, iDBmockInst2)
func TestGetModelInfoParamsInvalid(t *testing.T) {
os.Setenv("LOG_FILE_NAME", "testing")
- iDBMockInst := new(iDBMock)
+ iDBMockInst := new(mme_mocks.IDBMock)
handler := apis.NewMmeApiHandler(nil, iDBMockInst)
router := routers.InitRouter(handler)
responseRecorder := httptest.NewRecorder()
func TestGetModelInfoByNameSuccess(t *testing.T) {
os.Setenv("LOG_FILE_NAME", "testing")
- iDBMockInst := new(iDBMock)
+ iDBMockInst := new(mme_mocks.IDBMock)
iDBMockInst.On("GetModelInfoByName").Return([]models.ModelRelatedInformation{
{
Id: "1234",
func TestGetModelInfoByNameFail(t *testing.T) {
os.Setenv("LOG_FILE_NAME", "testing")
- iDBMockInst := new(iDBMock)
+ iDBMockInst := new(mme_mocks.IDBMock)
iDBMockInst.On("GetModelInfoByName").Return([]models.ModelRelatedInformation{}, fmt.Errorf("db not available"))
handler := apis.NewMmeApiHandler(nil, iDBMockInst)
func TestGetModelInfoByNameAndVersionSuccess(t *testing.T) {
os.Setenv("LOG_FILE_NAME", "testing")
- iDBMockInst := new(iDBMock)
+ iDBMockInst := new(mme_mocks.IDBMock)
modelInfo := models.ModelRelatedInformation{
Id: "1234",
func TestGetModelInfoByNameAndVersionFail(t *testing.T) {
os.Setenv("LOG_FILE_NAME", "testing")
- iDBMockInst := new(iDBMock)
+ iDBMockInst := new(mme_mocks.IDBMock)
modelInfo := models.ModelRelatedInformation{}
iDBMockInst.On("GetModelInfoByNameAndVer").Return(&modelInfo, fmt.Errorf("db not available"))