Skip to content

Commit

Permalink
Removing test changes for now
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusgomes28 committed Oct 20, 2024
1 parent 3a5fe07 commit 005e394
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 49 deletions.
28 changes: 21 additions & 7 deletions tests/admin_app_tests/endpoint_tests/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions tests/admin_app_tests/endpoint_tests/page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
14 changes: 4 additions & 10 deletions tests/admin_app_tests/endpoint_tests/posts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand Down
15 changes: 6 additions & 9 deletions tests/app_tests/app_settings/app_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -61,21 +60,19 @@ 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",
DatabaseName: "test_database_name",
WebserverPort: "99999",
AdminPort: "99998",
DatabasePort: "666",
Shortcodes: []common.Shortcode{},
}

bytes, err := toml.Marshal(missing_database_address)
Expand Down
2 changes: 0 additions & 2 deletions tests/app_tests/endpoint_tests/posts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
3 changes: 1 addition & 2 deletions tests/system_tests/admin_app/endpoint_tests/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions tests/system_tests/admin_app/endpoint_tests/post_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand Down
20 changes: 5 additions & 15 deletions urchin_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

0 comments on commit 005e394

Please sign in to comment.