From 303ab08e086c2b790c9fa0432929ba5f6eb7862c Mon Sep 17 00:00:00 2001 From: Molly Draven Date: Fri, 25 Oct 2024 21:05:26 -0400 Subject: [PATCH] Add unit test for AuthenticateUser function --- src/web_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/web_test.go 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) + } + }) + } +}