fix new test

This commit is contained in:
Andrea Spacca
2020-11-11 09:18:03 +01:00
parent 2db6465639
commit a7c8c75a49
+26 -20
View File
@@ -291,27 +291,33 @@ func TestSendTestNotificationRoute_ScriptFailure(t *testing.T) {
} }
func TestSendTestNotificationRoute_ScriptSuccess(t *testing.T) { func TestSendTestNotificationRoute_ScriptSuccess(t *testing.T) {
//setup for _, basePath := range basePathTestCases {
parentPath, _ := ioutil.TempDir("", "") t.Run(fmt.Sprintf(`with basePath "%s"`, basePath), func(tt *testing.T) {
defer os.RemoveAll(parentPath) //setup
mockCtrl := gomock.NewController(t) //setup
defer mockCtrl.Finish() parentPath, _ := ioutil.TempDir("", "")
fakeConfig := mock_config.NewMockInterface(mockCtrl) defer os.RemoveAll(parentPath)
fakeConfig.EXPECT().GetString("web.database.location").AnyTimes().Return(path.Join(parentPath, "scrutiny_test.db")) mockCtrl := gomock.NewController(t)
fakeConfig.EXPECT().GetString("web.src.frontend.path").AnyTimes().Return(parentPath) defer mockCtrl.Finish()
fakeConfig.EXPECT().GetStringSlice("notify.urls").AnyTimes().Return([]string{"script:///usr/bin/env"}) fakeConfig := mock_config.NewMockInterface(mockCtrl)
ae := web.AppEngine{ fakeConfig.EXPECT().GetString("web.database.location").AnyTimes().Return(path.Join(parentPath, "scrutiny_test.db"))
Config: fakeConfig, 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", basePath + "/api/health/notify", strings.NewReader("{}"))
router.ServeHTTP(wr, req)
//assert
require.Equal(t, 200, wr.Code)
})
} }
router := ae.Setup(logrus.New())
//test
wr := httptest.NewRecorder()
req, _ := http.NewRequest("POST", "/api/health/notify", strings.NewReader("{}"))
router.ServeHTTP(wr, req)
//assert
require.Equal(t, 200, wr.Code)
} }
func TestSendTestNotificationRoute_ShoutrrrFailure(t *testing.T) { func TestSendTestNotificationRoute_ShoutrrrFailure(t *testing.T) {