Skip to content

Commit

Permalink
Test cases added for name config property in configuration_metadata_t…
Browse files Browse the repository at this point in the history
…est.go
  • Loading branch information
AamnaZahid authored and anthonydahanne committed Oct 23, 2024
1 parent 00998bd commit eb32c22
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions boot/configuration_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,77 @@ import (
"github.com/paketo-buildpacks/spring-boot/v5/boot"
)

func testConfigurationMetadata(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect

path string
)

it.Before(func() {
var err error

path, err = ioutil.TempDir("", "configuration-metadata")
Expect(err).NotTo(HaveOccurred())
})

it.After(func() {
Expect(os.RemoveAll(path)).To(Succeed())
})

context("from path", func() {
// ... (existing test cases)

it("returns dataflow decoded contents with names", func() {
Expect(os.MkdirAll(filepath.Join(path, "META-INF"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "META-INF", "spring-configuration-metadata.json"),
[]byte(`{ "properties": [ { "name": "alpha", "sourceType": "alpha" } ] }`), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "META-INF", "dataflow-configuration-metadata.properties"),
[]byte("configuration-properties.names=alpha"), 0644)).To(Succeed())

cm, err := boot.NewConfigurationMetadataFromPath(path)
Expect(err).NotTo(HaveOccurred())

Expect(boot.NewDataFlowConfigurationMetadata(path, cm)).To(Equal(boot.ConfigurationMetadata{
Properties: []boot.Property{{Name: "alpha", SourceType: "alpha"}},
}))
})

it("returns combined dataflow decoded contents with classes and names", func() {
Expect(os.MkdirAll(filepath.Join(path, "META-INF"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "META-INF", "spring-configuration-metadata.json"),
[]byte(`{ "groups": [ { "name": "alpha", "sourceType": "alpha" }, { "name": "beta", "sourceType": "beta" } ] }`), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "META-INF", "dataflow-configuration-metadata.properties"),
[]byte("configuration-properties.classes=alpha\nconfiguration-properties.names=beta"), 0644)).To(Succeed())

cm, err := boot.NewConfigurationMetadataFromPath(path)
Expect(err).NotTo(HaveOccurred())

Expect(boot.NewDataFlowConfigurationMetadata(path, cm)).To(Equal(boot.ConfigurationMetadata{
Groups: []boot.Group{
{Name: "alpha", SourceType: "alpha"},
{Name: "beta", SourceType: "beta"},
},
}))
})

it("handles empty names gracefully", func() {
Expect(os.MkdirAll(filepath.Join(path, "META-INF"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "META-INF", "spring-configuration-metadata.json"),
[]byte(`{ "properties": [ { "name": "alpha", "sourceType": "alpha" } ] }`), 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(path, "META-INF", "dataflow-configuration-metadata.properties"),
[]byte("configuration-properties.names="), 0644)).To(Succeed())

cm, err := boot.NewConfigurationMetadataFromPath(path)
Expect(err).NotTo(HaveOccurred())

Expect(boot.NewDataFlowConfigurationMetadata(path, cm)).To(Equal(boot.ConfigurationMetadata{
Properties: []boot.Property{{Name: "alpha", SourceType: "alpha"}},
}))
})
})


func testConfigurationMetadata(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
Expand Down

0 comments on commit eb32c22

Please sign in to comment.