Skip to content

Commit

Permalink
rename mock_app => mock_appauth
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Nov 21, 2022
1 parent 0445418 commit 28b7b4b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion internal/app/appauth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/rusq/slackdump/v2/internal/encio"
)

//go:generate mockgen -source=auth.go -destination=../../mocks/mock_app/mock_app.go Credentials,createOpener
//go:generate mockgen -source=auth.go -destination=../../mocks/mock_appauth/mock_appauth.go Credentials,createOpener
//go:generate mockgen -destination=../../mocks/mock_io/mock_io.go io ReadCloser,WriteCloser

// isWSL is true if we're running in the WSL environment
Expand Down
38 changes: 19 additions & 19 deletions internal/app/appauth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/assert"

"github.com/rusq/slackdump/v2/auth"
"github.com/rusq/slackdump/v2/internal/mocks/mock_app"
"github.com/rusq/slackdump/v2/internal/mocks/mock_appauth"
"github.com/rusq/slackdump/v2/internal/mocks/mock_io"
)

Expand Down Expand Up @@ -132,15 +132,15 @@ func TestInitProvider(t *testing.T) {
tests := []struct {
name string
args args
expect func(m *mock_app.MockCredentials)
expect func(m *mock_appauth.MockCredentials)
authTestErr error
want auth.Provider
wantErr bool
}{
{
"empty creds, no errors",
args{context.Background(), testDir, "wsp"},
func(m *mock_app.MockCredentials) {
func(m *mock_appauth.MockCredentials) {
m.EXPECT().IsEmpty().Return(false)
m.EXPECT().
AuthProvider(gomock.Any(), "wsp").
Expand All @@ -153,7 +153,7 @@ func TestInitProvider(t *testing.T) {
{
"creds empty, tryLoad succeeds",
args{context.Background(), testDir, "wsp"},
func(m *mock_app.MockCredentials) {
func(m *mock_appauth.MockCredentials) {
m.EXPECT().IsEmpty().Return(true)
},
nil,
Expand All @@ -163,7 +163,7 @@ func TestInitProvider(t *testing.T) {
{
"creds empty, tryLoad fails",
args{context.Background(), testDir, "wsp"},
func(m *mock_app.MockCredentials) {
func(m *mock_appauth.MockCredentials) {
m.EXPECT().IsEmpty().Return(true)
m.EXPECT().AuthProvider(gomock.Any(), "wsp").Return(returnedProv, nil)
},
Expand All @@ -174,7 +174,7 @@ func TestInitProvider(t *testing.T) {
{
"creds non-empty, provider failed",
args{context.Background(), testDir, "wsp"},
func(m *mock_app.MockCredentials) {
func(m *mock_appauth.MockCredentials) {
m.EXPECT().IsEmpty().Return(false)
m.EXPECT().AuthProvider(gomock.Any(), "wsp").Return(nil, errors.New("authProvider failed"))
},
Expand All @@ -185,7 +185,7 @@ func TestInitProvider(t *testing.T) {
{
"creds non-empty, provider succeeds, save succeeds",
args{context.Background(), testDir, "wsp"},
func(m *mock_app.MockCredentials) {
func(m *mock_appauth.MockCredentials) {
m.EXPECT().IsEmpty().Return(false)
m.EXPECT().AuthProvider(gomock.Any(), "wsp").Return(returnedProv, nil)
},
Expand All @@ -196,7 +196,7 @@ func TestInitProvider(t *testing.T) {
{
"creds non-empty, provider succeeds, save fails",
args{context.Background(), t.TempDir() + "$", "wsp"},
func(m *mock_app.MockCredentials) {
func(m *mock_appauth.MockCredentials) {
m.EXPECT().IsEmpty().Return(false)
m.EXPECT().AuthProvider(gomock.Any(), "wsp").Return(returnedProv, nil)
},
Expand All @@ -220,7 +220,7 @@ func TestInitProvider(t *testing.T) {
t.Fatal(err)
}

mc := mock_app.NewMockCredentials(gomock.NewController(t))
mc := mock_appauth.NewMockCredentials(gomock.NewController(t))
tt.expect(mc)

// test
Expand Down Expand Up @@ -313,14 +313,14 @@ func Test_loadCreds(t *testing.T) {
tests := []struct {
name string
args args
expect func(mco *mock_app.MockcreateOpener, mrc *mock_io.MockReadCloser)
expect func(mco *mock_appauth.MockcreateOpener, mrc *mock_io.MockReadCloser)
want auth.Provider
wantErr bool
}{
{
"all ok",
args{"fakefile.ext"},
func(mco *mock_app.MockcreateOpener, mrc *mock_io.MockReadCloser) {
func(mco *mock_appauth.MockcreateOpener, mrc *mock_io.MockReadCloser) {
readCall := mrc.EXPECT().
Read(gomock.Any()).
DoAndReturn(func(b []byte) (int, error) {
Expand All @@ -338,7 +338,7 @@ func Test_loadCreds(t *testing.T) {
{
"auth.Read error",
args{"fakefile.ext"},
func(mco *mock_app.MockcreateOpener, mrc *mock_io.MockReadCloser) {
func(mco *mock_appauth.MockcreateOpener, mrc *mock_io.MockReadCloser) {
readCall := mrc.EXPECT().
Read(gomock.Any()).
Return(0, errors.New("auth.Read error"))
Expand All @@ -354,7 +354,7 @@ func Test_loadCreds(t *testing.T) {
{
"read error",
args{"fakefile.ext"},
func(mco *mock_app.MockcreateOpener, mrc *mock_io.MockReadCloser) {
func(mco *mock_appauth.MockcreateOpener, mrc *mock_io.MockReadCloser) {
mco.EXPECT().
Open("fakefile.ext").
Return(nil, errors.New("it was at this moment that test framework knew: it fucked up"))
Expand All @@ -366,7 +366,7 @@ func Test_loadCreds(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctrl := gomock.NewController(t)
mco := mock_app.NewMockcreateOpener(ctrl)
mco := mock_appauth.NewMockcreateOpener(ctrl)
mrc := mock_io.NewMockReadCloser(ctrl)
tt.expect(mco, mrc)

Expand Down Expand Up @@ -398,13 +398,13 @@ func Test_saveCreds(t *testing.T) {
tests := []struct {
name string
args args
expect func(m *mock_app.MockcreateOpener, mwc *mock_io.MockWriteCloser)
expect func(m *mock_appauth.MockcreateOpener, mwc *mock_io.MockWriteCloser)
wantErr bool
}{
{
"all ok",
args{filename: "filename.ext", p: testProv},
func(m *mock_app.MockcreateOpener, mwc *mock_io.MockWriteCloser) {
func(m *mock_appauth.MockcreateOpener, mwc *mock_io.MockWriteCloser) {
wc := mwc.EXPECT().Write(testProvBytes).Return(len(testProvBytes), nil)
mwc.EXPECT().Close().After(wc).Return(nil)

Expand All @@ -415,15 +415,15 @@ func Test_saveCreds(t *testing.T) {
{
"create fails",
args{filename: "filename.ext", p: testProv},
func(m *mock_app.MockcreateOpener, mwc *mock_io.MockWriteCloser) {
func(m *mock_appauth.MockcreateOpener, mwc *mock_io.MockWriteCloser) {
m.EXPECT().Create("filename.ext").Return(nil, errors.New("create fail"))
},
true,
},
{
"write fails",
args{filename: "filename.ext", p: testProv},
func(m *mock_app.MockcreateOpener, mwc *mock_io.MockWriteCloser) {
func(m *mock_appauth.MockcreateOpener, mwc *mock_io.MockWriteCloser) {
wc := mwc.EXPECT().Write(testProvBytes).Return(0, errors.New("write fail"))
mwc.EXPECT().Close().After(wc).Return(nil)

Expand All @@ -435,7 +435,7 @@ func Test_saveCreds(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctrl := gomock.NewController(t)
mco := mock_app.NewMockcreateOpener(ctrl)
mco := mock_appauth.NewMockcreateOpener(ctrl)
mwc := mock_io.NewMockWriteCloser(ctrl)
tt.expect(mco, mwc)

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 28b7b4b

Please sign in to comment.