Skip to content

Commit

Permalink
Merge pull request #330 from OpsLevel/kr/parent-service
Browse files Browse the repository at this point in the history
Add parent system to service during create and update
  • Loading branch information
rocktavious authored Dec 12, 2023
2 parents 6fda227 + 29b241e commit 7895ee7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Feature-20231211-195315.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Feature
body: Add ability to set the parent system of a service during create or update
time: 2023-12-11T19:53:15.713772-06:00
2 changes: 2 additions & 0 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type ServiceCreateInput struct {
Tier string `json:"tierAlias,omitempty"`
Owner *IdentifierInput `json:"ownerInput,omitempty"`
Lifecycle string `json:"lifecycleAlias,omitempty"`
Parent *IdentifierInput `json:"parent,omitempty"`
}

type ServiceUpdateInput struct {
Expand All @@ -71,6 +72,7 @@ type ServiceUpdateInput struct {
Tier string `json:"tierAlias,omitempty"`
Owner *IdentifierInput `json:"ownerInput,omitempty"`
Lifecycle string `json:"lifecycleAlias,omitempty"`
Parent *IdentifierInput `json:"parent,omitempty"`
}

type ServiceDeleteInput struct {
Expand Down
40 changes: 40 additions & 0 deletions service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,25 @@ func TestCreateService(t *testing.T) {
autopilot.Equals(t, 1, len(result.Aliases))
}

func TestCreateServiceWithParentSystem(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation ServiceCreate($input:ServiceCreateInput!){serviceCreate(input: $input){service{apiDocumentPath,description,framework,htmlUrl,id,aliases,language,lifecycle{alias,description,id,index,name},managedAliases,name,owner{alias,id},preferredApiDocument{id,htmlUrl,source{... on ApiDocIntegration{id,name,type},... on ServiceRepository{baseDirectory,displayName,id,repository{id,defaultAlias},service{id,aliases}}},timestamps{createdAt,updatedAt}},preferredApiDocumentSource,product,repos{edges{node{id,defaultAlias},serviceRepositories{baseDirectory,displayName,id,repository{id,defaultAlias},service{id,aliases}}},{{ template "pagination_request" }},totalCount},tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount},tier{alias,description,id,index,name},timestamps{createdAt,updatedAt},tools{nodes{category,categoryAlias,displayName,environment,id,url,service{id,aliases}},{{ template "pagination_request" }},totalCount}},errors{message,path}}}`,
`{ "input": { "name": "Foo", "description": "Foo service", "parent": {"alias": "FooSystem"} } }`,
`{ "data": { "serviceCreate": { "service": {{ template "service_1" }}, "errors": [] } }}`,
)
client := BestTestClient(t, "service/create_with_system", testRequest)
// Act
result, err := client.CreateService(ol.ServiceCreateInput{
Name: "Foo",
Description: "Foo service",
Parent: ol.NewIdentifier("FooSystem"),
})
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, 1, len(result.Aliases))
}

func TestUpdateService(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
Expand All @@ -264,6 +283,27 @@ func TestUpdateService(t *testing.T) {
autopilot.Equals(t, "Foo", result.Name)
}

func TestUpdateServiceWithSystem(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation ServiceUpdate($input:ServiceUpdateInput!){serviceUpdate(input: $input){service{apiDocumentPath,description,framework,htmlUrl,id,aliases,language,lifecycle{alias,description,id,index,name},managedAliases,name,owner{alias,id},preferredApiDocument{id,htmlUrl,source{... on ApiDocIntegration{id,name,type},... on ServiceRepository{baseDirectory,displayName,id,repository{id,defaultAlias},service{id,aliases}}},timestamps{createdAt,updatedAt}},preferredApiDocumentSource,product,repos{edges{node{id,defaultAlias},serviceRepositories{baseDirectory,displayName,id,repository{id,defaultAlias},service{id,aliases}}},{{ template "pagination_request" }},totalCount},tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount},tier{alias,description,id,index,name},timestamps{createdAt,updatedAt},tools{nodes{category,categoryAlias,displayName,environment,id,url,service{id,aliases}},{{ template "pagination_request" }},totalCount}},errors{message,path}}}`,
`{"input":{"id": "123456789", "parent": {"alias": "FooSystem"}}}`,
`{"data": {"serviceUpdate": { "service": {{ template "service_1" }}, "errors": [] }}}`,
)

client := BestTestClient(t, "service/update_with_system", testRequest)

// Act
result, err := client.UpdateService(ol.ServiceUpdateInput{
Id: "123456789",
Parent: ol.NewIdentifier("FooSystem"),
})

// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, "Foo", result.Name)
}

func TestGetServiceIdWithAlias(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
Expand Down

0 comments on commit 7895ee7

Please sign in to comment.