Skip to content

Commit

Permalink
Add unit test for AuthenticateUser function
Browse files Browse the repository at this point in the history
  • Loading branch information
drazisil committed Oct 26, 2024
1 parent d754068 commit 303ab08
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/web_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package gorace_test

import (
"fmt"
"testing"
. "github.com/rustymotors/gorace/src"
)

func TestAuthenticateUser(t *testing.T) {
tests := []struct {
username string
password string
expected int
}{
{"admin", "admin", 1},
{"admin", "wrongpassword", 0},
{"wronguser", "admin", 0},
{"wronguser", "wrongpassword", 0},
}

for _, test := range tests {
t.Run(fmt.Sprintf("username=%s,password=%s", test.username, test.password), func(t *testing.T) {
result := AuthenticateUser(test.username, test.password)
if result != test.expected {
t.Errorf("AuthenticateUser(%s, %s) = %d; want %d", test.username, test.password, result, test.expected)
}
})
}
}

0 comments on commit 303ab08

Please sign in to comment.