func (im *InvokerManager) isInvokerOnboarded(newInvoker invokerapi.APIInvokerEnrolmentDetails) bool {
for _, invoker := range im.onboardedInvokers {
- if newInvoker.OnboardingInformation.ApiInvokerPublicKey == invoker.OnboardingInformation.ApiInvokerPublicKey {
+ if invoker.IsOnboarded(newInvoker) {
return true
}
}
return nil
}
+
+func (ied *APIInvokerEnrolmentDetails) IsOnboarded(otherInvoker APIInvokerEnrolmentDetails) bool {
+ return ied.OnboardingInformation.ApiInvokerPublicKey == otherInvoker.OnboardingInformation.ApiInvokerPublicKey
+}
err = invokerUnderTest.Validate()
assert.Nil(t, err)
}
+
+func TestIsOnboarded(t *testing.T) {
+ publicKey := "publicKey"
+ invokerUnderTest := APIInvokerEnrolmentDetails{
+ OnboardingInformation: OnboardingInformation{
+ ApiInvokerPublicKey: publicKey,
+ },
+ }
+
+ otherInvoker := APIInvokerEnrolmentDetails{
+ OnboardingInformation: OnboardingInformation{
+ ApiInvokerPublicKey: "otherPublicKey",
+ },
+ }
+ assert.False(t, invokerUnderTest.IsOnboarded(otherInvoker))
+
+ otherInvoker.OnboardingInformation.ApiInvokerPublicKey = publicKey
+ assert.True(t, invokerUnderTest.IsOnboarded(otherInvoker))
+}
func (pm *ProviderManager) isProviderRegistered(newProvider provapi.APIProviderEnrolmentDetails) bool {
for _, prov := range pm.registeredProviders {
- if newProvider.RegSec == prov.RegSec {
+ if prov.IsRegistered(newProvider) {
return true
}
}
}
return nil
}
+
+func (pd APIProviderEnrolmentDetails) IsRegistered(otherProvider APIProviderEnrolmentDetails) bool {
+ return pd.RegSec == otherProvider.RegSec
+}
assert.Nil(t, providerDetailsUnderTest.Validate())
}
+func TestIsRegistered(t *testing.T) {
+ regSec := "regSec"
+ providerUnderTest := APIProviderEnrolmentDetails{
+ RegSec: regSec,
+ }
+
+ otherProvider := APIProviderEnrolmentDetails{
+ RegSec: "otherRegSec",
+ }
+ assert.False(t, providerUnderTest.IsRegistered(otherProvider))
+
+ otherProvider.RegSec = regSec
+ assert.True(t, providerUnderTest.IsRegistered(otherProvider))
+}
+
func getProvider() APIProviderEnrolmentDetails {
testFuncs := []APIProviderFunctionDetails{
{
func (ps *PublishService) isServicePublished(newService publishapi.ServiceAPIDescription) bool {
for _, services := range ps.publishedServices {
for _, service := range services {
- if newService.ApiName == service.ApiName {
+ if service.IsPublished(newService) {
return true
}
}
}
return nil
}
+
+func (sd ServiceAPIDescription) IsPublished(otherService ServiceAPIDescription) bool {
+ return sd.ApiName == otherService.ApiName
+}
assert.Nil(t, err)
}
+
+func TestIsServicePublished(t *testing.T) {
+ apiName := "apiName"
+ serviceUnderTest := ServiceAPIDescription{
+ ApiName: apiName,
+ }
+
+ otherService := ServiceAPIDescription{
+ ApiName: "otherApiName",
+ }
+ assert.False(t, serviceUnderTest.IsPublished(otherService))
+
+ otherService.ApiName = apiName
+ assert.True(t, serviceUnderTest.IsPublished(otherService))
+}