Skip to content

Commit

Permalink
refactor: move related test files to their package
Browse files Browse the repository at this point in the history
  • Loading branch information
fyvri committed Dec 28, 2024
1 parent 9d8bc2d commit 7e9c026
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 142 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ func run(runners Runners) error {
go func(source entity.Source) {
defer wg.Done()

innerWG := sync.WaitGroup{}
proxies, err := sourceUsecase.ProcessSource(&source)
if err != nil {
return
}

innerWG := sync.WaitGroup{}
for _, proxy := range proxies {
innerWG.Add(1)
go func(source entity.Source, proxy string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package entity_test
package entity

import (
"encoding/json"
"strconv"
"testing"

"github.com/fyvri/fresh-proxy-list/internal/entity"
)

var (
Expand All @@ -19,7 +17,7 @@ var (

func TestUnmarshalJSONWithIsChecked(t *testing.T) {
var (
source = entity.Source{}
source = Source{}
data = []byte(`{
"method": "` + testMethod + `",
"category": "` + testCategory + `",
Expand Down Expand Up @@ -52,7 +50,7 @@ func TestUnmarshalJSONWithIsChecked(t *testing.T) {

func TestUnmarshalJSONWithoutIsChecked(t *testing.T) {
var (
source = entity.Source{}
source = Source{}
data = []byte(`{
"method": "` + testMethod + `",
"category": "` + testCategory + `",
Expand Down Expand Up @@ -84,7 +82,7 @@ func TestUnmarshalJSONWithoutIsChecked(t *testing.T) {

func TestUnmarshalJSONWithInvalidData(t *testing.T) {
var (
source = entity.Source{}
source = Source{}
data = []byte(`{
"method": "` + testMethod + `",
"category": "` + testCategory + `",
Expand All @@ -100,7 +98,7 @@ func TestUnmarshalJSONWithInvalidData(t *testing.T) {

func TestUnmarshalJSONWithEmptyData(t *testing.T) {
var (
source = entity.Source{}
source = Source{}
data = []byte(`{}`)
)
err := json.Unmarshal(data, &source)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package repository_test
package repository

import (
"bytes"
Expand All @@ -10,7 +10,6 @@ import (
"strings"
"testing"

"github.com/fyvri/fresh-proxy-list/internal/infrastructure/repository"
"github.com/fyvri/fresh-proxy-list/pkg/utils"
)

Expand All @@ -37,13 +36,13 @@ func TestNewFileRepository(t *testing.T) {
return &bytes.Buffer{}, nil
}
mockCSVWriterUtil := &mockCSVWriterUtil{}
fileRepository := repository.NewFileRepository(mockMkdirAll, mockCreate, mockCSVWriterUtil)
fileRepository := NewFileRepository(mockMkdirAll, mockCreate, mockCSVWriterUtil)

if fileRepository == nil {
t.Errorf(expectedReturnNonNil, "NewFileRepository", "FileRepositoryInterface")
}

r, ok := fileRepository.(*repository.FileRepository)
r, ok := fileRepository.(*FileRepository)
if !ok {
t.Errorf(expectedTypeAssertionErrorMessage, "*FileRepository")
}
Expand Down Expand Up @@ -435,7 +434,7 @@ func TestSaveFile(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r := &repository.FileRepository{
r := &FileRepository{
MkdirAll: tt.fields.mkdirAll,
Create: tt.fields.create,
CSVWriter: tt.fields.csvWriter,
Expand Down Expand Up @@ -517,7 +516,7 @@ func TestWriteCSV(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var buf bytes.Buffer
r := &repository.FileRepository{
r := &FileRepository{
CSVWriter: tt.fields.csvWriter,
}
err := r.WriteCSV(&buf, tt.args.header, tt.args.rows)
Expand Down
Loading

0 comments on commit 7e9c026

Please sign in to comment.