WIP: Add server unit testing #73
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Blocks
#11 Add tests
luca0N/lanbassador
Reference
luca0N/lanbassador!73
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "dev_server_tests"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Create tests in the server project, as required by issue #11.
account.goapi.goconfig.gocrypto.godb.goenv.golib.gomain.gonet.gows.goSome testing will require mocks to simulate things like database connections, and WebSocket connections.
Some changes are needed in this file.
@ -0,0 +63,4 @@rows := sqlmock.NewRows([]string{"id"}).AddRow(id)// FIXME: make this a LIMIT 1!mock.ExpectQuery("SELECT id FROM users WHERE username = (.+);").WillReturnRows(rows)As the comment suggests, this (and the original source file from which this statement was based upon) need to be updated to include
LIMIT 1.@ -0,0 +77,4 @@// TODO: actually check the sessionToken in the queryrows := sqlmock.NewRows([]string{"user_id"}).AddRow(userId)mock.ExpectQuery(`SELECT user_id FROM sessions WHERE token = UNHEX(\(.+)\) LIMIT 1;`).WillReturnRows(rows)This whole source file makes use of regular expressions for expected statements. A lot of them could use some work to account for the testing of more issues, with this
tokenbeing an example. The expected query should containsessionToken.Fixed by using
.WithArgs().@ -0,0 +118,4 @@func TestCheckSchema(t *testing.T) {mock, err := initDatabaseMock()if err != nil {t.Errorf(`initDatabaseMock() = "%s", want nil`, err)The possibility of using the
%vformat for errors should be evaluated. Additionally, having the error message in quotes here is misleading, as it could imply that the function has returned a string type instead of an error.@ -0,0 +125,4 @@mockCheckDatabaseSchemaExists(mock)mockGetDatabaseSchemaVersion(mock)checkSchema()To preserve consistency with the rest of the file, the blank line between the mock functions and
checkSchema()must be removed.@ -0,0 +84,4 @@return fmt.Errorf(`len(data) = %d, want 0`, len(data))}got := res.Header.Get("Access-Control-Allow-Methods")This function should check for other preflight headers, such as
Access-Control-Allow-Origin, andAccess-Control-Allow-Headers.Additionally, this function should also check for a 204 No Content response status code.
Add server unit testingto WIP: Add server unit testing@ -0,0 +297,4 @@if err != nil || !got {t.Errorf(`checkEndpointMalformed(%v, "%s", %v) = (%t, %v), want (true, nil)`, http.HandlerFunc(handleEndpointApiSession), contentType, payloadBytes, got, err)}}Both the
TestEndpointApiAccountPostNoPayloadand theTestEndpointApiSessionPostNoPayloadtests fail, as explained in the commit message for2a3d557720.The issue needs to be investigated.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.