diff --git a/src/web_test.go b/src/web_test.go new file mode 100644 index 0000000..6d2a2ff --- /dev/null +++ b/src/web_test.go @@ -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) + } + }) + } +}