Add tests for newly added features 11/11211/2
authorYouhwan Seol <yh.seol@samsung.com>
Wed, 22 Feb 2023 05:47:21 +0000 (14:47 +0900)
committerYouhwan Seol <yh.seol@samsung.com>
Thu, 25 May 2023 01:22:02 +0000 (10:22 +0900)
Change-Id: I66e0a87da017cb1fd3bea175ee3e7359ef2852a8
Signed-off-by: Youhwan Seol <yh.seol@samsung.com>
pkg/api/v1/info/info_test.go [new file with mode: 0644]
pkg/api/v1/revision/revision_test.go [new file with mode: 0644]
pkg/api/v1/status/status_test.go [new file with mode: 0644]

diff --git a/pkg/api/v1/info/info_test.go b/pkg/api/v1/info/info_test.go
new file mode 100644 (file)
index 0000000..7318fc7
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+==================================================================================
+
+Copyright (c) 2023 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 info
+
+import (
+       "errors"
+       "go/types"
+       "net/http"
+       "net/http/httptest"
+       . "net/url"
+       "testing"
+
+       "github.com/gin-gonic/gin"
+       "github.com/golang/mock/gomock"
+
+       "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/api/commons/url"
+
+       controllermock "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/controller/v1/adapter/mock"
+)
+
+const (
+       testName = "test_name"
+)
+
+func TestReceivedInfoRequest_ExpectCalledInfoController(t *testing.T) {
+       ctrl := gomock.NewController(t)
+       defer ctrl.Finish()
+
+       mockobj := controllermock.NewMockCommand(ctrl)
+       gomock.InOrder(
+               mockobj.EXPECT().Info(testName),
+       )
+
+       ipsAdapter = mockobj
+
+       w := httptest.NewRecorder()
+
+       param := Values{}
+       param.Set("name", testName)
+
+       r, err := http.NewRequest("GET", url.V1()+url.IPS()+url.Info(), nil)
+       if err != nil {
+               t.Errorf("http.NewRequest return Error : %s", err.Error())
+       }
+       r.Header.Set("Content-Type", "application/json")
+       r.URL.RawQuery = param.Encode()
+
+       c, _ := gin.CreateTestContext(w)
+       c.Request = r
+
+       status := Executor{}
+       status.Get(c)
+}
+
+func TestNegativeReceivedInfoRequestWithoutParam_ExpectInfoControllerReturnError(t *testing.T) {
+       ctrl := gomock.NewController(t)
+       defer ctrl.Finish()
+
+       mockobj := controllermock.NewMockCommand(ctrl)
+       gomock.InOrder(
+               mockobj.EXPECT().Info("").Return(types.Info{}, errors.New("test error")),
+       )
+
+       ipsAdapter = mockobj
+
+       w := httptest.NewRecorder()
+
+       r, err := http.NewRequest("GET", url.V1()+url.IPS()+url.Info(), nil)
+       if err != nil {
+               t.Errorf("http.NewRequest return Error : %s", err.Error())
+       }
+       r.Header.Set("Content-Type", "application/json")
+
+       c, _ := gin.CreateTestContext(w)
+       c.Request = r
+
+       status := Executor{}
+       status.Get(c)
+}
diff --git a/pkg/api/v1/revision/revision_test.go b/pkg/api/v1/revision/revision_test.go
new file mode 100644 (file)
index 0000000..b97dfeb
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+==================================================================================
+
+Copyright (c) 2023 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 revision
+
+import (
+       "errors"
+       "net/http"
+       "net/http/httptest"
+       . "net/url"
+       "testing"
+
+       "github.com/gin-gonic/gin"
+       "github.com/golang/mock/gomock"
+
+       "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/api/commons/url"
+       "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/commons/types"
+
+       controllermock "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/controller/v1/adapter/mock"
+)
+
+const (
+       testName = "test_name"
+)
+
+func TestReceivedRevisionRequest_ExpectCalledRevisionController(t *testing.T) {
+       ctrl := gomock.NewController(t)
+       defer ctrl.Finish()
+
+       mockobj := controllermock.NewMockCommand(ctrl)
+       gomock.InOrder(
+               mockobj.EXPECT().Revision(testName),
+       )
+
+       ipsAdapter = mockobj
+
+       w := httptest.NewRecorder()
+
+       param := Values{}
+       param.Set("name", testName)
+
+       r, err := http.NewRequest("GET", url.V1()+url.IPS()+url.Revision(), nil)
+       if err != nil {
+               t.Errorf("http.NewRequest return Error : %s", err.Error())
+       }
+       r.Header.Set("Content-Type", "application/json")
+       r.URL.RawQuery = param.Encode()
+
+       c, _ := gin.CreateTestContext(w)
+       c.Request = r
+
+       revision := Executor{}
+       revision.Get(c)
+}
+
+func TestNegativeReceivedRevisionRequestWithoutParam_ExpectRevisionControllerReturnError(t *testing.T) {
+       ctrl := gomock.NewController(t)
+       defer ctrl.Finish()
+
+       mockobj := controllermock.NewMockCommand(ctrl)
+       gomock.InOrder(
+               mockobj.EXPECT().Revision("").Return(types.Revision{}, errors.New("test error")),
+       )
+
+       ipsAdapter = mockobj
+
+       w := httptest.NewRecorder()
+
+       r, err := http.NewRequest("GET", url.V1()+url.IPS()+url.Revision(), nil)
+       if err != nil {
+               t.Errorf("http.NewRequest return Error : %s", err.Error())
+       }
+       r.Header.Set("Content-Type", "application/json")
+
+       c, _ := gin.CreateTestContext(w)
+       c.Request = r
+
+       revision := Executor{}
+       revision.Get(c)
+}
diff --git a/pkg/api/v1/status/status_test.go b/pkg/api/v1/status/status_test.go
new file mode 100644 (file)
index 0000000..333d6a7
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+==================================================================================
+
+Copyright (c) 2023 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 status
+
+import (
+       "errors"
+       "net/http"
+       "net/http/httptest"
+       . "net/url"
+       "testing"
+
+       "github.com/gin-gonic/gin"
+       "github.com/golang/mock/gomock"
+
+       "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/api/commons/url"
+       "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/commons/types"
+
+       controllermock "gerrit.o-ran-sc.org/r/aiml-fw/aihp/ips/kserve-adapter/pkg/controller/v1/adapter/mock"
+)
+
+const (
+       testName = "test_name"
+)
+
+func TestReceivedStatusRequest_ExpectCalledStatusController(t *testing.T) {
+       ctrl := gomock.NewController(t)
+       defer ctrl.Finish()
+
+       mockobj := controllermock.NewMockCommand(ctrl)
+       gomock.InOrder(
+               mockobj.EXPECT().Status(testName),
+       )
+
+       ipsAdapter = mockobj
+
+       w := httptest.NewRecorder()
+
+       param := Values{}
+       param.Set("name", testName)
+
+       r, err := http.NewRequest("GET", url.V1()+url.IPS()+url.Status(), nil)
+       if err != nil {
+               t.Errorf("http.NewRequest return Error : %s", err.Error())
+       }
+       r.Header.Set("Content-Type", "application/json")
+       r.URL.RawQuery = param.Encode()
+
+       c, _ := gin.CreateTestContext(w)
+       c.Request = r
+
+       status := Executor{}
+       status.Get(c)
+}
+
+func TestNegativeReceivedStatusRequest_ExpectStatusControllerReturnError(t *testing.T) {
+       ctrl := gomock.NewController(t)
+       defer ctrl.Finish()
+
+       mockobj := controllermock.NewMockCommand(ctrl)
+       gomock.InOrder(
+               mockobj.EXPECT().Status("").Return(types.Status{}, errors.New("test error")),
+       )
+
+       ipsAdapter = mockobj
+
+       w := httptest.NewRecorder()
+
+       r, err := http.NewRequest("GET", url.V1()+url.IPS()+url.Status(), nil)
+       if err != nil {
+               t.Errorf("http.NewRequest return Error : %s", err.Error())
+       }
+       r.Header.Set("Content-Type", "application/json")
+
+       c, _ := gin.CreateTestContext(w)
+       c.Request = r
+
+       status := Executor{}
+       status.Get(c)
+}