@@ -53,7 +53,7 @@ func TestV1PGBouncerLogging(t *testing.T) {
5353 }
5454 }` )
5555 assert .NilError (t , cc .Create (ctx , base .DeepCopy (), client .DryRunAll ),
56- "expected this base to be valid" )
56+ "expected this option to be valid" )
5757 })
5858
5959 t .Run ("Cannot set logging on tmp without .log" , func (t * testing.T ) {
@@ -73,4 +73,96 @@ func TestV1PGBouncerLogging(t *testing.T) {
7373 assert .Assert (t , apierrors .IsInvalid (err ))
7474 assert .ErrorContains (t , err , "logfile config must end with '.log'" )
7575 })
76+
77+ t .Run ("Cannot set logging on tmp without correct subdir" , func (t * testing.T ) {
78+ tmp := base .DeepCopy ()
79+
80+ require .UnmarshalInto (t , & tmp .Spec .Proxy , `{
81+ pgBouncer: {
82+ config: {
83+ global: {
84+ logfile: "/tmp/logs/log.log"
85+ }
86+ }
87+ }
88+ }` )
89+
90+ err := cc .Create (ctx , tmp .DeepCopy (), client .DryRunAll )
91+ assert .Assert (t , apierrors .IsInvalid (err ))
92+ assert .ErrorContains (t , err , "logfile destination is restricted to '/tmp/logs/pgbouncer/' or an existing additional volume" )
93+
94+ require .UnmarshalInto (t , & tmp .Spec .Proxy , `{
95+ pgBouncer: {
96+ config: {
97+ global: {
98+ logfile: "/tmp/pgbouncer/log.log"
99+ }
100+ }
101+ }
102+ }` )
103+
104+ err = cc .Create (ctx , tmp .DeepCopy (), client .DryRunAll )
105+ assert .Assert (t , apierrors .IsInvalid (err ))
106+ assert .ErrorContains (t , err , "logfile destination is restricted to '/tmp/logs/pgbouncer/' or an existing additional volume" )
107+ })
108+
109+ t .Run ("Cannot set logging on volumes that don't exist" , func (t * testing.T ) {
110+ vol := base .DeepCopy ()
111+
112+ require .UnmarshalInto (t , & vol .Spec .Proxy , `{
113+ pgBouncer: {
114+ config: {
115+ global: {
116+ logfile: "/volumes/logging/log.log"
117+ }
118+ }
119+ }
120+ }` )
121+
122+ err := cc .Create (ctx , vol .DeepCopy (), client .DryRunAll )
123+ assert .Assert (t , apierrors .IsInvalid (err ))
124+ assert .ErrorContains (t , err , "logfile destination is restricted to '/tmp/logs/pgbouncer/' or an existing additional volume" )
125+ })
126+
127+ t .Run ("Cannot set logging elsewhere" , func (t * testing.T ) {
128+ vol := base .DeepCopy ()
129+
130+ require .UnmarshalInto (t , & vol .Spec .Proxy , `{
131+ pgBouncer: {
132+ config: {
133+ global: {
134+ logfile: "/var/log.log"
135+ }
136+ }
137+ }
138+ }` )
139+
140+ err := cc .Create (ctx , vol .DeepCopy (), client .DryRunAll )
141+ assert .Assert (t , apierrors .IsInvalid (err ))
142+ assert .ErrorContains (t , err , "logfile destination is restricted to '/tmp/logs/pgbouncer/' or an existing additional volume" )
143+ })
144+
145+ t .Run ("Can set logging on volumes that exist" , func (t * testing.T ) {
146+ vol := base .DeepCopy ()
147+
148+ require .UnmarshalInto (t , & vol .Spec .Proxy , `{
149+ pgBouncer: {
150+ config: {
151+ global: {
152+ logfile: "/volumes/logging/log.log"
153+ }
154+ },
155+ volumes: {
156+ additional: [
157+ {
158+ name: logging,
159+ claimName: required-1
160+ }]
161+ }
162+ }
163+ }` )
164+
165+ assert .NilError (t , cc .Create (ctx , vol .DeepCopy (), client .DryRunAll ),
166+ "expected this option to be valid" )
167+ })
76168}
0 commit comments