-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6381c4
commit f394f54
Showing
5 changed files
with
153 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
services/storage/tests/internal/delivery/http/cloud/handler_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package cloud | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"errors" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/febrihidayan/go-architecture-monorepo/pkg/common" | ||
"github.com/febrihidayan/go-architecture-monorepo/pkg/exceptions" | ||
"github.com/febrihidayan/go-architecture-monorepo/services/storage/internal/config" | ||
cloud_http "github.com/febrihidayan/go-architecture-monorepo/services/storage/internal/delivery/http/delivery/cloud" | ||
"github.com/febrihidayan/go-architecture-monorepo/services/storage/tests/mocks/usecases" | ||
"github.com/gorilla/mux" | ||
"github.com/hashicorp/go-multierror" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type CloudHandlerSuite struct { | ||
suite.Suite | ||
Route *mux.Router | ||
Cfg *config.StorageConfig | ||
Http *cloud_http.CloudHttpHandler | ||
Response *httptest.ResponseRecorder | ||
CloudUsecase *usecases.CloudUsecaseMock | ||
Error *exceptions.CustomError | ||
Token string | ||
Id common.ID | ||
} | ||
|
||
func (x *CloudHandlerSuite) SetupTest() { | ||
x.Cfg = &config.StorageConfig{ | ||
MaxUpload: 15, | ||
} | ||
|
||
x.CloudUsecase = new(usecases.CloudUsecaseMock) | ||
|
||
x.Response = httptest.NewRecorder() | ||
x.Route = mux.NewRouter() | ||
|
||
x.Http = &cloud_http.CloudHttpHandler{ | ||
Cfg: x.Cfg, | ||
CloudUsecase: x.CloudUsecase, | ||
} | ||
|
||
x.Error = &exceptions.CustomError{ | ||
Status: exceptions.ERRREPOSITORY, | ||
Errors: multierror.Append(errors.New(mock.Anything)), | ||
} | ||
|
||
x.Token = "Bearer eyJhbGciOiJIUzI1NiIsImtpZCI6InNpbTIifQ.eyJleHAiOjE3MDM4NjI3NTgsImp0aSI6Im1uYjIzdmNzcnQ3NTZ5dWlvbW5idmN4OThlcnR5dWlvcCIsInJvbGVzIjpbInN1cGVyYWRtaW5pc3RyYXRvciJdLCJzdWIiOiIzYzkyYzE4MC1mOGE0LTQ0ZGMtYWJlZS00ZDg2ODhmNDBjYWUifQ.aMKIC5uTqAxEEAhZ-aqvuhDYfc56M_6ZukUGImoxdLs" | ||
x.Id = common.NewID() | ||
|
||
} | ||
|
||
func TestAclHandler(t *testing.T) { | ||
suite.Run(t, new(CloudHandlerSuite)) | ||
} | ||
|
||
type Any []interface{} | ||
|
||
func (a Any) Get(i int) interface{} { | ||
return a[i] | ||
} | ||
|
||
type HandlerParams struct { | ||
method string | ||
path string | ||
payload Any | ||
expected int | ||
} | ||
|
||
func BodyHelper(v any) *bytes.Buffer { | ||
b, _ := json.Marshal(v) | ||
return bytes.NewBuffer(b) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package usecases | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/febrihidayan/go-architecture-monorepo/pkg/exceptions" | ||
"github.com/febrihidayan/go-architecture-monorepo/services/storage/domain/entities" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
type CloudUsecaseMock struct { | ||
mock.Mock | ||
} | ||
|
||
func (x *CloudUsecaseMock) Create(ctx context.Context, payload entities.CloudDto) (result *entities.Cloud, err *exceptions.CustomError) { | ||
args := x.Called(payload) | ||
|
||
if n, ok := args.Get(0).(*entities.Cloud); ok { | ||
result = n | ||
} | ||
|
||
if n, ok := args.Get(1).(*exceptions.CustomError); ok { | ||
err = n | ||
} | ||
|
||
return | ||
} | ||
|
||
func (x *CloudUsecaseMock) DeleteAllStatusJob(ctx context.Context) (err *exceptions.CustomError) { | ||
args := x.Called() | ||
|
||
if n, ok := args.Get(0).(*exceptions.CustomError); ok { | ||
err = n | ||
} | ||
|
||
return | ||
} | ||
|
||
func (x *CloudUsecaseMock) Deletes(ctx context.Context, payloads []*entities.Cloud) (err *exceptions.CustomError) { | ||
args := x.Called(payloads) | ||
|
||
if n, ok := args.Get(0).(*exceptions.CustomError); ok { | ||
err = n | ||
} | ||
|
||
return | ||
} | ||
|
||
func (x *CloudUsecaseMock) UpdateStatus(ctx context.Context, payloads []*entities.Cloud) (err *exceptions.CustomError) { | ||
args := x.Called(payloads) | ||
|
||
if n, ok := args.Get(0).(*exceptions.CustomError); ok { | ||
err = n | ||
} | ||
|
||
return | ||
} |