From a60d0147b715e21473503b57a1c3be2950229261 Mon Sep 17 00:00:00 2001 From: Trevor Johnson Date: Fri, 30 Apr 2021 12:06:47 -0700 Subject: [PATCH] change api service name (#20) Co-authored-by: Trevor Johnson --- pkg/discovery/publish.go | 14 +++------- pkg/discovery/publish_test.go | 4 +-- pkg/traceability/eventmapper.go | 4 +-- pkg/traceability/eventmapper_test.go | 35 +++++++++++++++++++++++++ pkg/traceability/eventprocessor_test.go | 4 +-- 5 files changed, 43 insertions(+), 18 deletions(-) diff --git a/pkg/discovery/publish.go b/pkg/discovery/publish.go index a514e28..fd70b94 100644 --- a/pkg/discovery/publish.go +++ b/pkg/discovery/publish.go @@ -1,8 +1,6 @@ package discovery import ( - "fmt" - "github.com/Axway/agent-sdk/pkg/agent" "github.com/Axway/agent-sdk/pkg/apic" "github.com/Axway/agent-sdk/pkg/util/log" @@ -31,7 +29,7 @@ func (a *Agent) publishLoop() { func (a *Agent) publish(serviceDetail *ServiceDetail) error { log.Infof("Publishing API \"%s (%s)\" to Amplify Central", serviceDetail.APIName, serviceDetail.ID) - serviceBody, err := buildServiceBody(serviceDetail) + serviceBody, err := BuildServiceBody(serviceDetail) if err != nil { log.Errorf("Error building service body for API \"%s (%s)\": %s", serviceDetail.APIName, serviceDetail.ID, err.Error()) return err @@ -45,8 +43,8 @@ func (a *Agent) publish(serviceDetail *ServiceDetail) error { return err } -// buildServiceBody - creates the service definition -func buildServiceBody(service *ServiceDetail) (apic.ServiceBody, error) { +// BuildServiceBody - creates the service definition +func BuildServiceBody(service *ServiceDetail) (apic.ServiceBody, error) { tags := map[string]interface{}{} if service.Tags != nil { for _, tag := range service.Tags { @@ -70,12 +68,8 @@ func buildServiceBody(service *ServiceDetail) (apic.ServiceBody, error) { SetStatus(service.Status). SetSubscriptionName(service.SubscriptionName). SetTags(tags). - SetTitle(FormatServiceTitle(service.Title, service.Version)). + SetTitle(service.Title). SetURL(service.URL). SetVersion(service.Version). Build() } - -func FormatServiceTitle(title, version string) string { - return fmt.Sprintf("%s (%s)", title, version) -} diff --git a/pkg/discovery/publish_test.go b/pkg/discovery/publish_test.go index 46f67ef..3b387db 100644 --- a/pkg/discovery/publish_test.go +++ b/pkg/discovery/publish_test.go @@ -45,7 +45,7 @@ func Test_buildServiceBody(t *testing.T) { URL: "https://petstore3.us-e2.cloudhub.io", Version: "1.0.0", } - apicSvc, err := buildServiceBody(sd) + apicSvc, err := BuildServiceBody(sd) assert.Nil(t, err) assert.Equal(t, sd.APIName, apicSvc.APIName) assert.Equal(t, sd.APISpec, apicSvc.SpecDefinition) @@ -62,7 +62,7 @@ func Test_buildServiceBody(t *testing.T) { assert.Equal(t, sd.Status, apicSvc.Status) assert.Equal(t, sd.SubscriptionName, apicSvc.SubscriptionName) assert.Equal(t, map[string]interface{}{"tag1": true}, apicSvc.Tags) - assert.Equal(t, FormatServiceTitle(sd.Title, sd.Version), apicSvc.NameToPush) + assert.Equal(t, sd.Title, apicSvc.NameToPush) assert.Equal(t, sd.URL, apicSvc.URL) assert.Equal(t, sd.Version, apicSvc.Version) } diff --git a/pkg/traceability/eventmapper.go b/pkg/traceability/eventmapper.go index adbf83a..29f47bf 100644 --- a/pkg/traceability/eventmapper.go +++ b/pkg/traceability/eventmapper.go @@ -6,8 +6,6 @@ import ( "net/http" "strconv" - "github.com/Axway/agents-mulesoft/pkg/discovery" - "github.com/Axway/agents-mulesoft/pkg/anypoint" "github.com/Axway/agent-sdk/pkg/agent" @@ -108,7 +106,7 @@ func (em *EventMapper) createSummaryEvent( return transaction.NewTransactionSummaryBuilder(). SetDuration(event.ResponseTime). SetEntryPoint("http", method, uri, host). - SetProxy(transaction.FormatProxyID(version), discovery.FormatServiceTitle(name, version), 1). + SetProxy(transaction.FormatProxyID(version), name, 1). SetStatus(getTransactionSummaryStatus(statusCode), strconv.Itoa(statusCode)). SetTeam(teamID). SetTransactionID(txID). diff --git a/pkg/traceability/eventmapper_test.go b/pkg/traceability/eventmapper_test.go index 35b2fd3..f63e247 100644 --- a/pkg/traceability/eventmapper_test.go +++ b/pkg/traceability/eventmapper_test.go @@ -4,6 +4,8 @@ import ( "testing" "time" + "github.com/Axway/agents-mulesoft/pkg/discovery" + "github.com/Axway/agent-sdk/pkg/transaction" "github.com/stretchr/testify/assert" @@ -105,3 +107,36 @@ func Test_buildHeaders(t *testing.T) { res := buildHeaders(h) assert.Equal(t, "{\"Authorization\":\"abc123\",\"User-Agent\":\"MulesoftTraceability\"}", res) } + +func Test_APIServiceNameAndTransactionProxyNameAreEqual(t *testing.T) { + sd := &discovery.ServiceDetail{ + APIName: "petstore-3", + APISpec: []byte("{\"openapi\":\"3.0.1\",\"servers\":[{\"url\":\"google.com\"}]}"), + APIUpdateSeverity: "", + AuthPolicy: "pass-through", + Description: "petstore api", + Documentation: nil, + ID: "211799904", + Image: "", + ImageContentType: "", + ResourceType: "oas3", + ServiceAttributes: nil, + Stage: "Sandbox", + State: "", + Status: "", + SubscriptionName: "", + Tags: nil, + Title: "petstore-3", + URL: "", + Version: "1.0.0", + } + body, err := discovery.BuildServiceBody(sd) + assert.Nil(t, err) + apiServiceName := body.NameToPush + + em := &EventMapper{} + le, err := em.createSummaryEvent(100, FormatTxnId(event.APIVersionID, event.MessageID), event, "123") + assert.Nil(t, err) + transactionProxyName := le.TransactionSummary.Proxy.Name + assert.Equal(t, apiServiceName, transactionProxyName) +} diff --git a/pkg/traceability/eventprocessor_test.go b/pkg/traceability/eventprocessor_test.go index 0b7d763..81b93d1 100644 --- a/pkg/traceability/eventprocessor_test.go +++ b/pkg/traceability/eventprocessor_test.go @@ -6,8 +6,6 @@ import ( "testing" "time" - "github.com/Axway/agents-mulesoft/pkg/discovery" - "github.com/Axway/agents-mulesoft/pkg/anypoint" "github.com/stretchr/testify/assert" @@ -61,7 +59,7 @@ func TestEventProcessor_ProcessRaw(t *testing.T) { assert.Equal(t, TeamID, summaryEvent.TransactionSummary.Team.ID) assert.Equal(t, transaction.FormatProxyID(event.APIVersionName), summaryEvent.TransactionSummary.Proxy.ID) assert.Equal(t, 1, summaryEvent.TransactionSummary.Proxy.Revision) - assert.Equal(t, discovery.FormatServiceTitle(event.APIName, event.APIVersionName), summaryEvent.TransactionSummary.Proxy.Name) + assert.Equal(t, event.APIName, summaryEvent.TransactionSummary.Proxy.Name) assert.Nil(t, summaryEvent.TransactionSummary.Runtime) assert.Equal(t, "http", summaryEvent.TransactionSummary.EntryPoint.Type) assert.Equal(t, event.Verb, summaryEvent.TransactionSummary.EntryPoint.Method)