From a1d0c66fd263f2fed7c585410fa8f3fd291c12f4 Mon Sep 17 00:00:00 2001 From: eiei114 Date: Sun, 5 Nov 2023 06:12:03 +0900 Subject: [PATCH 1/7] =?UTF-8?q?gotests=E3=82=B3=E3=83=A1=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/application/middleware/auth.go | 1 + app/application/service/user_service.go | 1 + app/infrastructure/persistence/user_repository.go | 1 + app/interface/handler/handler.go | 1 + 4 files changed, 4 insertions(+) diff --git a/app/application/middleware/auth.go b/app/application/middleware/auth.go index fe269f7..ffb0617 100644 --- a/app/application/middleware/auth.go +++ b/app/application/middleware/auth.go @@ -10,6 +10,7 @@ import ( "net/http" ) +//go:generate gotests -w -all $GOFILE type Middleware struct { UserService service.UserServiceInterface } diff --git a/app/application/service/user_service.go b/app/application/service/user_service.go index 4e03811..d26dc20 100644 --- a/app/application/service/user_service.go +++ b/app/application/service/user_service.go @@ -8,6 +8,7 @@ import ( "log" ) +//go:generate gotests -w -all $GOFILE type UserService struct { UserRepository repository.UserRepository } diff --git a/app/infrastructure/persistence/user_repository.go b/app/infrastructure/persistence/user_repository.go index 603ba14..7b1417b 100644 --- a/app/infrastructure/persistence/user_repository.go +++ b/app/infrastructure/persistence/user_repository.go @@ -7,6 +7,7 @@ import ( "log" ) +//go:generate gotests -w -all $GOFILE type UserRepository struct { Conn *bun.DB } diff --git a/app/interface/handler/handler.go b/app/interface/handler/handler.go index 2c64358..6ab9031 100644 --- a/app/interface/handler/handler.go +++ b/app/interface/handler/handler.go @@ -12,6 +12,7 @@ import ( "strconv" ) +//go:generate gotests -w -all $GOFILE type UserHandler struct { userService service.UserServiceInterface } From 4287eeecf78d1e0ded933013ed484d8242988994 Mon Sep 17 00:00:00 2001 From: eiei114 Date: Sun, 5 Nov 2023 06:13:17 +0900 Subject: [PATCH 2/7] tidy --- app/go.mod | 2 ++ app/go.sum | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/app/go.mod b/app/go.mod index bb7feac..4f2d61e 100644 --- a/app/go.mod +++ b/app/go.mod @@ -12,6 +12,7 @@ require ( ) require ( + github.com/cweill/gotests v1.6.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/stretchr/testify v1.8.4 // indirect github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect @@ -19,4 +20,5 @@ require ( github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect golang.org/x/mod v0.14.0 // indirect golang.org/x/sys v0.14.0 // indirect + golang.org/x/tools v0.14.0 // indirect ) diff --git a/app/go.sum b/app/go.sum index c45abc2..40dcaca 100644 --- a/app/go.sum +++ b/app/go.sum @@ -1,3 +1,5 @@ +github.com/cweill/gotests v1.6.0 h1:KJx+/p4EweijYzqPb4Y/8umDCip1Cv6hEVyOx0mE9W8= +github.com/cweill/gotests v1.6.0/go.mod h1:CaRYbxQZGQOxXDvM9l0XJVV2Tjb2E5H53vq+reR2GrA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -49,8 +51,11 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191109212701-97ad0ed33101/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= +golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From 2772e91ed82cd9c5dec43a08f1e3beb5fe810a73 Mon Sep 17 00:00:00 2001 From: eiei114 Date: Sun, 5 Nov 2023 06:13:29 +0900 Subject: [PATCH 3/7] wa-kuhuro-kousinn --- .github/workflows/auto_mockgen.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/auto_mockgen.yml b/.github/workflows/auto_mockgen.yml index fdbadc4..1fa8312 100644 --- a/.github/workflows/auto_mockgen.yml +++ b/.github/workflows/auto_mockgen.yml @@ -28,11 +28,20 @@ jobs: go install go.uber.org/mock/mockgen@latest go install github.com/sanposhiho/gomockhandler@latest + - name: Install gotests + run: | + go get -u github.com/cweill/gotests/... + - name: Generate mocks run: | cd app go generate ./... + - name: Go lint + run: | + go fmt ./... + go mod tidy + - name: Configure Git run: | git config user.name "GitHub Actions" From 619fa486842018118202faaa3d33b36065465ea8 Mon Sep 17 00:00:00 2001 From: eiei114 Date: Sun, 5 Nov 2023 06:16:10 +0900 Subject: [PATCH 4/7] =?UTF-8?q?=E3=83=AF=E3=83=BC=E3=82=AF=E3=83=95?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/auto_mockgen.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/auto_mockgen.yml b/.github/workflows/auto_mockgen.yml index 1fa8312..a993179 100644 --- a/.github/workflows/auto_mockgen.yml +++ b/.github/workflows/auto_mockgen.yml @@ -30,6 +30,7 @@ jobs: - name: Install gotests run: | + cd app go get -u github.com/cweill/gotests/... - name: Generate mocks From b909d1d692664e365ed8fe559f797cde7f95e8d4 Mon Sep 17 00:00:00 2001 From: eiei114 Date: Sun, 5 Nov 2023 06:19:16 +0900 Subject: [PATCH 5/7] =?UTF-8?q?=E3=83=AF=E3=83=BC=E3=82=AF=E3=83=95?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/auto_mockgen.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/auto_mockgen.yml b/.github/workflows/auto_mockgen.yml index a993179..9eb95f2 100644 --- a/.github/workflows/auto_mockgen.yml +++ b/.github/workflows/auto_mockgen.yml @@ -30,9 +30,7 @@ jobs: - name: Install gotests run: | - cd app - go get -u github.com/cweill/gotests/... - + go install github.com/cweill/gotests/gotests@latest - name: Generate mocks run: | cd app From 08492b9589500c665c23b6d03dc7b69fdf872440 Mon Sep 17 00:00:00 2001 From: eiei114 Date: Sun, 5 Nov 2023 06:21:03 +0900 Subject: [PATCH 6/7] =?UTF-8?q?=E3=83=AF=E3=83=BC=E3=82=AF=E3=83=95?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/auto_mockgen.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/auto_mockgen.yml b/.github/workflows/auto_mockgen.yml index 9eb95f2..ec92f74 100644 --- a/.github/workflows/auto_mockgen.yml +++ b/.github/workflows/auto_mockgen.yml @@ -38,6 +38,7 @@ jobs: - name: Go lint run: | + cd app go fmt ./... go mod tidy From d8c3fcb846ad5cd88b64293ab462fb40174c4b86 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Sat, 4 Nov 2023 21:21:58 +0000 Subject: [PATCH 7/7] Generate missing mocks [skip ci] --- app/application/middleware/auth_test.go | 98 ++++++++ app/application/service/user_service_test.go | 227 ++++++++++++++++++ app/go.mod | 4 +- app/go.sum | 32 +-- .../persistence/user_repository_test.go | 217 +++++++++++++++++ app/interface/handler/handler_test.go | 144 +++++++++++ 6 files changed, 689 insertions(+), 33 deletions(-) create mode 100644 app/application/middleware/auth_test.go create mode 100644 app/application/service/user_service_test.go create mode 100644 app/infrastructure/persistence/user_repository_test.go create mode 100644 app/interface/handler/handler_test.go diff --git a/app/application/middleware/auth_test.go b/app/application/middleware/auth_test.go new file mode 100644 index 0000000..d1267c6 --- /dev/null +++ b/app/application/middleware/auth_test.go @@ -0,0 +1,98 @@ +package middleware + +import ( + "reflect" + "testing" + + "example.com/application/service" + "github.com/uptrace/bunrouter" +) + +func TestNewMiddleware(t *testing.T) { + type args struct { + userService service.UserServiceInterface + } + tests := []struct { + name string + args args + want *Middleware + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewMiddleware(tt.args.userService); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewMiddleware() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMiddleware_AuthenticateMiddleware(t *testing.T) { + type fields struct { + UserService service.UserServiceInterface + } + tests := []struct { + name string + fields fields + want func(bunrouter.HandlerFunc) bunrouter.HandlerFunc + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := &Middleware{ + UserService: tt.fields.UserService, + } + if got := m.AuthenticateMiddleware(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("Middleware.AuthenticateMiddleware() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMiddleware_CorsMiddleware(t *testing.T) { + type fields struct { + UserService service.UserServiceInterface + } + tests := []struct { + name string + fields fields + want func(bunrouter.HandlerFunc) bunrouter.HandlerFunc + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := &Middleware{ + UserService: tt.fields.UserService, + } + if got := m.CorsMiddleware(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("Middleware.CorsMiddleware() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestMiddleware_RecoverMiddleware(t *testing.T) { + type fields struct { + UserService service.UserServiceInterface + } + tests := []struct { + name string + fields fields + want func(bunrouter.HandlerFunc) bunrouter.HandlerFunc + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := &Middleware{ + UserService: tt.fields.UserService, + } + if got := m.RecoverMiddleware(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("Middleware.RecoverMiddleware() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/app/application/service/user_service_test.go b/app/application/service/user_service_test.go new file mode 100644 index 0000000..565db41 --- /dev/null +++ b/app/application/service/user_service_test.go @@ -0,0 +1,227 @@ +package service + +import ( + "context" + "reflect" + "testing" + + "example.com/domain" + "example.com/domain/repository" +) + +func TestNewUserService(t *testing.T) { + type args struct { + UserRepository repository.UserRepository + } + tests := []struct { + name string + args args + want *UserService + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewUserService(tt.args.UserRepository); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewUserService() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUserService_Add(t *testing.T) { + type fields struct { + UserRepository repository.UserRepository + } + type args struct { + ctx context.Context + name string + } + tests := []struct { + name string + fields fields + args args + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + u := &UserService{ + UserRepository: tt.fields.UserRepository, + } + got, err := u.Add(tt.args.ctx, tt.args.name) + if (err != nil) != tt.wantErr { + t.Errorf("UserService.Add() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("UserService.Add() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUserService_UpdateUser(t *testing.T) { + type fields struct { + UserRepository repository.UserRepository + } + type args struct { + ctx context.Context + user domain.User + } + tests := []struct { + name string + fields fields + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + u := &UserService{ + UserRepository: tt.fields.UserRepository, + } + if err := u.UpdateUser(tt.args.ctx, tt.args.user); (err != nil) != tt.wantErr { + t.Errorf("UserService.UpdateUser() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestUserService_Delete(t *testing.T) { + type fields struct { + UserRepository repository.UserRepository + } + type args struct { + ctx context.Context + id string + } + tests := []struct { + name string + fields fields + args args + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + u := &UserService{ + UserRepository: tt.fields.UserRepository, + } + got, err := u.Delete(tt.args.ctx, tt.args.id) + if (err != nil) != tt.wantErr { + t.Errorf("UserService.Delete() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("UserService.Delete() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUserService_GetUserByUserId(t *testing.T) { + type fields struct { + UserRepository repository.UserRepository + } + type args struct { + ctx context.Context + id string + } + tests := []struct { + name string + fields fields + args args + want domain.User + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + u := &UserService{ + UserRepository: tt.fields.UserRepository, + } + got, err := u.GetUserByUserId(tt.args.ctx, tt.args.id) + if (err != nil) != tt.wantErr { + t.Errorf("UserService.GetUserByUserId() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("UserService.GetUserByUserId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUserService_GetUserByAuthToken(t *testing.T) { + type fields struct { + UserRepository repository.UserRepository + } + type args struct { + ctx context.Context + authToken string + } + tests := []struct { + name string + fields fields + args args + want *domain.User + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + u := &UserService{ + UserRepository: tt.fields.UserRepository, + } + got, err := u.GetUserByAuthToken(tt.args.ctx, tt.args.authToken) + if (err != nil) != tt.wantErr { + t.Errorf("UserService.GetUserByAuthToken() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("UserService.GetUserByAuthToken() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUserService_GetUserRanking(t *testing.T) { + type fields struct { + UserRepository repository.UserRepository + } + type args struct { + ctx context.Context + } + tests := []struct { + name string + fields fields + args args + want []*domain.UserRanking + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + u := &UserService{ + UserRepository: tt.fields.UserRepository, + } + got, err := u.GetUserRanking(tt.args.ctx) + if (err != nil) != tt.wantErr { + t.Errorf("UserService.GetUserRanking() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("UserService.GetUserRanking() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/app/go.mod b/app/go.mod index 4f2d61e..69912ef 100644 --- a/app/go.mod +++ b/app/go.mod @@ -4,15 +4,14 @@ go 1.21.1 require ( github.com/go-sql-driver/mysql v1.7.1 - github.com/golang/mock v1.6.0 github.com/google/uuid v1.3.1 github.com/uptrace/bun v1.1.16 github.com/uptrace/bun/dialect/mysqldialect v1.1.16 github.com/uptrace/bunrouter v1.0.20 + go.uber.org/mock v0.3.0 ) require ( - github.com/cweill/gotests v1.6.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/stretchr/testify v1.8.4 // indirect github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect @@ -20,5 +19,4 @@ require ( github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect golang.org/x/mod v0.14.0 // indirect golang.org/x/sys v0.14.0 // indirect - golang.org/x/tools v0.14.0 // indirect ) diff --git a/app/go.sum b/app/go.sum index 40dcaca..4a7017b 100644 --- a/app/go.sum +++ b/app/go.sum @@ -1,12 +1,8 @@ -github.com/cweill/gotests v1.6.0 h1:KJx+/p4EweijYzqPb4Y/8umDCip1Cv6hEVyOx0mE9W8= -github.com/cweill/gotests v1.6.0/go.mod h1:CaRYbxQZGQOxXDvM9l0XJVV2Tjb2E5H53vq+reR2GrA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= @@ -29,36 +25,12 @@ github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9 github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +go.uber.org/mock v0.3.0 h1:3mUxI1No2/60yUYax92Pt8eNOEecx2D3lcXZh2NEZJo= +go.uber.org/mock v0.3.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191109212701-97ad0ed33101/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= -golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/app/infrastructure/persistence/user_repository_test.go b/app/infrastructure/persistence/user_repository_test.go new file mode 100644 index 0000000..62c6300 --- /dev/null +++ b/app/infrastructure/persistence/user_repository_test.go @@ -0,0 +1,217 @@ +package infrastructure + +import ( + "context" + "reflect" + "testing" + + "example.com/domain" + "github.com/uptrace/bun" +) + +func TestNewUserRepository(t *testing.T) { + type args struct { + Conn *bun.DB + } + tests := []struct { + name string + args args + want *UserRepository + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewUserRepository(tt.args.Conn); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewUserRepository() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUserRepository_AddUser(t *testing.T) { + type fields struct { + Conn *bun.DB + } + type args struct { + ctx context.Context + id string + authToken string + name string + } + tests := []struct { + name string + fields fields + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + u := &UserRepository{ + Conn: tt.fields.Conn, + } + if err := u.AddUser(tt.args.ctx, tt.args.id, tt.args.authToken, tt.args.name); (err != nil) != tt.wantErr { + t.Errorf("UserRepository.AddUser() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestUserRepository_UpdateUser(t *testing.T) { + type fields struct { + Conn *bun.DB + } + type args struct { + ctx context.Context + user domain.User + } + tests := []struct { + name string + fields fields + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + u := &UserRepository{ + Conn: tt.fields.Conn, + } + if err := u.UpdateUser(tt.args.ctx, tt.args.user); (err != nil) != tt.wantErr { + t.Errorf("UserRepository.UpdateUser() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestUserRepository_DeleteUser(t *testing.T) { + type fields struct { + Conn *bun.DB + } + type args struct { + ctx context.Context + id string + } + tests := []struct { + name string + fields fields + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + u := &UserRepository{ + Conn: tt.fields.Conn, + } + if err := u.DeleteUser(tt.args.ctx, tt.args.id); (err != nil) != tt.wantErr { + t.Errorf("UserRepository.DeleteUser() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestUserRepository_GetUserByUserId(t *testing.T) { + type fields struct { + Conn *bun.DB + } + type args struct { + ctx context.Context + id string + } + tests := []struct { + name string + fields fields + args args + want domain.User + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + u := &UserRepository{ + Conn: tt.fields.Conn, + } + got, err := u.GetUserByUserId(tt.args.ctx, tt.args.id) + if (err != nil) != tt.wantErr { + t.Errorf("UserRepository.GetUserByUserId() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("UserRepository.GetUserByUserId() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUserRepository_GetUserByAuthToken(t *testing.T) { + type fields struct { + Conn *bun.DB + } + type args struct { + ctx context.Context + authToken string + } + tests := []struct { + name string + fields fields + args args + want *domain.User + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + u := &UserRepository{ + Conn: tt.fields.Conn, + } + got, err := u.GetUserByAuthToken(tt.args.ctx, tt.args.authToken) + if (err != nil) != tt.wantErr { + t.Errorf("UserRepository.GetUserByAuthToken() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("UserRepository.GetUserByAuthToken() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUserRepository_GetUserRanking(t *testing.T) { + type fields struct { + Conn *bun.DB + } + type args struct { + ctx context.Context + } + tests := []struct { + name string + fields fields + args args + want []*domain.UserRanking + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + u := &UserRepository{ + Conn: tt.fields.Conn, + } + got, err := u.GetUserRanking(tt.args.ctx) + if (err != nil) != tt.wantErr { + t.Errorf("UserRepository.GetUserRanking() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("UserRepository.GetUserRanking() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/app/interface/handler/handler_test.go b/app/interface/handler/handler_test.go new file mode 100644 index 0000000..ad30104 --- /dev/null +++ b/app/interface/handler/handler_test.go @@ -0,0 +1,144 @@ +package _interface + +import ( + "reflect" + "testing" + + "example.com/application/service" + "github.com/uptrace/bunrouter" +) + +func TestNewUserHandler(t *testing.T) { + type args struct { + userService service.UserServiceInterface + } + tests := []struct { + name string + args args + want *UserHandler + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewUserHandler(tt.args.userService); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewUserHandler() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUserHandler_UserCreateHandle(t *testing.T) { + type fields struct { + userService service.UserServiceInterface + } + tests := []struct { + name string + fields fields + want bunrouter.HandlerFunc + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + u := &UserHandler{ + userService: tt.fields.userService, + } + if got := u.UserCreateHandle(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UserHandler.UserCreateHandle() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUserHandler_UserGetHandle(t *testing.T) { + type fields struct { + userService service.UserServiceInterface + } + tests := []struct { + name string + fields fields + want bunrouter.HandlerFunc + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + u := &UserHandler{ + userService: tt.fields.userService, + } + if got := u.UserGetHandle(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UserHandler.UserGetHandle() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUserHandler_ScoreUpdateHandle(t *testing.T) { + type fields struct { + userService service.UserServiceInterface + } + tests := []struct { + name string + fields fields + want bunrouter.HandlerFunc + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + u := &UserHandler{ + userService: tt.fields.userService, + } + if got := u.ScoreUpdateHandle(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UserHandler.ScoreUpdateHandle() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUserHandler_UserRankingGetHandle(t *testing.T) { + type fields struct { + userService service.UserServiceInterface + } + tests := []struct { + name string + fields fields + want bunrouter.HandlerFunc + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + u := &UserHandler{ + userService: tt.fields.userService, + } + if got := u.UserRankingGetHandle(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UserHandler.UserRankingGetHandle() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestUserHandler_DestroyHandle(t *testing.T) { + type fields struct { + userService service.UserServiceInterface + } + tests := []struct { + name string + fields fields + want bunrouter.HandlerFunc + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + u := &UserHandler{ + userService: tt.fields.userService, + } + if got := u.DestroyHandle(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UserHandler.DestroyHandle() = %v, want %v", got, tt.want) + } + }) + } +}