"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"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/mock"
"github.com/jackc/pgerrcode"
"github.com/lib/pq"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/mock"
)
var registerModelBody = `{
assert.Equal(t, 409, w.Code)
body, _ := io.ReadAll(w.Body)
- assert.Equal(t, "{\"status\":409,\"title\":\"model name and version combination already present\",\"detail\":\"The request json is not correct as\"}", string(body))
+ assert.Equal(t, "{\"status\":409,\"title\":\"Conflict\",\"detail\":\"model name and version combination already present\"}", string(body))
}
func TestRegisterModelFailCreate(t *testing.T) {
assert.Equal(t, 500, w.Code)
body, _ := io.ReadAll(w.Body)
- assert.Equal(t, "{\"status\":500,\"title\":\"Bad Request\",\"detail\":\"The request json is not correct as\"}", string(body))
+ assert.Equal(t, "{\"status\":500,\"title\":\"Internal Server Error\",\"detail\":\"Database error: pq: \"}", string(body))
}
func TestWhenSuccessGetModelInfoList(t *testing.T) {
- // Setting ENV
os.Setenv("LOG_FILE_NAME", "testing")
- // Setting Mock
iDBmockInst := new(iDBMock)
iDBmockInst.On("GetAll").Return([]models.ModelRelatedInformation{
{
}
func TestWhenFailGetModelInfoList(t *testing.T) {
- // Setting ENV
os.Setenv("LOG_FILE_NAME", "testing")
- // Setting Mock
iDBmockInst2 := new(iDBMock)
iDBmockInst2.On("GetAll").Return([]models.ModelRelatedInformation{}, fmt.Errorf("db not available"))
}
func TestGetModelInfoParamsInvalid(t *testing.T) {
- // Setting ENV
os.Setenv("LOG_FILE_NAME", "testing")
- // Setting Mock
iDBMockInst := new(iDBMock)
-
handler := apis.NewMmeApiHandler(nil, iDBMockInst)
router := routers.InitRouter(handler)
responseRecorder := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/ai-ml-model-discovery/v1/models?model-me=qoe2", nil)
-
router.ServeHTTP(responseRecorder, req)
body, _ := io.ReadAll(responseRecorder.Body)
fmt.Println(responseRecorder)
+
assert.Equal(t, 400, responseRecorder.Code)
assert.Equal(t, `{"status":400,"title":"Bad Request","detail":"Only allowed params are modelname and modelversion"}`, string(body))
}
func TestGetModelInfoByNameSuccess(t *testing.T) {
- // Setting ENV
os.Setenv("LOG_FILE_NAME", "testing")
- // Setting Mock
iDBMockInst := new(iDBMock)
iDBMockInst.On("GetModelInfoByName").Return([]models.ModelRelatedInformation{
{
},
},
}, nil)
+
handler := apis.NewMmeApiHandler(nil, iDBMockInst)
router := routers.InitRouter(handler)
responseRecorder := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/ai-ml-model-discovery/v1/models?model-name=qoe1", nil)
-
router.ServeHTTP(responseRecorder, req)
response := responseRecorder.Result()
}
func TestGetModelInfoByNameFail(t *testing.T) {
- // Setting ENV
os.Setenv("LOG_FILE_NAME", "testing")
- // Setting Mock
iDBMockInst := new(iDBMock)
iDBMockInst.On("GetModelInfoByName").Return([]models.ModelRelatedInformation{}, fmt.Errorf("db not available"))
}
func TestGetModelInfoByNameAndVersionSuccess(t *testing.T) {
- // Setting ENV
os.Setenv("LOG_FILE_NAME", "testing")
iDBMockInst := new(iDBMock)
responseRecorder := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/ai-ml-model-discovery/v1/models?model-name=test&model-version=v1.0", nil)
-
router.ServeHTTP(responseRecorder, req)
response := responseRecorder.Result()
}
func TestGetModelInfoByNameAndVersionFail(t *testing.T) {
- // Setting ENV
os.Setenv("LOG_FILE_NAME", "testing")
iDBMockInst := new(iDBMock)
responseRecorder := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/ai-ml-model-discovery/v1/models?model-name=test&model-version=v1.0", nil)
-
router.ServeHTTP(responseRecorder, req)
response := responseRecorder.Result()
- fmt.Println(responseRecorder)
body, _ := io.ReadAll(response.Body)
+ var modelInfos []models.ModelRelatedInformation
+ json.Unmarshal(body, &modelInfos)
+
assert.Equal(t, 500, responseRecorder.Code)
assert.Equal(t, `{"status":500,"title":"Internal Server Error","detail":"Can't fetch all the models due to , db not available"}`, string(body))
}