aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pkg/database/sql/user_test.go138
-rw-r--r--templates/user.qtpl2
2 files changed, 86 insertions, 54 deletions
diff --git a/pkg/database/sql/user_test.go b/pkg/database/sql/user_test.go
index db43676..fda7440 100644
--- a/pkg/database/sql/user_test.go
+++ b/pkg/database/sql/user_test.go
@@ -12,69 +12,101 @@ import (
)
func TestCreate(t *testing.T) {
- t.Parallel()
- db, tearDown := setup(t)
- defer tearDown()
-
- userRepository := NewUserRepository(db)
-
- id, err := userRepository.Create(context.Background(), &repository.CreateUser{
- Username: "new_username",
- Name: "new_name",
- })
- if err != nil {
- t.Fatalf("Error creating: %s", err.Error())
+ testCases := []struct {
+ name string
+ createUser *repository.CreateUser
+ want *repository.User
+ }{
+ {
+ name: "Normal",
+ createUser: &repository.CreateUser{
+ Username: "new_username",
+ Name: "new_name",
+ },
+ want: &repository.User{
+ ID: 1, // since the database is being created I can assume 1
+ Username: "new_username",
+ Name: "new_name",
+ },
+ },
}
- got, err := userRepository.Get(context.Background(), id)
- if err != nil {
- t.Fatalf("Error getting: %s", err.Error())
- }
- want := &repository.User{
- ID: id,
- Username: "new_username",
- Name: "new_name",
- }
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ db, tearDown := setup(t)
+ defer tearDown()
+
+ userRepository := NewUserRepository(db)
+ id, err := userRepository.Create(context.Background(), tc.createUser)
+ if err != nil {
+ t.Fatalf("Error creating: %s", err.Error())
+ }
- if diff := cmp.Diff(want, got); diff != "" {
- t.Errorf("%s() mismatch (-want +got):\n%s", "Update", diff)
+ got, err := userRepository.Get(context.Background(), id)
+ if err != nil {
+ t.Fatalf("Error getting: %s", err.Error())
+ }
+
+ if diff := cmp.Diff(tc.want, got); diff != "" {
+ t.Errorf("%s() mismatch (-want +got):\n%s", "Update", diff)
+ }
+ })
}
}
func TestUpdate(t *testing.T) {
- t.Parallel()
- db, tearDown := setup(t)
- defer tearDown()
-
- userRepository := NewUserRepository(db)
-
- id, err := userRepository.Create(context.Background(), &repository.CreateUser{
- Username: "username",
- Name: "name",
- })
- if err != nil {
- t.Fatalf("Error creating user: %s", err.Error())
+ testCases := []struct {
+ name string
+ createUser *repository.CreateUser
+ want *repository.User
+ }{
+ {
+ name: "Normal creation",
+ createUser: &repository.CreateUser{
+ Username: "username",
+ Name: "name",
+ IsAdmin: true,
+ Path: "/tmp/new_folder",
+ },
+ want: &repository.User{
+ ID: 1, // since the database is being created I can assume 1
+ Username: "new_username",
+ Name: "new_name",
+ IsAdmin: true,
+ Path: "/tmp/new_folder",
+ },
+ },
}
- err = userRepository.Update(context.Background(), id, &repository.UpdateUser{
- Username: "new_username",
- Name: "new_name",
- })
- if err != nil {
- t.Fatalf("Error update user: %s", err.Error())
- }
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ db, tearDown := setup(t)
+ defer tearDown()
- got, err := userRepository.Get(context.Background(), 1)
- if err != nil {
- t.Fatalf("Error getting user: %s", err.Error())
- }
- want := &repository.User{
- ID: id,
- Username: "new_username",
- Name: "new_name",
- }
+ userRepository := NewUserRepository(db)
+
+ id, err := userRepository.Create(context.Background(), tc.createUser)
+ if err != nil {
+ t.Fatalf("Error creating user: %s", err.Error())
+ }
+
+ err = userRepository.Update(context.Background(), id, &repository.UpdateUser{
+ Username: "new_username",
+ Name: "new_name",
+ })
+ if err != nil {
+ t.Fatalf("Error update user: %s", err.Error())
+ }
+
+ got, err := userRepository.Get(context.Background(), 1)
+ if err != nil {
+ t.Fatalf("Error getting user: %s", err.Error())
+ }
+
+ if diff := cmp.Diff(tc.want, got); diff != "" {
+ t.Errorf("%s() mismatch (-want +got):\n%s", "Update", diff)
+ }
- if diff := cmp.Diff(want, got); diff != "" {
- t.Errorf("%s() mismatch (-want +got):\n%s", "Update", diff)
+ })
}
}
diff --git a/templates/user.qtpl b/templates/user.qtpl
index ba2f071..6ec783d 100644
--- a/templates/user.qtpl
+++ b/templates/user.qtpl
@@ -9,7 +9,7 @@ type UserPage struct {
%}
-{% func (p *UserPage) Title() %}Login{% endfunc %}
+{% func (p *UserPage) Title() %}User{% endfunc %}
{% func (p *UserPage) Content() %}
<h1>Initial Setup</h1>