Skip to content

Commit

Permalink
fix new test
Browse files Browse the repository at this point in the history
  • Loading branch information
aspacca committed May 30, 2021
1 parent 2db6465 commit a7c8c75
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions webapp/backend/pkg/web/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,27 +291,33 @@ func TestSendTestNotificationRoute_ScriptFailure(t *testing.T) {
}

func TestSendTestNotificationRoute_ScriptSuccess(t *testing.T) {
//setup
parentPath, _ := ioutil.TempDir("", "")
defer os.RemoveAll(parentPath)
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
fakeConfig := mock_config.NewMockInterface(mockCtrl)
fakeConfig.EXPECT().GetString("web.database.location").AnyTimes().Return(path.Join(parentPath, "scrutiny_test.db"))
fakeConfig.EXPECT().GetString("web.src.frontend.path").AnyTimes().Return(parentPath)
fakeConfig.EXPECT().GetStringSlice("notify.urls").AnyTimes().Return([]string{"script:///usr/bin/env"})
ae := web.AppEngine{
Config: fakeConfig,
}
router := ae.Setup(logrus.New())
for _, basePath := range basePathTestCases {
t.Run(fmt.Sprintf(`with basePath "%s"`, basePath), func(tt *testing.T) {
//setup
//setup
parentPath, _ := ioutil.TempDir("", "")
defer os.RemoveAll(parentPath)
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
fakeConfig := mock_config.NewMockInterface(mockCtrl)
fakeConfig.EXPECT().GetString("web.database.location").AnyTimes().Return(path.Join(parentPath, "scrutiny_test.db"))
fakeConfig.EXPECT().GetString("web.src.frontend.path").AnyTimes().Return(parentPath)
fakeConfig.EXPECT().GetString("web.src.backend.basepath").Return(basePath).AnyTimes()
fakeConfig.EXPECT().GetStringSlice("notify.urls").AnyTimes().Return([]string{"script:///usr/bin/env"})
ae := web.AppEngine{
Config: fakeConfig,
}
router := ae.Setup(logrus.New())

//test
wr := httptest.NewRecorder()
req, _ := http.NewRequest("POST", "/api/health/notify", strings.NewReader("{}"))
router.ServeHTTP(wr, req)
//test
wr := httptest.NewRecorder()
req, _ := http.NewRequest("POST", basePath + "/api/health/notify", strings.NewReader("{}"))
router.ServeHTTP(wr, req)

//assert
require.Equal(t, 200, wr.Code)
//assert
require.Equal(t, 200, wr.Code)
})
}
}

func TestSendTestNotificationRoute_ShoutrrrFailure(t *testing.T) {
Expand Down

0 comments on commit a7c8c75

Please sign in to comment.