Skip to content

Commit

Permalink
#222 add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
KRaffael committed Nov 2, 2023
1 parent b8e2142 commit 81ee301
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions internal/service/services/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,41 @@ func tstCurrent() openapi.ServiceDto {
}
}

func tstCurrentSpec() openapi.ServiceDto {
return openapi.ServiceDto{
Owner: "owner",
Quicklinks: []openapi.Quicklink{
{
Url: p("url"),
Title: p("title"),
Description: p("desc"),
},
},
Repositories: []string{"repo1", "repo2"},
AlertTarget: "target",
DevelopmentOnly: b(true),
OperationType: p("PLATFORM"),
TimeStamp: "ts",
CommitHash: "hash",
Lifecycle: p("experimental"),
Spec: &openapi.ServiceSpecDto{
DependsOn: []string{"other-domain"},
ProvidesApis: []string{"some-other-api"},
ConsumesApis: []string{"other-api"},
},
}
}

func tstPatchService(t *testing.T, patch openapi.ServicePatchDto, expected openapi.ServiceDto) {
actual := patchService(tstCurrent(), patch)
require.Equal(t, expected, actual)
}

func tstPatchServiceSpec(t *testing.T, patch openapi.ServicePatchDto, expected openapi.ServiceDto) {
actual := patchService(tstCurrentSpec(), patch)
require.Equal(t, expected, actual)
}

func TestPatchService_EmptyPatch(t *testing.T) {
docs.Description("patching of services works with an empty patch")
expected := tstCurrent()
Expand Down Expand Up @@ -120,6 +150,52 @@ func TestPatchService_ClearFields(t *testing.T) {
})
}

func TestPatchServiceSpec_EmptyPatch(t *testing.T) {
docs.Description("patching of service spec with an empty patch")
expected := tstCurrent()
tstPatchService(t, openapi.ServicePatchDto{
TimeStamp: "ts",
CommitHash: "hash",
}, expected)
}

func TestPatchServiceSpec_ReplaceAll(t *testing.T) {
docs.Description("patching of service spec with an empty patch")
expected := tstCurrent()
expected.Spec = &openapi.ServiceSpecDto{
DependsOn: []string{"some-domain"},
ProvidesApis: []string{"some-other-api"},
ConsumesApis: []string{"some-api"},
}
tstPatchService(t, openapi.ServicePatchDto{
TimeStamp: "ts",
CommitHash: "hash",
Spec: &openapi.ServiceSpecDto{
DependsOn: []string{"some-domain"},
ProvidesApis: []string{"some-other-api"},
ConsumesApis: []string{"some-api"},
},
}, expected)
}

func TestPatchServiceSpec_ReplaceSpecific(t *testing.T) {
docs.Description("patching of service spec with an empty patch")
expected := tstCurrent()
expected.Spec = &openapi.ServiceSpecDto{
DependsOn: []string{"some-domain"},
ConsumesApis: []string{"some-api"},
}
tstPatchServiceSpec(t, openapi.ServicePatchDto{
TimeStamp: "ts",
CommitHash: "hash",
Spec: &openapi.ServiceSpecDto{
DependsOn: []string{"some-domain"},
ProvidesApis: []string{},
ConsumesApis: []string{"some-api"},
},
}, expected)
}

func tstValid() openapi.ServiceDto {
description := "short service description"
return openapi.ServiceDto{
Expand Down

0 comments on commit 81ee301

Please sign in to comment.