mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
helpers/config: Add unit tests for read/write var from py/ini
This commit is contained in:
parent
d74bc485dd
commit
cc8247acfd
1 changed files with 380 additions and 129 deletions
|
@ -1,20 +1,24 @@
|
|||
_make_dummy_files() {
|
||||
|
||||
local_dummy_dir="$1"
|
||||
#################
|
||||
# _ __ _ _ #
|
||||
# | '_ \| | | | #
|
||||
# | |_) | |_| | #
|
||||
# | .__/ \__, | #
|
||||
# | | __/ | #
|
||||
# |_| |___/ #
|
||||
# #
|
||||
#################
|
||||
|
||||
cat << EOF > $dummy_dir/dummy.ini
|
||||
# Some comment
|
||||
foo =
|
||||
enabled = False
|
||||
# title = Old title
|
||||
title = Lorem Ipsum
|
||||
email = root@example.com
|
||||
theme = colib'ris
|
||||
port = 1234
|
||||
url = https://yunohost.org
|
||||
[dict]
|
||||
ldap_base = ou=users,dc=yunohost,dc=org
|
||||
EOF
|
||||
_read_py() {
|
||||
local file="$1"
|
||||
local key="$2"
|
||||
python3 -c "exec(open('$file').read()); print($key)"
|
||||
}
|
||||
|
||||
ynhtest_config_read_py() {
|
||||
|
||||
local dummy_dir="$(mktemp -d -p $VAR_WWW)"
|
||||
file="$dummy_dir/dummy.py"
|
||||
|
||||
cat << EOF > $dummy_dir/dummy.py
|
||||
# Some comment
|
||||
|
@ -26,30 +30,245 @@ THEME = "colib'ris"
|
|||
EMAIL = "root@example.com"
|
||||
PORT = 1234
|
||||
URL = 'https://yunohost.org'
|
||||
DICT = {}
|
||||
DICT['ldap_base'] = "ou=users,dc=yunohost,dc=org"
|
||||
EOF
|
||||
|
||||
test "$(_read_py "$file" "FOO")" == "None"
|
||||
test "$(ynh_read_var_in_file "$file" "FOO")" == "None"
|
||||
|
||||
test "$(_read_py "$file" "ENABLED")" == "False"
|
||||
test "$(ynh_read_var_in_file "$file" "ENABLED")" == "False"
|
||||
|
||||
test "$(_read_py "$file" "TITLE")" == "Lorem Ipsum"
|
||||
test "$(ynh_read_var_in_file "$file" "TITLE")" == "Lorem Ipsum"
|
||||
|
||||
test "$(_read_py "$file" "THEME")" == "colib'ris"
|
||||
test "$(ynh_read_var_in_file "$file" "THEME")" == "colib'ris"
|
||||
|
||||
test "$(_read_py "$file" "EMAIL")" == "root@example.com"
|
||||
test "$(ynh_read_var_in_file "$file" "EMAIL")" == "root@example.com"
|
||||
|
||||
test "$(_read_py "$file" "PORT")" == "1234"
|
||||
test "$(ynh_read_var_in_file "$file" "PORT")" == "1234"
|
||||
|
||||
test "$(_read_py "$file" "URL")" == "https://yunohost.org"
|
||||
test "$(ynh_read_var_in_file "$file" "URL")" == "https://yunohost.org"
|
||||
|
||||
test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org"
|
||||
|
||||
! _read_py "$file" "NONEXISTENT"
|
||||
test "$(ynh_read_var_in_file "$file" "NONEXISTENT")" == "YNH_NULL"
|
||||
|
||||
! _read_py "$file" "ENABLE"
|
||||
test "$(ynh_read_var_in_file "$file" "ENABLE")" == "YNH_NULL"
|
||||
}
|
||||
|
||||
_ynh_read_yaml_with_python() {
|
||||
ynhtest_config_write_py() {
|
||||
local dummy_dir="$(mktemp -d -p $VAR_WWW)"
|
||||
file="$dummy_dir/dummy.py"
|
||||
|
||||
cat << EOF > $dummy_dir/dummy.py
|
||||
# Some comment
|
||||
FOO = None
|
||||
ENABLED = False
|
||||
# TITLE = "Old title"
|
||||
TITLE = "Lorem Ipsum"
|
||||
THEME = "colib'ris"
|
||||
EMAIL = "root@example.com"
|
||||
PORT = 1234
|
||||
URL = 'https://yunohost.org'
|
||||
DICT = {}
|
||||
DICT['ldap_base'] = "ou=users,dc=yunohost,dc=org"
|
||||
EOF
|
||||
|
||||
#ynh_write_var_in_file "$file" "FOO" "bar"
|
||||
#test "$(_read_py "$file" "FOO")" == "bar" # FIXME FIXME FIXME
|
||||
#test "$(ynh_read_var_in_file "$file" "FOO")" == "bar"
|
||||
|
||||
ynh_write_var_in_file "$file" "ENABLED" "True"
|
||||
test "$(_read_py "$file" "ENABLED")" == "True"
|
||||
test "$(ynh_read_var_in_file "$file" "ENABLED")" == "True"
|
||||
|
||||
ynh_write_var_in_file "$file" "TITLE" "Foo Bar"
|
||||
test "$(_read_py "$file" "TITLE")" == "Foo Bar"
|
||||
test "$(ynh_read_var_in_file "$file" "TITLE")" == "Foo Bar"
|
||||
|
||||
ynh_write_var_in_file "$file" "THEME" "super-awesome-theme"
|
||||
test "$(_read_py "$file" "THEME")" == "super-awesome-theme"
|
||||
test "$(ynh_read_var_in_file "$file" "THEME")" == "super-awesome-theme"
|
||||
|
||||
ynh_write_var_in_file "$file" "EMAIL" "sam@domain.tld"
|
||||
test "$(_read_py "$file" "EMAIL")" == "sam@domain.tld"
|
||||
test "$(ynh_read_var_in_file "$file" "EMAIL")" == "sam@domain.tld"
|
||||
|
||||
ynh_write_var_in_file "$file" "PORT" "5678"
|
||||
test "$(_read_py "$file" "PORT")" == "5678"
|
||||
test "$(ynh_read_var_in_file "$file" "PORT")" == "5678"
|
||||
|
||||
ynh_write_var_in_file "$file" "URL" "https://domain.tld/foobar"
|
||||
test "$(_read_py "$file" "URL")" == "https://domain.tld/foobar"
|
||||
test "$(ynh_read_var_in_file "$file" "URL")" == "https://domain.tld/foobar"
|
||||
|
||||
ynh_write_var_in_file "$file" "ldap_base" "ou=users,dc=yunohost,dc=org"
|
||||
test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org"
|
||||
|
||||
ynh_write_var_in_file "$file" "NONEXISTENT" "foobar"
|
||||
! _read_py "$file" "NONEXISTENT"
|
||||
test "$(ynh_read_var_in_file "$file" "NONEXISTENT")" == "YNH_NULL"
|
||||
|
||||
ynh_write_var_in_file "$file" "ENABLE" "foobar"
|
||||
! _read_py "$file" "ENABLE"
|
||||
test "$(ynh_read_var_in_file "$file" "ENABLE")" == "YNH_NULL"
|
||||
|
||||
}
|
||||
|
||||
###############
|
||||
# _ _ #
|
||||
# (_) (_) #
|
||||
# _ _ __ _ #
|
||||
# | | '_ \| | #
|
||||
# | | | | | | #
|
||||
# |_|_| |_|_| #
|
||||
# #
|
||||
###############
|
||||
|
||||
_read_ini() {
|
||||
local file="$1"
|
||||
local key="$2"
|
||||
python3 -c "import configparser; c = configparser.ConfigParser(); c.read('$file'); print(c['main']['$key'])"
|
||||
}
|
||||
|
||||
ynhtest_config_read_ini() {
|
||||
local dummy_dir="$(mktemp -d -p $VAR_WWW)"
|
||||
file="$dummy_dir/dummy.yml"
|
||||
|
||||
cat << EOF > $file
|
||||
# Some comment
|
||||
; Another comment
|
||||
[main]
|
||||
foo = null
|
||||
enabled = False
|
||||
# title = Old title
|
||||
title = Lorem Ipsum
|
||||
theme = colib'ris
|
||||
email = root@example.com
|
||||
port = 1234
|
||||
url = https://yunohost.org
|
||||
[dict]
|
||||
ldap_base = ou=users,dc=yunohost,dc=org
|
||||
EOF
|
||||
|
||||
test "$(_read_ini "$file" "foo")" == "null"
|
||||
test "$(ynh_read_var_in_file "$file" "foo")" == "null"
|
||||
|
||||
test "$(_read_ini "$file" "enabled")" == "False"
|
||||
test "$(ynh_read_var_in_file "$file" "enabled")" == "False"
|
||||
|
||||
test "$(_read_ini "$file" "title")" == "Lorem Ipsum"
|
||||
test "$(ynh_read_var_in_file "$file" "title")" == "Lorem Ipsum"
|
||||
|
||||
test "$(_read_ini "$file" "theme")" == "colib'ris"
|
||||
test "$(ynh_read_var_in_file "$file" "theme")" == "colib'ris"
|
||||
|
||||
test "$(_read_ini "$file" "email")" == "root@example.com"
|
||||
test "$(ynh_read_var_in_file "$file" "email")" == "root@example.com"
|
||||
|
||||
test "$(_read_ini "$file" "port")" == "1234"
|
||||
test "$(ynh_read_var_in_file "$file" "port")" == "1234"
|
||||
|
||||
test "$(_read_ini "$file" "url")" == "https://yunohost.org"
|
||||
test "$(ynh_read_var_in_file "$file" "url")" == "https://yunohost.org"
|
||||
|
||||
test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org"
|
||||
|
||||
! _read_ini "$file" "nonexistent"
|
||||
test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL"
|
||||
|
||||
! _read_ini "$file" "enable"
|
||||
test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL"
|
||||
|
||||
}
|
||||
|
||||
ynhtest_config_write_ini() {
|
||||
local dummy_dir="$(mktemp -d -p $VAR_WWW)"
|
||||
file="$dummy_dir/dummy.ini"
|
||||
|
||||
cat << EOF > $file
|
||||
# Some comment
|
||||
; Another comment
|
||||
[main]
|
||||
foo = null
|
||||
enabled = False
|
||||
# title = Old title
|
||||
title = Lorem Ipsum
|
||||
theme = colib'ris
|
||||
email = root@example.com
|
||||
port = 1234
|
||||
url = https://yunohost.org
|
||||
[dict]
|
||||
ldap_base = ou=users,dc=yunohost,dc=org
|
||||
EOF
|
||||
|
||||
ynh_write_var_in_file "$file" "foo" "bar"
|
||||
test "$(_read_ini "$file" "foo")" == "bar"
|
||||
test "$(ynh_read_var_in_file "$file" "foo")" == "bar"
|
||||
|
||||
ynh_write_var_in_file "$file" "enabled" "True"
|
||||
test "$(_read_ini "$file" "enabled")" == "True"
|
||||
test "$(ynh_read_var_in_file "$file" "enabled")" == "True"
|
||||
|
||||
ynh_write_var_in_file "$file" "title" "Foo Bar"
|
||||
test "$(_read_ini "$file" "title")" == "Foo Bar"
|
||||
test "$(ynh_read_var_in_file "$file" "title")" == "Foo Bar"
|
||||
|
||||
ynh_write_var_in_file "$file" "theme" "super-awesome-theme"
|
||||
test "$(_read_ini "$file" "theme")" == "super-awesome-theme"
|
||||
test "$(ynh_read_var_in_file "$file" "theme")" == "super-awesome-theme"
|
||||
|
||||
ynh_write_var_in_file "$file" "email" "sam@domain.tld"
|
||||
test "$(_read_ini "$file" "email")" == "sam@domain.tld"
|
||||
test "$(ynh_read_var_in_file "$file" "email")" == "sam@domain.tld"
|
||||
|
||||
ynh_write_var_in_file "$file" "port" "5678"
|
||||
test "$(_read_ini "$file" "port")" == "5678"
|
||||
test "$(ynh_read_var_in_file "$file" "port")" == "5678"
|
||||
|
||||
ynh_write_var_in_file "$file" "url" "https://domain.tld/foobar"
|
||||
test "$(_read_ini "$file" "url")" == "https://domain.tld/foobar"
|
||||
test "$(ynh_read_var_in_file "$file" "url")" == "https://domain.tld/foobar"
|
||||
|
||||
ynh_write_var_in_file "$file" "ldap_base" "ou=users,dc=yunohost,dc=org"
|
||||
test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org"
|
||||
|
||||
ynh_write_var_in_file "$file" "nonexistent" "foobar"
|
||||
! _read_ini "$file" "nonexistent"
|
||||
test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL"
|
||||
|
||||
ynh_write_var_in_file "$file" "enable" "foobar"
|
||||
! _read_ini "$file" "enable"
|
||||
test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL"
|
||||
|
||||
}
|
||||
|
||||
#############################
|
||||
# _ #
|
||||
# | | #
|
||||
# _ _ __ _ _ __ ___ | | #
|
||||
# | | | |/ _` | '_ ` _ \| | #
|
||||
# | |_| | (_| | | | | | | | #
|
||||
# \__, |\__,_|_| |_| |_|_| #
|
||||
# __/ | #
|
||||
# |___/ #
|
||||
# #
|
||||
#############################
|
||||
|
||||
_read_yaml() {
|
||||
local file="$1"
|
||||
local key="$2"
|
||||
python3 -c "import yaml; print(yaml.safe_load(open('$file'))['$key'])"
|
||||
}
|
||||
|
||||
_ynh_read_json_with_python() {
|
||||
local file="$1"
|
||||
local key="$2"
|
||||
python3 -c "import json; print(json.load(open('$file'))['$key'])"
|
||||
}
|
||||
|
||||
_ynh_read_php_with_php() {
|
||||
local file="$1"
|
||||
local key="$2"
|
||||
php -r "include '$file'; echo var_export(\$$key);" | sed "s/^'//g" | sed "s/'$//g"
|
||||
}
|
||||
|
||||
|
||||
ynhtest_config_read_yaml() {
|
||||
local dummy_dir="$(mktemp -d -p $VAR_WWW)"
|
||||
file="$dummy_dir/dummy.yml"
|
||||
|
@ -68,33 +287,33 @@ dict:
|
|||
ldap_base: ou=users,dc=yunohost,dc=org
|
||||
EOF
|
||||
|
||||
test "$(_ynh_read_yaml_with_python "$file" "foo")" == "None"
|
||||
test "$(_read_yaml "$file" "foo")" == "None"
|
||||
test "$(ynh_read_var_in_file "$file" "foo")" == ""
|
||||
|
||||
test "$(_ynh_read_yaml_with_python "$file" "enabled")" == "False"
|
||||
test "$(_read_yaml "$file" "enabled")" == "False"
|
||||
test "$(ynh_read_var_in_file "$file" "enabled")" == "false"
|
||||
|
||||
test "$(_ynh_read_yaml_with_python "$file" "title")" == "Lorem Ipsum"
|
||||
test "$(_read_yaml "$file" "title")" == "Lorem Ipsum"
|
||||
test "$(ynh_read_var_in_file "$file" "title")" == "Lorem Ipsum"
|
||||
|
||||
test "$(_ynh_read_yaml_with_python "$file" "theme")" == "colib'ris"
|
||||
test "$(_read_yaml "$file" "theme")" == "colib'ris"
|
||||
test "$(ynh_read_var_in_file "$file" "theme")" == "colib'ris"
|
||||
|
||||
test "$(_ynh_read_yaml_with_python "$file" "email")" == "root@example.com"
|
||||
test "$(_read_yaml "$file" "email")" == "root@example.com"
|
||||
test "$(ynh_read_var_in_file "$file" "email")" == "root@example.com"
|
||||
|
||||
test "$(_ynh_read_yaml_with_python "$file" "port")" == "1234"
|
||||
test "$(_read_yaml "$file" "port")" == "1234"
|
||||
test "$(ynh_read_var_in_file "$file" "port")" == "1234"
|
||||
|
||||
test "$(_ynh_read_yaml_with_python "$file" "url")" == "https://yunohost.org"
|
||||
test "$(_read_yaml "$file" "url")" == "https://yunohost.org"
|
||||
test "$(ynh_read_var_in_file "$file" "url")" == "https://yunohost.org"
|
||||
|
||||
test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org"
|
||||
|
||||
! _ynh_read_yaml_with_python "$file" "nonexistent"
|
||||
! _read_yaml "$file" "nonexistent"
|
||||
test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL"
|
||||
|
||||
! _ynh_read_yaml_with_python "$file" "enable"
|
||||
! _read_yaml "$file" "enable"
|
||||
test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL"
|
||||
}
|
||||
|
||||
|
@ -117,35 +336,33 @@ dict:
|
|||
ldap_base: ou=users,dc=yunohost,dc=org
|
||||
EOF
|
||||
|
||||
|
||||
|
||||
#ynh_write_var_in_file "$file" "foo" "bar"
|
||||
# cat $dummy_dir/dummy.yml # to debug
|
||||
#! test "$(_ynh_read_yaml_with_python "$file" "foo")" == "bar" # FIXME FIXME FIXME : writing broke the yaml syntax... "foo:bar" (no space aftr :)
|
||||
#! test "$(_read_yaml "$file" "foo")" == "bar" # FIXME FIXME FIXME : writing broke the yaml syntax... "foo:bar" (no space aftr :)
|
||||
#test "$(ynh_read_var_in_file "$file" "foo")" == "bar"
|
||||
|
||||
ynh_write_var_in_file "$file" "enabled" "true"
|
||||
test "$(_ynh_read_yaml_with_python "$file" "enabled")" == "True"
|
||||
test "$(_read_yaml "$file" "enabled")" == "True"
|
||||
test "$(ynh_read_var_in_file "$file" "enabled")" == "true"
|
||||
|
||||
ynh_write_var_in_file "$file" "title" "Foo Bar"
|
||||
test "$(_ynh_read_yaml_with_python "$file" "title")" == "Foo Bar"
|
||||
test "$(_read_yaml "$file" "title")" == "Foo Bar"
|
||||
test "$(ynh_read_var_in_file "$file" "title")" == "Foo Bar"
|
||||
|
||||
ynh_write_var_in_file "$file" "theme" "super-awesome-theme"
|
||||
test "$(_ynh_read_yaml_with_python "$file" "theme")" == "super-awesome-theme"
|
||||
test "$(_read_yaml "$file" "theme")" == "super-awesome-theme"
|
||||
test "$(ynh_read_var_in_file "$file" "theme")" == "super-awesome-theme"
|
||||
|
||||
ynh_write_var_in_file "$file" "email" "sam@domain.tld"
|
||||
test "$(_ynh_read_yaml_with_python "$file" "email")" == "sam@domain.tld"
|
||||
test "$(_read_yaml "$file" "email")" == "sam@domain.tld"
|
||||
test "$(ynh_read_var_in_file "$file" "email")" == "sam@domain.tld"
|
||||
|
||||
ynh_write_var_in_file "$file" "port" "5678"
|
||||
test "$(_ynh_read_yaml_with_python "$file" "port")" == "5678"
|
||||
test "$(_read_yaml "$file" "port")" == "5678"
|
||||
test "$(ynh_read_var_in_file "$file" "port")" == "5678"
|
||||
|
||||
ynh_write_var_in_file "$file" "url" "https://domain.tld/foobar"
|
||||
test "$(_ynh_read_yaml_with_python "$file" "url")" == "https://domain.tld/foobar"
|
||||
test "$(_read_yaml "$file" "url")" == "https://domain.tld/foobar"
|
||||
test "$(ynh_read_var_in_file "$file" "url")" == "https://domain.tld/foobar"
|
||||
|
||||
ynh_write_var_in_file "$file" "ldap_base" "ou=foobar,dc=domain,dc=tld"
|
||||
|
@ -159,6 +376,24 @@ EOF
|
|||
test "$(ynh_read_var_in_file "$file" "enabled")" == "true"
|
||||
}
|
||||
|
||||
#########################
|
||||
# _ #
|
||||
# (_) #
|
||||
# _ ___ ___ _ __ #
|
||||
# | / __|/ _ \| '_ \ #
|
||||
# | \__ \ (_) | | | | #
|
||||
# | |___/\___/|_| |_| #
|
||||
# _/ | #
|
||||
# |__/ #
|
||||
# #
|
||||
#########################
|
||||
|
||||
_read_json() {
|
||||
local file="$1"
|
||||
local key="$2"
|
||||
python3 -c "import json; print(json.load(open('$file'))['$key'])"
|
||||
}
|
||||
|
||||
ynhtest_config_read_json() {
|
||||
local dummy_dir="$(mktemp -d -p $VAR_WWW)"
|
||||
file="$dummy_dir/dummy.json"
|
||||
|
@ -179,33 +414,33 @@ ynhtest_config_read_json() {
|
|||
EOF
|
||||
|
||||
|
||||
test "$(_ynh_read_json_with_python "$file" "foo")" == "None"
|
||||
test "$(_read_json "$file" "foo")" == "None"
|
||||
test "$(ynh_read_var_in_file "$file" "foo")" == "null," # FIXME FIXME FIXME trailing ,
|
||||
|
||||
test "$(_ynh_read_json_with_python "$file" "enabled")" == "False"
|
||||
test "$(_read_json "$file" "enabled")" == "False"
|
||||
test "$(ynh_read_var_in_file "$file" "enabled")" == "false," # FIXME FIXME FIXME trailing ,
|
||||
|
||||
test "$(_ynh_read_json_with_python "$file" "title")" == "Lorem Ipsum"
|
||||
test "$(_read_json "$file" "title")" == "Lorem Ipsum"
|
||||
test "$(ynh_read_var_in_file "$file" "title")" == "Lorem Ipsum"
|
||||
|
||||
test "$(_ynh_read_json_with_python "$file" "theme")" == "colib'ris"
|
||||
test "$(_read_json "$file" "theme")" == "colib'ris"
|
||||
test "$(ynh_read_var_in_file "$file" "theme")" == "colib'ris"
|
||||
|
||||
test "$(_ynh_read_json_with_python "$file" "email")" == "root@example.com"
|
||||
test "$(_read_json "$file" "email")" == "root@example.com"
|
||||
test "$(ynh_read_var_in_file "$file" "email")" == "root@example.com"
|
||||
|
||||
test "$(_ynh_read_json_with_python "$file" "port")" == "1234"
|
||||
test "$(_read_json "$file" "port")" == "1234"
|
||||
test "$(ynh_read_var_in_file "$file" "port")" == "1234," # FIXME FIXME FIXME trailing ,
|
||||
|
||||
test "$(_ynh_read_json_with_python "$file" "url")" == "https://yunohost.org"
|
||||
test "$(_read_json "$file" "url")" == "https://yunohost.org"
|
||||
test "$(ynh_read_var_in_file "$file" "url")" == "https://yunohost.org"
|
||||
|
||||
test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org"
|
||||
|
||||
! _ynh_read_json_with_python "$file" "nonexistent"
|
||||
! _read_json "$file" "nonexistent"
|
||||
test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL"
|
||||
|
||||
! _ynh_read_json_with_python "$file" "enable"
|
||||
! _read_json "$file" "enable"
|
||||
test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL"
|
||||
}
|
||||
|
||||
|
@ -231,35 +466,35 @@ EOF
|
|||
|
||||
#ynh_write_var_in_file "$file" "foo" "bar"
|
||||
#cat $file
|
||||
#test "$(_ynh_read_json_with_python "$file" "foo")" == "bar" # FIXME FIXME FIXME
|
||||
#test "$(_read_json "$file" "foo")" == "bar" # FIXME FIXME FIXME
|
||||
#test "$(ynh_read_var_in_file "$file" "foo")" == "bar"
|
||||
|
||||
#ynh_write_var_in_file "$file" "enabled" "true"
|
||||
#test "$(_ynh_read_json_with_python "$file" "enabled")" == "True" # FIXME FIXME FIXME
|
||||
#test "$(_read_json "$file" "enabled")" == "True" # FIXME FIXME FIXME
|
||||
#test "$(ynh_read_var_in_file "$file" "enabled")" == "true"
|
||||
|
||||
ynh_write_var_in_file "$file" "title" "Foo Bar"
|
||||
cat $file
|
||||
test "$(_ynh_read_json_with_python "$file" "title")" == "Foo Bar"
|
||||
test "$(_read_json "$file" "title")" == "Foo Bar"
|
||||
test "$(ynh_read_var_in_file "$file" "title")" == "Foo Bar"
|
||||
|
||||
ynh_write_var_in_file "$file" "theme" "super-awesome-theme"
|
||||
cat $file
|
||||
test "$(_ynh_read_json_with_python "$file" "theme")" == "super-awesome-theme"
|
||||
test "$(_read_json "$file" "theme")" == "super-awesome-theme"
|
||||
test "$(ynh_read_var_in_file "$file" "theme")" == "super-awesome-theme"
|
||||
|
||||
ynh_write_var_in_file "$file" "email" "sam@domain.tld"
|
||||
cat $file
|
||||
test "$(_ynh_read_json_with_python "$file" "email")" == "sam@domain.tld"
|
||||
test "$(_read_json "$file" "email")" == "sam@domain.tld"
|
||||
test "$(ynh_read_var_in_file "$file" "email")" == "sam@domain.tld"
|
||||
|
||||
#ynh_write_var_in_file "$file" "port" "5678"
|
||||
#cat $file
|
||||
#test "$(_ynh_read_json_with_python "$file" "port")" == "5678" # FIXME FIXME FIXME
|
||||
#test "$(_read_json "$file" "port")" == "5678" # FIXME FIXME FIXME
|
||||
#test "$(ynh_read_var_in_file "$file" "port")" == "5678"
|
||||
|
||||
ynh_write_var_in_file "$file" "url" "https://domain.tld/foobar"
|
||||
test "$(_ynh_read_json_with_python "$file" "url")" == "https://domain.tld/foobar"
|
||||
test "$(_read_json "$file" "url")" == "https://domain.tld/foobar"
|
||||
test "$(ynh_read_var_in_file "$file" "url")" == "https://domain.tld/foobar"
|
||||
|
||||
ynh_write_var_in_file "$file" "ldap_base" "ou=foobar,dc=domain,dc=tld"
|
||||
|
@ -273,7 +508,23 @@ EOF
|
|||
#test "$(ynh_read_var_in_file "$file" "enabled")" == "true" # FIXME
|
||||
}
|
||||
|
||||
#######################
|
||||
# _ #
|
||||
# | | #
|
||||
# _ __ | |__ _ __ #
|
||||
# | '_ \| '_ \| '_ \ #
|
||||
# | |_) | | | | |_) | #
|
||||
# | .__/|_| |_| .__/ #
|
||||
# | | | | #
|
||||
# |_| |_| #
|
||||
# #
|
||||
#######################
|
||||
|
||||
_read_php() {
|
||||
local file="$1"
|
||||
local key="$2"
|
||||
php -r "include '$file'; echo var_export(\$$key);" | sed "s/^'//g" | sed "s/'$//g"
|
||||
}
|
||||
|
||||
ynhtest_config_read_php() {
|
||||
local dummy_dir="$(mktemp -d -p $VAR_WWW)"
|
||||
|
@ -296,33 +547,33 @@ ynhtest_config_read_php() {
|
|||
?>
|
||||
EOF
|
||||
|
||||
test "$(_ynh_read_php_with_php "$file" "foo")" == "NULL"
|
||||
test "$(_read_php "$file" "foo")" == "NULL"
|
||||
test "$(ynh_read_var_in_file "$file" "foo")" == "NULL;" # FIXME FIXME FIXME trailing ;
|
||||
|
||||
test "$(_ynh_read_php_with_php "$file" "enabled")" == "false"
|
||||
test "$(_read_php "$file" "enabled")" == "false"
|
||||
test "$(ynh_read_var_in_file "$file" "enabled")" == "false;" # FIXME FIXME FIXME trailing ;
|
||||
|
||||
test "$(_ynh_read_php_with_php "$file" "title")" == "Lorem Ipsum"
|
||||
test "$(_read_php "$file" "title")" == "Lorem Ipsum"
|
||||
test "$(ynh_read_var_in_file "$file" "title")" == "Lorem Ipsum"
|
||||
|
||||
test "$(_ynh_read_php_with_php "$file" "theme")" == "colib\\'ris"
|
||||
test "$(_read_php "$file" "theme")" == "colib\\'ris"
|
||||
test "$(ynh_read_var_in_file "$file" "theme")" == "colib'ris"
|
||||
|
||||
test "$(_ynh_read_php_with_php "$file" "email")" == "root@example.com"
|
||||
test "$(_read_php "$file" "email")" == "root@example.com"
|
||||
test "$(ynh_read_var_in_file "$file" "email")" == "root@example.com"
|
||||
|
||||
test "$(_ynh_read_php_with_php "$file" "port")" == "1234"
|
||||
test "$(_read_php "$file" "port")" == "1234"
|
||||
test "$(ynh_read_var_in_file "$file" "port")" == "1234;" # FIXME FIXME FIXME trailing ;
|
||||
|
||||
test "$(_ynh_read_php_with_php "$file" "url")" == "https://yunohost.org"
|
||||
test "$(_read_php "$file" "url")" == "https://yunohost.org"
|
||||
test "$(ynh_read_var_in_file "$file" "url")" == "https://yunohost.org"
|
||||
|
||||
test "$(ynh_read_var_in_file "$file" "ldap_base")" == "ou=users,dc=yunohost,dc=org"
|
||||
|
||||
! _ynh_read_php_with_php "$file" "nonexistent"
|
||||
! _read_php "$file" "nonexistent"
|
||||
test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL"
|
||||
|
||||
! _ynh_read_php_with_php "$file" "enable"
|
||||
! _read_php "$file" "enable"
|
||||
test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL"
|
||||
}
|
||||
|
||||
|
@ -350,36 +601,36 @@ EOF
|
|||
|
||||
#ynh_write_var_in_file "$file" "foo" "bar"
|
||||
#cat $file
|
||||
#test "$(_ynh_read_php_with_php "$file" "foo")" == "bar"
|
||||
#test "$(_read_php "$file" "foo")" == "bar"
|
||||
#test "$(ynh_read_var_in_file "$file" "foo")" == "bar" # FIXME FIXME FIXME
|
||||
|
||||
#ynh_write_var_in_file "$file" "enabled" "true"
|
||||
#cat $file
|
||||
#test "$(_ynh_read_php_with_php "$file" "enabled")" == "true"
|
||||
#test "$(_read_php "$file" "enabled")" == "true"
|
||||
#test "$(ynh_read_var_in_file "$file" "enabled")" == "true" # FIXME FIXME FIXME
|
||||
|
||||
ynh_write_var_in_file "$file" "title" "Foo Bar"
|
||||
cat $file
|
||||
test "$(_ynh_read_php_with_php "$file" "title")" == "Foo Bar"
|
||||
test "$(ynh_read_var_in_file "$file" "title")" == "Foo Bar"
|
||||
test "$(_read_php "$file" "title")" == "Foo Bar"
|
||||
test "$(ynh_read_var_in_file "$file" "title")" == "Foo Bar"
|
||||
|
||||
ynh_write_var_in_file "$file" "theme" "super-awesome-theme"
|
||||
cat $file
|
||||
test "$(_ynh_read_php_with_php "$file" "theme")" == "super-awesome-theme"
|
||||
test "$(_read_php "$file" "theme")" == "super-awesome-theme"
|
||||
test "$(ynh_read_var_in_file "$file" "theme")" == "super-awesome-theme"
|
||||
|
||||
ynh_write_var_in_file "$file" "email" "sam@domain.tld"
|
||||
cat $file
|
||||
test "$(_ynh_read_php_with_php "$file" "email")" == "sam@domain.tld"
|
||||
test "$(_read_php "$file" "email")" == "sam@domain.tld"
|
||||
test "$(ynh_read_var_in_file "$file" "email")" == "sam@domain.tld"
|
||||
|
||||
#ynh_write_var_in_file "$file" "port" "5678"
|
||||
#cat $file
|
||||
#test "$(_ynh_read_php_with_php "$file" "port")" == "5678" # FIXME FIXME FIXME
|
||||
#test "$(_read_php "$file" "port")" == "5678" # FIXME FIXME FIXME
|
||||
#test "$(ynh_read_var_in_file "$file" "port")" == "5678"
|
||||
|
||||
ynh_write_var_in_file "$file" "url" "https://domain.tld/foobar"
|
||||
test "$(_ynh_read_php_with_php "$file" "url")" == "https://domain.tld/foobar"
|
||||
test "$(_read_php "$file" "url")" == "https://domain.tld/foobar"
|
||||
test "$(ynh_read_var_in_file "$file" "url")" == "https://domain.tld/foobar"
|
||||
|
||||
ynh_write_var_in_file "$file" "ldap_base" "ou=foobar,dc=domain,dc=tld"
|
||||
|
|
Loading…
Add table
Reference in a new issue