Skip to content

Commit

Permalink
chore: test application packages
Browse files Browse the repository at this point in the history
Signed-off-by: maxwellgithinji <maxwellgithinji@gmail.com>
  • Loading branch information
maxwellgithinji committed Mar 14, 2023
1 parent cf8b67b commit e16454c
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 // indirect
github.com/ttacon/libphonenumber v1.2.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
Expand Down
65 changes: 65 additions & 0 deletions pkg/clinical/application/common/common_test.go
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 pkg/clinical/application/common/helpers/isc_helper_test.go
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) })
}
})
}
}
28 changes: 28 additions & 0 deletions pkg/clinical/application/utils/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,31 @@ func TestReportErrorToSentry(t *testing.T) {
})
}
}

func TestAddPubSubNamespace(t *testing.T) {
type args struct {
topicName string
serviceName string
}
tests := []struct {
name string
args args
want string
}{
{
name: "Happy case: add pubsub namespace",
args: args{
topicName: "test",
serviceName: "service",
},
want: "service-test-staging-v1",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := AddPubSubNamespace(tt.args.topicName, tt.args.serviceName); got != tt.want {
t.Errorf("AddPubSubNamespace() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit e16454c

Please sign in to comment.