-
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.
Signed-off-by: maxwellgithinji <maxwellgithinji@gmail.com>
- Loading branch information
1 parent
cf8b67b
commit e16454c
Showing
4 changed files
with
131 additions
and
0 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
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,65 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/brianvoe/gofakeit" | ||
extMock "github.com/savannahghi/clinical/pkg/clinical/application/extensions/mock" | ||
"github.com/savannahghi/interserviceclient" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewInterServiceClient(t *testing.T) { | ||
type args struct { | ||
serviceName string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
panics bool | ||
}{ | ||
{ | ||
name: "Happy case: initialize service", | ||
args: args{ | ||
serviceName: gofakeit.Name(), | ||
}, | ||
panics: false, | ||
}, | ||
{ | ||
name: "Sad case: failed to load deps from yaml", | ||
args: args{ | ||
serviceName: gofakeit.Name(), | ||
}, | ||
panics: true, | ||
}, | ||
{ | ||
name: "Sad case: failed load isc client", | ||
args: args{ | ||
serviceName: gofakeit.Name(), | ||
}, | ||
panics: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
fakeExt := extMock.NewFakeBaseExtensionMock() | ||
|
||
if tt.panics { | ||
if tt.name == "Sad case: failed to load deps from yaml" { | ||
fakeExt.LoadDepsFromYAMLFn = func() (*interserviceclient.DepsConfig, error) { | ||
return nil, fmt.Errorf("an error occurred") | ||
} | ||
} | ||
if tt.name == "Sad case: failed load isc client" { | ||
fakeExt.SetupISCclientFn = func(config interserviceclient.DepsConfig, serviceName string) (*interserviceclient.InterServiceClient, error) { | ||
return nil, fmt.Errorf("an error occurred") | ||
} | ||
} | ||
assert.Panics(t, func() { NewInterServiceClient(tt.args.serviceName, fakeExt) }) | ||
} else { | ||
assert.NotPanics(t, func() { NewInterServiceClient(tt.args.serviceName, fakeExt) }) | ||
} | ||
}) | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
pkg/clinical/application/common/helpers/isc_helper_test.go
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,37 @@ | ||
package helpers | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/brianvoe/gofakeit" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestInitializeInterServiceClient(t *testing.T) { | ||
type args struct { | ||
serviceName string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
panics bool | ||
}{ | ||
|
||
{ | ||
name: "Happy case", | ||
args: args{ | ||
serviceName: gofakeit.Name(), | ||
}, | ||
panics: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if tt.panics { | ||
assert.Panics(t, func() { _ = InitializeInterServiceClient(tt.args.serviceName) }) | ||
} else { | ||
assert.NotPanics(t, func() { _ = InitializeInterServiceClient(tt.args.serviceName) }) | ||
} | ||
}) | ||
} | ||
} |
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