Skip to content

Commit

Permalink
Fix adding connected app label (#2306)
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymongib committed Jan 16, 2019
1 parent 8d2af79 commit a8ea14a
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 4 deletions.
Expand Up @@ -279,10 +279,7 @@ func apiDefined(serviceDefinition *model.ServiceDefinition) bool {
}

func overrideLabels(application string, labels map[string]string) map[string]string {
_, found := labels[connectedApp]
if found {
labels[connectedApp] = application
}
labels[connectedApp] = application

return labels
}
Expand Up @@ -316,6 +316,51 @@ func TestServiceDefinitionService_Create(t *testing.T) {
specService.AssertExpectations(t)
})

t.Run("should add connected-app label if not provided", func(t *testing.T) {
// given
serviceDefinition := model.ServiceDefinition{
Name: "Some service",
Description: "Some cool service",
Provider: "Service Provider",
Labels: &map[string]string{"test": "test"},
Api: nil,
Events: nil,
Documentation: nil,
}

applicationService := applications.Service{
ID: "uuid-1",
DisplayName: "Some service",
LongDescription: "Some cool service",
ShortDescription: "Some cool service",
ProviderDisplayName: "Service Provider",
Labels: map[string]string{"connected-app": "app", "test": "test"},
Tags: make([]string, 0),
API: nil,
Events: false,
}

uuidGenerator := new(uuidmocks.Generator)
uuidGenerator.On("NewUUID").Return("uuid-1")
serviceRepository := new(applicationsmocks.ServiceRepository)
serviceRepository.On("Create", "app", applicationService).Return(nil)
specService := new(specmocks.Service)
specService.On("PutSpec", &serviceDefinition, "").Return(nil)

service := NewServiceDefinitionService(uuidGenerator, nil, serviceRepository, specService)

// when
serviceID, err := service.Create("app", &serviceDefinition)

// then
require.NoError(t, err)
assert.Equal(t, "uuid-1", serviceID)

uuidGenerator.AssertExpectations(t)
serviceRepository.AssertExpectations(t)
specService.AssertExpectations(t)
})

t.Run("should return error when adding API fails", func(t *testing.T) {
// given
serviceAPI := &model.API{
Expand Down
44 changes: 44 additions & 0 deletions tests/application-registry-tests/test/apitests/metadata_test.go
Expand Up @@ -220,6 +220,50 @@ func TestApiMetadata(t *testing.T) {
require.Equal(t, http.StatusNoContent, statusCode)
})

t.Run("should register service adding connected-app label to the existing", func(t *testing.T) {
// when
initialServiceDefinition := prepareServiceDetails("service-identifier-4", map[string]string{"test": "test"}).WithAPI(oauthAPI)

statusCode, postResponseData, err := metadataServiceClient.CreateService(t, initialServiceDefinition)
require.NoError(t, err)

// then
require.Equal(t, http.StatusOK, statusCode)
require.NotEmpty(t, postResponseData.ID)

// when
statusCode, receivedServiceDefinition, err := metadataServiceClient.GetService(t, postResponseData.ID)
require.NoError(t, err)
expectedLabels := map[string]string{"test": "test", connectedApp: dummyApp.Name}
expectedServiceDefinition := getExpectedDefinition(initialServiceDefinition, expectedLabels, receivedServiceDefinition.Identifier)

// then
require.Equal(t, http.StatusOK, statusCode)
require.EqualValues(t, expectedServiceDefinition, *receivedServiceDefinition)

// when
statusCode, existingServices, err := metadataServiceClient.GetAllServices(t)
require.NoError(t, err)

postedService := findPostedService(existingServices, postResponseData.ID)

// then
require.Equal(t, http.StatusOK, statusCode)
require.NotNil(t, postedService)
require.Equal(t, "test service", postedService.Name)
require.Equal(t, "service provider", postedService.Provider)
require.Equal(t, "service description", postedService.Description)
require.True(t, strings.HasPrefix(postedService.Identifier, "service-identifier-4"))
require.Equal(t, expectedLabels, postedService.Labels)

// clean up
statusCode, err = metadataServiceClient.DeleteService(t, postResponseData.ID)
require.NoError(t, err)
initialServiceDefinition.Labels = map[string]string{}

require.Equal(t, http.StatusNoContent, statusCode)
})

t.Run("should register service modifying swagger api spec", func(t *testing.T) {
// when
initialServiceDefinition := prepareServiceDetails("service-identifier-5", map[string]string{"connected-app": dummyApp.Name}).WithAPI(swaggerSpecAPI)
Expand Down

0 comments on commit a8ea14a

Please sign in to comment.