-
-
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.
minor: rafactoring and adding some tests
- Loading branch information
1 parent
b409e8f
commit 9caeb85
Showing
11 changed files
with
390 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
with-expecter: true | ||
packages: | ||
renatoaraujo/uk-visa-sponsors/internal/sponsors: | ||
config: | ||
all: True | ||
dir: "{{.InterfaceDirRelative}}/mocks" | ||
outpkg: "mocks_test" | ||
filename: "{{.InterfaceName}}.go" | ||
mockname: "{{.InterfaceName}}" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package cmd | ||
package commands | ||
|
||
import ( | ||
"os" | ||
|
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,9 @@ | ||
package main | ||
|
||
import ( | ||
"renatoaraujo/uk-visa-sponsors/cmd/cli/commands" | ||
) | ||
|
||
func main() { | ||
commands.Execute() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package sponsors_test | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"renatoaraujo/uk-visa-sponsors/internal/sponsors" | ||
mocks "renatoaraujo/uk-visa-sponsors/internal/sponsors/mocks" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewHandler(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
load bool | ||
fetcherSetup func(client *mocks.Fetcher) | ||
processorSetup func(client *mocks.Processor) | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "Successfully initialise Handler without preloading data", | ||
load: false, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Successfully to initialise Handler preloading data", | ||
load: true, | ||
fetcherSetup: func(client *mocks.Fetcher) { | ||
client.On("FetchDataSource").Return( | ||
"datasource", | ||
nil, | ||
) | ||
client.On("FetchData", mock.Anything).Return( | ||
[]byte("some primitive data"), | ||
nil, | ||
) | ||
}, | ||
processorSetup: func(client *mocks.Processor) { | ||
client.On("ProcessRawData", mock.Anything).Return( | ||
[]map[string]string{ | ||
{ | ||
"Organisation Name": "Awesome company", | ||
"Route": "Skilled Worker Visa", | ||
}, | ||
}, | ||
nil, | ||
) | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Failed to initialise Handler preloading due to failure on fetching data", | ||
load: true, | ||
fetcherSetup: func(client *mocks.Fetcher) { | ||
client.On("FetchDataSource").Return( | ||
"datasource", | ||
nil, | ||
) | ||
client.On("FetchData", mock.Anything).Return( | ||
nil, | ||
errors.New("failed to fetch data"), | ||
) | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "Failed to initialise Handler preloading due to failure on processing raw data", | ||
load: true, | ||
fetcherSetup: func(client *mocks.Fetcher) { | ||
client.On("FetchDataSource").Return( | ||
"datasource", | ||
nil, | ||
) | ||
client.On("FetchData", mock.Anything).Return( | ||
[]byte("some primitive data"), | ||
nil, | ||
) | ||
}, | ||
processorSetup: func(client *mocks.Processor) { | ||
client.On("ProcessRawData", mock.Anything).Return( | ||
nil, | ||
errors.New("failed to process data"), | ||
) | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
|
||
fetcherMock := &mocks.Fetcher{} | ||
if tt.fetcherSetup != nil { | ||
tt.fetcherSetup(fetcherMock) | ||
} | ||
|
||
processorMock := &mocks.Processor{} | ||
if tt.processorSetup != nil { | ||
tt.processorSetup(processorMock) | ||
} | ||
|
||
handler, err := sponsors.NewHandler(fetcherMock, processorMock, tt.load) | ||
if tt.wantErr { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
|
||
if handler != nil { | ||
assert.IsType(t, &sponsors.Handler{}, handler) | ||
} | ||
|
||
mock.AssertExpectationsForObjects(t, fetcherMock) | ||
mock.AssertExpectationsForObjects(t, processorMock) | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.