diff --git a/pkg/database/sql/user_test.go b/pkg/database/sql/user_test.go
index db436767045e01cc9b20d03e3bee2576e01c6707..fda744038a8cb5ee639b4ec1dfc0132466904578 100644
--- a/pkg/database/sql/user_test.go
+++ b/pkg/database/sql/user_test.go
@@ -12,69 +12,101 @@ "git.sr.ht/~gabrielgio/img/pkg/database/repository"
)
func TestCreate(t *testing.T) {
- t.Parallel()
- db, tearDown := setup(t)
- defer tearDown()
+ 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",
+ },
+ },
+ }
- userRepository := NewUserRepository(db)
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ db, tearDown := setup(t)
+ defer tearDown()
- id, err := userRepository.Create(context.Background(), &repository.CreateUser{
- Username: "new_username",
- Name: "new_name",
- })
- if err != nil {
- t.Fatalf("Error creating: %s", err.Error())
- }
+ userRepository := NewUserRepository(db)
+ id, err := userRepository.Create(context.Background(), tc.createUser)
+ if err != nil {
+ t.Fatalf("Error creating: %s", err.Error())
+ }
- 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",
- }
+ got, err := userRepository.Get(context.Background(), id)
+ if err != nil {
+ t.Fatalf("Error getting: %s", err.Error())
+ }
- if diff := cmp.Diff(want, got); diff != "" {
- t.Errorf("%s() mismatch (-want +got):\n%s", "Update", diff)
+ 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()
+ 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",
+ },
+ },
+ }
- userRepository := NewUserRepository(db)
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ db, tearDown := setup(t)
+ defer tearDown()
- id, err := userRepository.Create(context.Background(), &repository.CreateUser{
- Username: "username",
- Name: "name",
- })
- if err != nil {
- t.Fatalf("Error creating user: %s", err.Error())
- }
+ 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())
+ }
- 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())
+ }
- 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",
- }
+ 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 ba2f071537abbcc25f8ec2d3fc1eb18f05b9ac1c..6ec783d6d9bbc32dcb34efe3deba29230cdc3e39 100644
--- a/templates/user.qtpl
+++ b/templates/user.qtpl
@@ -9,7 +9,7 @@ }
%}
-{% func (p *UserPage) Title() %}Login{% endfunc %}
+{% func (p *UserPage) Title() %}User{% endfunc %}
{% func (p *UserPage) Content() %}
<h1>Initial Setup</h1>