github.com/cloudfoundry/postgres-release/src/acceptance-tests@v0.0.0-20240511030151-872bdd2e0dba/testing/helpers/properties_test.go (about) 1 package helpers_test 2 3 import ( 4 "github.com/cloudfoundry/postgres-release/src/acceptance-tests/testing/helpers" 5 6 . "github.com/onsi/ginkgo/v2" 7 . "github.com/onsi/gomega" 8 ) 9 10 var _ = Describe("Properties", func() { 11 Describe("Load Global properties", func() { 12 Context("With a valid input and default values", func() { 13 var props helpers.ManifestProperties 14 15 It("Corretly load all the data", func() { 16 var err error 17 var data = ` 18 databases: 19 port: 5524 20 databases: 21 - citext: true 22 name: sandbox 23 ` 24 err = props.LoadJobProperties("postgres", []byte(data)) 25 Expect(err).NotTo(HaveOccurred()) 26 expected := helpers.Properties{ 27 Databases: helpers.PgProperties{ 28 Port: 5524, 29 Databases: []helpers.PgDBProperties{ 30 {CITExt: true, 31 Name: "sandbox"}, 32 }, 33 MaxConnections: 500, 34 LogLinePrefix: "%m: ", 35 CollectStatementStats: false, 36 }, 37 } 38 Expect(props.GetJobProperties("postgres")).To(Equal([]helpers.Properties{expected})) 39 }) 40 }) 41 Context("With a valid input and no default values", func() { 42 var props helpers.ManifestProperties 43 44 BeforeEach(func() { 45 var err error 46 var data = ` 47 databases: 48 port: 5524 49 address: x.x.x.x 50 databases: 51 - citext: true 52 name: sandbox 53 - citext: true 54 name: sandbox2 55 roles: 56 - name: pgadmin 57 password: admin 58 - name: pgadmin2 59 password: admin 60 max_connections: 10 61 log_line_prefix: "%d" 62 collect_statement_statistics: true 63 monit_timeout: 120 64 additional_config: 65 max_wal_senders: 5 66 archive_timeout: 1800s 67 ` 68 err = props.LoadJobProperties("postgres", []byte(data)) 69 Expect(err).NotTo(HaveOccurred()) 70 }) 71 72 It("Correctly load all the data", func() { 73 m := make(helpers.PgAdditionalConfigMap) 74 m["archive_timeout"] = "1800s" 75 m["max_wal_senders"] = 5 76 expected := helpers.Properties{ 77 Databases: helpers.PgProperties{ 78 Port: 5524, 79 Databases: []helpers.PgDBProperties{ 80 {CITExt: true, 81 Name: "sandbox"}, 82 {CITExt: true, 83 Name: "sandbox2"}, 84 }, 85 Roles: []helpers.PgRoleProperties{ 86 {Password: "admin", 87 Name: "pgadmin"}, 88 {Password: "admin", 89 Name: "pgadmin2"}, 90 }, 91 MaxConnections: 10, 92 LogLinePrefix: "%d", 93 CollectStatementStats: true, 94 MonitTimeout: 120, 95 AdditionalConfig: m, 96 }, 97 } 98 Expect(props.GetJobProperties("postgres")).To(Equal([]helpers.Properties{expected})) 99 100 }) 101 }) 102 Context("With a invalid input", func() { 103 var props helpers.ManifestProperties 104 105 It("Fail to load the an invalid yaml", func() { 106 var err error 107 err = props.LoadJobProperties("xxx", []byte("%%%")) 108 Expect(err).To(MatchError(ContainSubstring("yaml: could not find expected directive name"))) 109 }) 110 }) 111 }) 112 })