Skip to content

Commit

Permalink
change api service name (#20)
Browse files Browse the repository at this point in the history
Co-authored-by: Trevor Johnson <tjohnson@axway.com>
  • Loading branch information
tsjohns9 and Trevor Johnson authored Apr 30, 2021
1 parent 22e2581 commit a60d014
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
14 changes: 4 additions & 10 deletions pkg/discovery/publish.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions pkg/discovery/publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
4 changes: 1 addition & 3 deletions pkg/traceability/eventmapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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).
Expand Down
35 changes: 35 additions & 0 deletions pkg/traceability/eventmapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
4 changes: 1 addition & 3 deletions pkg/traceability/eventprocessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a60d014

Please sign in to comment.