Skip to content

Commit

Permalink
Update tests (#416)
Browse files Browse the repository at this point in the history
* Update tests
  • Loading branch information
johnfercher authored May 15, 2024
1 parent 027c37f commit 727147b
Show file tree
Hide file tree
Showing 26 changed files with 147 additions and 641 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ fmt:
.PHONY: lint
lint:
golangci-lint run --config=.golangci.yml ./...
make mock-lint

.PHONY: mock-lint
mock-lint:
bash shell/mock-check.sh

.PHONY: install
install:
bash install.sh
bash shell/install.sh

.PHONY: docs
docs:
Expand Down
6 changes: 3 additions & 3 deletions internal/cache/mutexcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestMutexCache_AddImage(t *testing.T) {
value := "value1"
img := &entity.Image{}

innerMock := &mocks.Cache{}
innerMock := mocks.NewCache(t)
innerMock.EXPECT().AddImage(value, img)

sut := cache.NewMutexDecorator(innerMock)
Expand All @@ -47,7 +47,7 @@ func TestMutexCache_GetImage(t *testing.T) {
imgToReturn := &entity.Image{}
errToReturn := errors.New("any error")

innerMock := &mocks.Cache{}
innerMock := mocks.NewCache(t)
innerMock.EXPECT().GetImage(value, ext).Return(imgToReturn, errToReturn)

sut := cache.NewMutexDecorator(innerMock)
Expand All @@ -67,7 +67,7 @@ func TestMutexCache_LoadImage(t *testing.T) {
ext := extension.Jpg
errToReturn := errors.New("any error")

innerMock := &mocks.Cache{}
innerMock := mocks.NewCache(t)
innerMock.EXPECT().LoadImage(value, ext).Return(errToReturn)

sut := cache.NewMutexDecorator(innerMock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestBorderColorStyler_Apply(t *testing.T) {
cfg := &entity.Config{}
var nilCellProp *props.Cell

inner := &mocks.CellWriter{}
inner := mocks.NewCellWriter(t)
inner.EXPECT().Apply(width, height, cfg, nilCellProp)

sut := cellwriter.NewBorderColorStyler(nil)
Expand All @@ -57,7 +57,7 @@ func TestBorderColorStyler_Apply(t *testing.T) {
cfg := &entity.Config{}
prop := &props.Cell{}

inner := &mocks.CellWriter{}
inner := mocks.NewCellWriter(t)
inner.EXPECT().Apply(width, height, cfg, prop)

sut := cellwriter.NewBorderColorStyler(nil)
Expand All @@ -78,10 +78,10 @@ func TestBorderColorStyler_Apply(t *testing.T) {
BorderColor: &props.Color{Red: 140, Green: 100, Blue: 80},
}

inner := &mocks.CellWriter{}
inner := mocks.NewCellWriter(t)
inner.EXPECT().Apply(width, height, cfg, prop)

fpdf := &mocks.Fpdf{}
fpdf := mocks.NewFpdf(t)
fpdf.EXPECT().SetDrawColor(prop.BorderColor.Red, prop.BorderColor.Green, prop.BorderColor.Blue)
fpdf.EXPECT().SetDrawColor(0, 0, 0)

Expand Down
10 changes: 5 additions & 5 deletions internal/providers/gofpdf/cellwriter/borderlinestyler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestBorderLineStyler_Apply(t *testing.T) {
cfg := &entity.Config{}
var nilCellProp *props.Cell

inner := &mocks.CellWriter{}
inner := mocks.NewCellWriter(t)
inner.EXPECT().Apply(width, height, cfg, nilCellProp)

sut := cellwriter.NewBorderLineStyler(nil)
Expand All @@ -59,7 +59,7 @@ func TestBorderLineStyler_Apply(t *testing.T) {
LineStyle: linestyle.Solid,
}

inner := &mocks.CellWriter{}
inner := mocks.NewCellWriter(t)
inner.EXPECT().Apply(width, height, cfg, prop)

sut := cellwriter.NewBorderLineStyler(nil)
Expand All @@ -78,7 +78,7 @@ func TestBorderLineStyler_Apply(t *testing.T) {
cfg := &entity.Config{}
prop := &props.Cell{}

inner := &mocks.CellWriter{}
inner := mocks.NewCellWriter(t)
inner.EXPECT().Apply(width, height, cfg, prop)

sut := cellwriter.NewBorderLineStyler(nil)
Expand All @@ -99,10 +99,10 @@ func TestBorderLineStyler_Apply(t *testing.T) {
LineStyle: linestyle.Dashed,
}

inner := &mocks.CellWriter{}
inner := mocks.NewCellWriter(t)
inner.EXPECT().Apply(width, height, cfg, prop)

fpdf := &mocks.Fpdf{}
fpdf := mocks.NewFpdf(t)
fpdf.EXPECT().SetDashPattern([]float64{1, 1}, 0.0)
fpdf.EXPECT().SetDashPattern([]float64{1, 0}, 0.0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestBorderThicknessStyler_Apply(t *testing.T) {
cfg := &entity.Config{}
var nilCellProp *props.Cell

inner := &mocks.CellWriter{}
inner := mocks.NewCellWriter(t)
inner.EXPECT().Apply(width, height, cfg, nilCellProp)

sut := cellwriter.NewBorderThicknessStyler(nil)
Expand All @@ -57,7 +57,7 @@ func TestBorderThicknessStyler_Apply(t *testing.T) {
cfg := &entity.Config{}
prop := &props.Cell{}

inner := &mocks.CellWriter{}
inner := mocks.NewCellWriter(t)
inner.EXPECT().Apply(width, height, cfg, prop)

sut := cellwriter.NewBorderThicknessStyler(nil)
Expand All @@ -78,10 +78,10 @@ func TestBorderThicknessStyler_Apply(t *testing.T) {
BorderThickness: 1.0,
}

inner := &mocks.CellWriter{}
inner := mocks.NewCellWriter(t)
inner.EXPECT().Apply(width, height, cfg, prop)

fpdf := &mocks.Fpdf{}
fpdf := mocks.NewFpdf(t)
fpdf.EXPECT().SetLineWidth(prop.BorderThickness)
fpdf.EXPECT().SetLineWidth(linestyle.DefaultLineThickness)

Expand Down
8 changes: 4 additions & 4 deletions internal/providers/gofpdf/cellwriter/cellwriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestCellWriter_Apply(t *testing.T) {
config := &entity.Config{}
width := 100.0
height := 200.0
fpdf := &mocks.Fpdf{}
fpdf := mocks.NewFpdf(t)
fpdf.EXPECT().CellFormat(width, height, "", "", 0, "C", false, 0, "")

sut := cellwriter.NewCellWriter(fpdf)
Expand All @@ -46,7 +46,7 @@ func TestCellWriter_Apply(t *testing.T) {
}
width := 100.0
height := 200.0
fpdf := &mocks.Fpdf{}
fpdf := mocks.NewFpdf(t)
fpdf.EXPECT().CellFormat(width, height, "", "1", 0, "C", false, 0, "")

sut := cellwriter.NewCellWriter(fpdf)
Expand All @@ -63,7 +63,7 @@ func TestCellWriter_Apply(t *testing.T) {
prop := fixture.CellProp()
width := 100.0
height := 200.0
fpdf := &mocks.Fpdf{}
fpdf := mocks.NewFpdf(t)
fpdf.EXPECT().CellFormat(width, height, "", "L", 0, "C", true, 0, "")

sut := cellwriter.NewCellWriter(fpdf)
Expand All @@ -82,7 +82,7 @@ func TestCellWriter_Apply(t *testing.T) {
prop := fixture.CellProp()
width := 100.0
height := 200.0
fpdf := &mocks.Fpdf{}
fpdf := mocks.NewFpdf(t)
fpdf.EXPECT().CellFormat(width, height, "", "1", 0, "C", true, 0, "")

sut := cellwriter.NewCellWriter(fpdf)
Expand Down
8 changes: 4 additions & 4 deletions internal/providers/gofpdf/cellwriter/fillcolorstyler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestFillColorStyle_Apply(t *testing.T) {
cfg := &entity.Config{}
var nilCellProp *props.Cell

inner := &mocks.CellWriter{}
inner := mocks.NewCellWriter(t)
inner.EXPECT().Apply(width, height, cfg, nilCellProp)

sut := cellwriter.NewFillColorStyler(nil)
Expand All @@ -56,7 +56,7 @@ func TestFillColorStyle_Apply(t *testing.T) {
cfg := &entity.Config{}
prop := &props.Cell{}

inner := &mocks.CellWriter{}
inner := mocks.NewCellWriter(t)
inner.EXPECT().Apply(width, height, cfg, prop)

sut := cellwriter.NewFillColorStyler(nil)
Expand All @@ -77,10 +77,10 @@ func TestFillColorStyle_Apply(t *testing.T) {
BackgroundColor: &props.Color{Red: 100, Green: 150, Blue: 170},
}

inner := &mocks.CellWriter{}
inner := mocks.NewCellWriter(t)
inner.EXPECT().Apply(width, height, cfg, prop)

fpdf := &mocks.Fpdf{}
fpdf := mocks.NewFpdf(t)
fpdf.EXPECT().SetFillColor(prop.BackgroundColor.Red, prop.BackgroundColor.Green, prop.BackgroundColor.Blue)
fpdf.EXPECT().SetFillColor(255, 255, 255)

Expand Down
14 changes: 7 additions & 7 deletions internal/providers/gofpdf/font_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestNewFont(t *testing.T) {
family := fontfamily.Arial
style := fontstyle.Bold

fpdf := &mocks.Fpdf{}
fpdf := mocks.NewFpdf(t)
fpdf.EXPECT().SetFont(family, string(style), size)

// Act
Expand All @@ -40,7 +40,7 @@ func TestFont_GetHeight(t *testing.T) {
family := fontfamily.Arial
style := fontstyle.Bold

fpdf := &mocks.Fpdf{}
fpdf := mocks.NewFpdf(t)
fpdf.EXPECT().SetFont(family, string(style), size)
font := gofpdf.NewFont(fpdf, size, family, style)

Expand All @@ -57,7 +57,7 @@ func TestFont_SetFamily(t *testing.T) {
family := fontfamily.Arial
style := fontstyle.Bold

fpdf := &mocks.Fpdf{}
fpdf := mocks.NewFpdf(t)
fpdf.EXPECT().SetFont(family, string(style), size)
fpdf.EXPECT().SetFont(fontfamily.Helvetica, string(style), size)
font := gofpdf.NewFont(fpdf, size, family, style)
Expand All @@ -75,7 +75,7 @@ func TestFont_SetStyle(t *testing.T) {
family := fontfamily.Arial
style := fontstyle.Bold

fpdf := &mocks.Fpdf{}
fpdf := mocks.NewFpdf(t)
fpdf.EXPECT().SetFont(family, string(style), size)
fpdf.EXPECT().SetFontStyle(string(fontstyle.BoldItalic))
font := gofpdf.NewFont(fpdf, size, family, style)
Expand All @@ -93,7 +93,7 @@ func TestFont_SetSize(t *testing.T) {
family := fontfamily.Arial
style := fontstyle.Bold

fpdf := &mocks.Fpdf{}
fpdf := mocks.NewFpdf(t)
fpdf.EXPECT().SetFont(family, string(style), size)
fpdf.EXPECT().SetFontSize(14.0)
font := gofpdf.NewFont(fpdf, size, family, style)
Expand All @@ -112,7 +112,7 @@ func TestFont_SetColor(t *testing.T) {
family := fontfamily.Arial
style := fontstyle.Bold

fpdf := &mocks.Fpdf{}
fpdf := mocks.NewFpdf(t)
fpdf.EXPECT().SetFont(family, string(style), size)
font := gofpdf.NewFont(fpdf, size, family, style)
color := &props.Color{Red: 0, Green: 0, Blue: 0}
Expand All @@ -129,7 +129,7 @@ func TestFont_SetColor(t *testing.T) {
family := fontfamily.Arial
style := fontstyle.Bold

fpdf := &mocks.Fpdf{}
fpdf := mocks.NewFpdf(t)
fpdf.EXPECT().SetFont(family, string(style), size)
fpdf.EXPECT().SetTextColor(200, 200, 200)
font := gofpdf.NewFont(fpdf, size, family, style)
Expand Down
10 changes: 5 additions & 5 deletions internal/providers/gofpdf/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func TestNewImage(t *testing.T) {
image := gofpdf2.NewImage(&mocks.Fpdf{}, &mocks.Math{})
image := gofpdf2.NewImage(mocks.NewFpdf(t), mocks.NewMath(t))

assert.NotNil(t, image)
assert.Equal(t, fmt.Sprintf("%T", image), "*gofpdf.image")
Expand All @@ -35,10 +35,10 @@ func TestImage_Add(t *testing.T) {
ImageType: string(img.Extension),
}

pdf := &mocks.Fpdf{}
pdf := mocks.NewFpdf(t)
pdf.EXPECT().RegisterImageOptionsReader(mock.Anything, options, bytes.NewReader(img.Bytes)).Return(nil)

image := gofpdf2.NewImage(pdf, &mocks.Math{})
image := gofpdf2.NewImage(pdf, mocks.NewMath(t))

// Act
err := image.Add(&img, &cell, &margins, &rect, img.Extension, true)
Expand All @@ -57,7 +57,7 @@ func TestImage_Add(t *testing.T) {
ImageType: string(img.Extension),
}

pdf := &mocks.Fpdf{}
pdf := mocks.NewFpdf(t)
pdf.EXPECT().RegisterImageOptionsReader(mock.Anything, options, bytes.NewReader(img.Bytes)).Return(&gofpdf.ImageInfoType{})
pdf.EXPECT().Image(mock.Anything, 30.0, 35.0, 98.0, mock.Anything, true, "", 0, "")

Expand All @@ -83,7 +83,7 @@ func TestImage_Add(t *testing.T) {
ImageType: string(img.Extension),
}

pdf := &mocks.Fpdf{}
pdf := mocks.NewFpdf(t)
pdf.EXPECT().RegisterImageOptionsReader(mock.Anything, options, bytes.NewReader(img.Bytes)).Return(&gofpdf.ImageInfoType{})
pdf.EXPECT().Image(mock.Anything, 21.0, mock.Anything, 98.0, mock.Anything, true, "", 0, "")

Expand Down
Loading

0 comments on commit 727147b

Please sign in to comment.