diff --git a/tests/admin_app_tests/endpoint_tests/images_test.go b/tests/admin_app_tests/endpoint_tests/images_test.go index 6a635b7..2158f5f 100644 --- a/tests/admin_app_tests/endpoint_tests/images_test.go +++ b/tests/admin_app_tests/endpoint_tests/images_test.go @@ -17,7 +17,6 @@ import ( "github.com/matheusgomes28/urchin/tests/mocks" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - lua "github.com/yuin/gopher-lua" ) type imageResponse struct { @@ -27,7 +26,7 @@ type imageResponse struct { func TestPostImage(t *testing.T) { database_mock := mocks.DatabaseMock{} - r := admin_app.SetupRoutes(app_settings, database_mock, make(map[string]*lua.LState)) + r := admin_app.SetupRoutes(app_settings, database_mock) w := httptest.NewRecorder() pr, pw := io.Pipe() @@ -59,7 +58,7 @@ func TestPostImage(t *testing.T) { func TestPostImageNotAnImageFile(t *testing.T) { database_mock := mocks.DatabaseMock{} - r := admin_app.SetupRoutes(app_settings, database_mock, make(map[string]*lua.LState)) + r := admin_app.SetupRoutes(app_settings, database_mock) w := httptest.NewRecorder() pr, pw := io.Pipe() @@ -86,7 +85,7 @@ func TestPostImageNotAnImageFile(t *testing.T) { func TestPostImageWrongFileContentType(t *testing.T) { database_mock := mocks.DatabaseMock{} - r := admin_app.SetupRoutes(app_settings, database_mock, make(map[string]*lua.LState)) + r := admin_app.SetupRoutes(app_settings, database_mock) w := httptest.NewRecorder() pr, pw := io.Pipe() @@ -112,10 +111,25 @@ func TestPostImageWrongFileContentType(t *testing.T) { assert.Equal(t, 400, w.Code) } +func TestGetImageNoDatabaseEntry(t *testing.T) { + database_mock := mocks.DatabaseMock{} + + r := admin_app.SetupRoutes(app_settings, database_mock) + + get_recorder := httptest.NewRecorder() + uuid, _ := uuid.New() + + uri := fmt.Sprintf("/images/%s", uuid.String()) + req, _ := http.NewRequest("GET", uri, bytes.NewBuffer([]byte{})) + r.ServeHTTP(get_recorder, req) + + assert.Equal(t, 404, get_recorder.Code) +} + func TestGetImageNoImageFile(t *testing.T) { database_mock := mocks.DatabaseMock{} - r := admin_app.SetupRoutes(app_settings, database_mock, make(map[string]*lua.LState)) + r := admin_app.SetupRoutes(app_settings, database_mock) get_recorder := httptest.NewRecorder() uuid, _ := uuid.New() @@ -130,7 +144,7 @@ func TestGetImageNoImageFile(t *testing.T) { func TestDeleteImage(t *testing.T) { database_mock := mocks.DatabaseMock{} - r := admin_app.SetupRoutes(app_settings, database_mock, make(map[string]*lua.LState)) + r := admin_app.SetupRoutes(app_settings, database_mock) post_recorder := httptest.NewRecorder() pr, pw := io.Pipe() @@ -174,7 +188,7 @@ func TestDeleteImage(t *testing.T) { func TestDeleteImageNoImageFile(t *testing.T) { database_mock := mocks.DatabaseMock{} - r := admin_app.SetupRoutes(app_settings, database_mock, make(map[string]*lua.LState)) + r := admin_app.SetupRoutes(app_settings, database_mock) delete_recorder := httptest.NewRecorder() uuid, _ := uuid.New() diff --git a/tests/admin_app_tests/endpoint_tests/page_test.go b/tests/admin_app_tests/endpoint_tests/page_test.go index b710658..dea682d 100644 --- a/tests/admin_app_tests/endpoint_tests/page_test.go +++ b/tests/admin_app_tests/endpoint_tests/page_test.go @@ -10,7 +10,6 @@ import ( admin_app "github.com/matheusgomes28/urchin/admin-app" "github.com/matheusgomes28/urchin/tests/mocks" "github.com/stretchr/testify/assert" - lua "github.com/yuin/gopher-lua" ) func TestAddPageHappyPath(t *testing.T) { @@ -26,7 +25,7 @@ func TestAddPageHappyPath(t *testing.T) { Link: "Link", } - router := admin_app.SetupRoutes(app_settings, databaseMock, make(map[string]*lua.LState)) + router := admin_app.SetupRoutes(app_settings, databaseMock) responseRecorder := httptest.NewRecorder() body, _ := json.Marshal(page_data) diff --git a/tests/admin_app_tests/endpoint_tests/posts_test.go b/tests/admin_app_tests/endpoint_tests/posts_test.go index 16f2429..15f4908 100644 --- a/tests/admin_app_tests/endpoint_tests/posts_test.go +++ b/tests/admin_app_tests/endpoint_tests/posts_test.go @@ -12,7 +12,6 @@ import ( "github.com/matheusgomes28/urchin/common" "github.com/matheusgomes28/urchin/tests/mocks" "github.com/stretchr/testify/assert" - lua "github.com/yuin/gopher-lua" ) var app_settings = common.AppSettings{ @@ -26,15 +25,10 @@ var app_settings = common.AppSettings{ } func TestPostPostSuccess(t *testing.T) { - - database_mock := mocks.DatabaseMock{} - r := admin_app.SetupRoutes(app_settings, database_mock, make(map[string]*lua.LState)) - w := httptest.NewRecorder() - - request := common.Pos{ - Title: "", - Excerpt: "", - Content: "", + databaseMock := mocks.DatabaseMock{ + AddPostHandler: func(string, string, string) (int, error) { + return 0, nil + }, } postData := admin_app.AddPostRequest{ diff --git a/tests/app_tests/app_settings/app_settings_test.go b/tests/app_tests/app_settings/app_settings_test.go index 187dbf9..480d188 100644 --- a/tests/app_tests/app_settings/app_settings_test.go +++ b/tests/app_tests/app_settings/app_settings_test.go @@ -45,7 +45,6 @@ func TestCorrectToml(t *testing.T) { {Name: "Contact", Href: "/contact", Title: "Contacts page"}, }, }, - Shortcodes: []common.Shortcode{}, } bytes, err := toml.Marshal(expected) assert.Nil(t, err) @@ -61,13 +60,12 @@ func TestCorrectToml(t *testing.T) { func TestMissingDatabaseAddress(t *testing.T) { missing_database_address := struct { - DatabaseUser string `toml:"database_user"` - DatabasePassword string `toml:"database_password"` - DatabaseName string `toml:"database_name"` - WebserverPort string `toml:"webserver_port"` - AdminPort string `toml:"admin_port"` - DatabasePort string `toml:"database_port"` - Shortcodes []Shortcode `toml:"shortcodes"` + DatabaseUser string `toml:"database_user"` + DatabasePassword string `toml:"database_password"` + DatabaseName string `toml:"database_name"` + WebserverPort string `toml:"webserver_port"` + AdminPort string `toml:"admin_port"` + DatabasePort string `toml:"database_port"` }{ DatabaseUser: "test_database_user", DatabasePassword: "test_database_password", @@ -75,7 +73,6 @@ func TestMissingDatabaseAddress(t *testing.T) { WebserverPort: "99999", AdminPort: "99998", DatabasePort: "666", - Shortcodes: []common.Shortcode{}, } bytes, err := toml.Marshal(missing_database_address) diff --git a/tests/app_tests/endpoint_tests/posts_test.go b/tests/app_tests/endpoint_tests/posts_test.go index 5a9cb6e..04316b6 100644 --- a/tests/app_tests/endpoint_tests/posts_test.go +++ b/tests/app_tests/endpoint_tests/posts_test.go @@ -96,8 +96,6 @@ func TestPostFailurePostDoesntExist(t *testing.T) { router.ServeHTTP(responseRecorder, request) - fmt.Printf("Value for the request: %d", responseRecorder.Code) - require.Equal(t, http.StatusNotFound, responseRecorder.Code) } diff --git a/tests/system_tests/admin_app/endpoint_tests/image_test.go b/tests/system_tests/admin_app/endpoint_tests/image_test.go index fb24681..84c3f46 100644 --- a/tests/system_tests/admin_app/endpoint_tests/image_test.go +++ b/tests/system_tests/admin_app/endpoint_tests/image_test.go @@ -12,7 +12,6 @@ import ( _ "github.com/go-sql-driver/mysql" "github.com/stretchr/testify/require" - lua "github.com/yuin/gopher-lua" admin_app "github.com/matheusgomes28/urchin/admin-app" "github.com/matheusgomes28/urchin/tests/helpers" @@ -56,7 +55,7 @@ func TestImageUpload(t *testing.T) { // Execute multiform request post_recorder := httptest.NewRecorder() - r := admin_app.SetupRoutes(app_settings, database, make(map[string]*lua.LState)) + r := admin_app.SetupRoutes(app_settings, database) require.Nil(t, err) req, _ := http.NewRequest("POST", "/images", pr) diff --git a/tests/system_tests/admin_app/endpoint_tests/post_test.go b/tests/system_tests/admin_app/endpoint_tests/post_test.go index ea2bdd3..b5ae28e 100644 --- a/tests/system_tests/admin_app/endpoint_tests/post_test.go +++ b/tests/system_tests/admin_app/endpoint_tests/post_test.go @@ -11,7 +11,6 @@ import ( _ "github.com/go-sql-driver/mysql" "github.com/stretchr/testify/require" - lua "github.com/yuin/gopher-lua" admin_app "github.com/matheusgomes28/urchin/admin-app" "github.com/matheusgomes28/urchin/tests/helpers" @@ -43,7 +42,7 @@ func TestPostExists(t *testing.T) { } w := httptest.NewRecorder() - r := admin_app.SetupRoutes(app_settings, database, make(map[string]*lua.LState)) + r := admin_app.SetupRoutes(app_settings, database) request_bytes, err := json.Marshal(add_post_request) require.Nil(t, err) req, _ := http.NewRequest("POST", "/posts", bytes.NewBuffer(request_bytes)) diff --git a/urchin_config.toml b/urchin_config.toml index 6e89007..96a1285 100644 --- a/urchin_config.toml +++ b/urchin_config.toml @@ -2,23 +2,23 @@ database_address = "localhost" # User to access datbaase -database_user = "root" +database_user = "urchin" # Password for the database user -database_password = "root" +database_password = "urchinpw" # port database_port = 3306 # name of database where urchin's # migrations was installed -database_name = "gocms" +database_name = "urchin" # port to run the webserver on -webserver_port = 8082 +webserver_port = 8080 # port to run the admin app on -admin_port = 8083 +admin_port = 8081 # Directory to use for storing uploaded images. image_dir = "./images" @@ -39,13 +39,3 @@ links = [ { name = "Images", href = "/images", title = "Images page" }, { name = "Contact", href = "/contact", title = "Contacts page" }, ] - -[[shortcodes]] -name = "img" -# must have function "HandleShortcode(arguments []string) -> string" -plugin = "plugins/image_shortcode.lua" - -[[shortcodes]] -name = "table" -# must have function "HandleShortcode(arguments []string) -> string" -plugin = "plugins/table_shortcode.lua"