-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
2 changed files
with
152 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,100 @@ | ||
package usecase | ||
package usecase_test | ||
|
||
import "testing" | ||
import ( | ||
"context" | ||
"testing" | ||
|
||
func TestArchiveInteractor_UploadArchive(t *testing.T) { | ||
// TODO implement this test | ||
mock_repository "github.com/CityBear3/satellite/internal/adaptor/gateway/repository/mock" | ||
"github.com/CityBear3/satellite/internal/domain/entity" | ||
"github.com/CityBear3/satellite/internal/domain/primitive" | ||
"github.com/CityBear3/satellite/internal/domain/primitive/archive" | ||
"github.com/CityBear3/satellite/internal/domain/primitive/device" | ||
"github.com/CityBear3/satellite/internal/usecase" | ||
mock_usecase "github.com/CityBear3/satellite/internal/usecase/mock" | ||
"github.com/stretchr/testify/assert" | ||
"go.uber.org/mock/gomock" | ||
) | ||
|
||
func TestArchiveInteractor_CreateArchive(t *testing.T) { | ||
type args struct { | ||
ctx context.Context | ||
req usecase.CreateArchiveInput | ||
device entity.Device | ||
} | ||
|
||
ctrl := gomock.NewController(t) | ||
mockArchiveRepository := mock_repository.NewMockIArchiveRepository(ctrl) | ||
mockEventRepository := mock_repository.NewMockIEventRepository(ctrl) | ||
mockITxManager := mock_usecase.NewMockITxManager(ctrl) | ||
|
||
sut := usecase.NewArchiveInteractor(mockArchiveRepository, mockEventRepository, mockITxManager) | ||
|
||
contentType, err := archive.NewContentType("image/png") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
data, err := archive.NewData([]byte("test")) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
deviceName, err := device.NewDeviceName("test") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
device := entity.NewDevice(primitive.NewID(), deviceName, nil, primitive.NewID()) | ||
|
||
tests := []struct { | ||
name string | ||
args args | ||
wantErr error | ||
assertion assert.ErrorAssertionFunc | ||
runMock func(ctx context.Context, req usecase.CreateArchiveInput, device entity.Device) | ||
}{ | ||
{ | ||
name: "success to create archive", | ||
args: args{ | ||
ctx: context.Background(), | ||
req: usecase.CreateArchiveInput{ | ||
ArchiveEventID: primitive.NewID(), | ||
ContentType: contentType, | ||
Data: data, | ||
}, | ||
device: device, | ||
}, | ||
|
||
assertion: assert.NoError, | ||
runMock: func(ctx context.Context, req usecase.CreateArchiveInput, device entity.Device) { | ||
mockITxManager. | ||
EXPECT(). | ||
DoInTx(ctx, gomock.Any()). | ||
DoAndReturn(func(ctx context.Context, f func(ctx2 context.Context) error) (interface{}, error) { | ||
return gomock.Any(), f(ctx) | ||
}) | ||
|
||
mockEventRepository. | ||
EXPECT(). | ||
GetArchiveEvent(ctx, req.ArchiveEventID). | ||
Return(entity.NewArchiveEvent(req.ArchiveEventID, device.ID, device.ClientID), nil) | ||
|
||
mockArchiveRepository. | ||
EXPECT().Save(ctx, gomock.Any()). | ||
Return(nil) | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tt.runMock(tt.args.ctx, tt.args.req, tt.args.device) | ||
err = sut.CreateArchive(tt.args.ctx, tt.args.req, tt.args.device) | ||
tt.assertion(t, err) | ||
|
||
if tt.wantErr != nil { | ||
assert.EqualError(t, err, tt.wantErr.Error()) | ||
} | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.