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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
slapos
Commits
261a8e6b
Commit
261a8e6b
authored
Nov 11, 2021
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test/recipe: update tests for postgres recipe regarding password update
parent
b8b42080
Changes
1
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
'
)
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