Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
104
Merge Requests
104
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos
Commits
261a8e6b
Commit
261a8e6b
authored
Nov 11, 2021
by
Jérome Perrin
2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test/recipe: update tests for postgres recipe regarding password update
parent
b8b42080
Pipeline
#18292
passed with stage
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
9 deletions
+68
-9
slapos/test/recipe/test_postgres.py
slapos/test/recipe/test_postgres.py
+68
-9
No files found.
slapos/test/recipe/test_postgres.py
View file @
261a8e6b
import
unittest
import
tempfile
import
os
import
shutil
import
os.path
import
tempfile
import
textwrap
import
unittest
import
zc.buildout.testing
class
PostgresTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
buildout
=
buildout
=
zc
.
buildout
.
testing
.
Buildout
()
self
.
pgdata_directory
=
tempfile
.
mkdtemp
()
self
.
addCleanup
(
shutil
.
rmtree
,
self
.
pgdata_directory
)
self
.
services_directory
=
tempfile
.
mkdtemp
()
self
.
addCleanup
(
shutil
.
rmtree
,
self
.
services_directory
)
self
.
software_bin_dir
=
tempfile
.
mkdtemp
()
# create fake programs
self
.
addCleanup
(
shutil
.
rmtree
,
self
.
software_bin_dir
)
initdb
=
os
.
path
.
join
(
self
.
software_bin_dir
,
'initdb'
)
with
open
(
initdb
,
'w'
)
as
f
:
f
.
write
(
textwrap
.
dedent
(
'''
\
#!/bin/sh
if [ ! "$1" = -D ]
then
echo Wrong arguments, expecting -D datadir ... got: "$@"
exit 1
fi
mkdir "$2"
'''
))
os
.
chmod
(
initdb
,
0o775
)
postgres
=
os
.
path
.
join
(
self
.
software_bin_dir
,
'postgres'
)
with
open
(
postgres
,
'w'
)
as
f
:
f
.
write
(
textwrap
.
dedent
(
'''
\
#!/bin/sh
exec cat > %s/postgres.sql
'''
)
%
os
.
path
.
join
(
self
.
pgdata_directory
,
'pgdata'
))
os
.
chmod
(
postgres
,
0o775
)
psql
=
os
.
path
.
join
(
self
.
software_bin_dir
,
'psql'
)
with
open
(
psql
,
'w'
)
as
f
:
f
.
write
(
textwrap
.
dedent
(
'''
\
#!/bin/sh -xe
exec cat > %s/psql.sql
'''
)
%
os
.
path
.
join
(
self
.
pgdata_directory
,
'pgdata'
))
os
.
chmod
(
psql
,
0o775
)
buildout
[
'postgres'
]
=
{
'bin'
:
'software/parts/postgres/bin/'
,
'bin'
:
self
.
software_bin_dir
,
'dbname'
:
'dbname'
,
'ipv4'
:
'127.0.0.1'
,
'ipv6'
:
'::1'
,
'port'
:
'5443'
,
'pgdata-directory'
:
self
.
pgdata_directory
,
'pgdata-directory'
:
os
.
path
.
join
(
self
.
pgdata_directory
,
'pgdata'
)
,
'services'
:
self
.
services_directory
,
'superuser'
:
'superuser'
,
'password'
:
'secret'
,
...
...
@@ -37,13 +73,36 @@ class PostgresTest(unittest.TestCase):
def
test_install
(
self
):
installed
=
self
.
recipe
.
install
()
self
.
assertIn
(
'postgresql.conf'
,
os
.
listdir
(
self
.
pgdata_directory
))
self
.
assertIn
(
'pg_hba.conf'
,
os
.
listdir
(
self
.
pgdata_directory
))
pgdata_directory
=
os
.
path
.
join
(
self
.
pgdata_directory
,
'pgdata'
)
self
.
assertIn
(
'postgresql.conf'
,
os
.
listdir
(
pgdata_directory
))
self
.
assertIn
(
'pg_hba.conf'
,
os
.
listdir
(
pgdata_directory
))
self
.
assertIn
(
'postgres-start'
,
os
.
listdir
(
self
.
services_directory
))
with
open
(
os
.
path
.
join
(
pgdata_directory
,
'postgres.sql'
))
as
f
:
self
.
assertEqual
(
f
.
read
(),
'ALTER USER "superuser" ENCRYPTED PASSWORD
\
'
md53992d9240b8f81ebd7e1f9a9fafeb06b
\
'
\
n
'
)
self
.
assertEqual
(
sorted
(
installed
),
sorted
([
os
.
path
.
join
(
self
.
pgdata_directory
,
'postgresql.conf'
),
os
.
path
.
join
(
self
.
pgdata_directory
,
'pg_hba.conf'
),
os
.
path
.
join
(
pgdata_directory
,
'postgresql.conf'
),
os
.
path
.
join
(
pgdata_directory
,
'pg_hba.conf'
),
os
.
path
.
join
(
self
.
services_directory
,
'postgres-start'
)]))
def
test_update_password
(
self
):
self
.
recipe
.
install
()
# simulate a running server
pgdata_directory
=
os
.
path
.
join
(
self
.
pgdata_directory
,
'pgdata'
)
open
(
os
.
path
.
join
(
pgdata_directory
,
'postmaster.pid'
),
'w'
).
close
()
self
.
recipe
.
options
[
'password'
]
=
'new'
self
.
recipe
.
install
()
with
open
(
os
.
path
.
join
(
pgdata_directory
,
'psql.sql'
))
as
f
:
self
.
assertEqual
(
f
.
read
(),
'ALTER USER "superuser" ENCRYPTED PASSWORD
\
'
md5442311d398491b7f6b512757b51ae9d8
\
'
\
n
'
)
Jérome Perrin
@jerome
mentioned in merge request
!1083 (merged)
·
Nov 12, 2021
mentioned in merge request
!1083 (merged)
mentioned in merge request !1083
Toggle commit list
Jérome Perrin
@jerome
mentioned in commit
1876c150
·
Nov 15, 2021
mentioned in commit
1876c150
mentioned in commit 1876c150abc6e6d4676460f5ab3f1b9b503b9fb5
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment