helpers/config: Add unit tests for read/write var from py/ini

This commit is contained in:
Alexandre Aubin 2021-09-03 23:36:54 +02:00
parent d74bc485dd
commit cc8247acfd

View file

@ -1,20 +1,24 @@
_make_dummy_files() {
local_dummy_dir="$1" #################
# _ __ _ _ #
# | '_ \| | | | #
# | |_) | |_| | #
# | .__/ \__, | #
# | | __/ | #
# |_| |___/ #
# #
#################
cat << EOF > $dummy_dir/dummy.ini _read_py() {
# Some comment local file="$1"
foo = local key="$2"
enabled = False python3 -c "exec(open('$file').read()); print($key)"
# title = Old title }
title = Lorem Ipsum
email = root@example.com ynhtest_config_read_py() {
theme = colib'ris
port = 1234 local dummy_dir="$(mktemp -d -p $VAR_WWW)"
url = https://yunohost.org file="$dummy_dir/dummy.py"
[dict]
ldap_base = ou=users,dc=yunohost,dc=org
EOF
cat << EOF > $dummy_dir/dummy.py cat << EOF > $dummy_dir/dummy.py
# Some comment # Some comment
@ -26,30 +30,245 @@ THEME = "colib'ris"
EMAIL = "root@example.com" EMAIL = "root@example.com"
PORT = 1234 PORT = 1234
URL = 'https://yunohost.org' URL = 'https://yunohost.org'
DICT = {}
DICT['ldap_base'] = "ou=users,dc=yunohost,dc=org" DICT['ldap_base'] = "ou=users,dc=yunohost,dc=org"
EOF 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 file="$1"
local key="$2" local key="$2"
python3 -c "import yaml; print(yaml.safe_load(open('$file'))['$key'])" 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() { ynhtest_config_read_yaml() {
local dummy_dir="$(mktemp -d -p $VAR_WWW)" local dummy_dir="$(mktemp -d -p $VAR_WWW)"
file="$dummy_dir/dummy.yml" file="$dummy_dir/dummy.yml"
@ -68,33 +287,33 @@ dict:
ldap_base: ou=users,dc=yunohost,dc=org ldap_base: ou=users,dc=yunohost,dc=org
EOF 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_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_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_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_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_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_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" "url")" == "https://yunohost.org"
test "$(ynh_read_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_read_yaml_with_python "$file" "nonexistent" ! _read_yaml "$file" "nonexistent"
test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL" 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" test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL"
} }
@ -117,35 +336,33 @@ dict:
ldap_base: ou=users,dc=yunohost,dc=org ldap_base: ou=users,dc=yunohost,dc=org
EOF EOF
#ynh_write_var_in_file "$file" "foo" "bar" #ynh_write_var_in_file "$file" "foo" "bar"
# cat $dummy_dir/dummy.yml # to debug # 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" #test "$(ynh_read_var_in_file "$file" "foo")" == "bar"
ynh_write_var_in_file "$file" "enabled" "true" 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" test "$(ynh_read_var_in_file "$file" "enabled")" == "true"
ynh_write_var_in_file "$file" "title" "Foo Bar" 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" test "$(ynh_read_var_in_file "$file" "title")" == "Foo Bar"
ynh_write_var_in_file "$file" "theme" "super-awesome-theme" 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" test "$(ynh_read_var_in_file "$file" "theme")" == "super-awesome-theme"
ynh_write_var_in_file "$file" "email" "sam@domain.tld" 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" test "$(ynh_read_var_in_file "$file" "email")" == "sam@domain.tld"
ynh_write_var_in_file "$file" "port" "5678" 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" test "$(ynh_read_var_in_file "$file" "port")" == "5678"
ynh_write_var_in_file "$file" "url" "https://domain.tld/foobar" 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" 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" 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" 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() { ynhtest_config_read_json() {
local dummy_dir="$(mktemp -d -p $VAR_WWW)" local dummy_dir="$(mktemp -d -p $VAR_WWW)"
file="$dummy_dir/dummy.json" file="$dummy_dir/dummy.json"
@ -179,33 +414,33 @@ ynhtest_config_read_json() {
EOF 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_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_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_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_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_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_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" "url")" == "https://yunohost.org"
test "$(ynh_read_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_read_json_with_python "$file" "nonexistent" ! _read_json "$file" "nonexistent"
test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL" 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" test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL"
} }
@ -231,35 +466,35 @@ EOF
#ynh_write_var_in_file "$file" "foo" "bar" #ynh_write_var_in_file "$file" "foo" "bar"
#cat $file #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" #test "$(ynh_read_var_in_file "$file" "foo")" == "bar"
#ynh_write_var_in_file "$file" "enabled" "true" #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" #test "$(ynh_read_var_in_file "$file" "enabled")" == "true"
ynh_write_var_in_file "$file" "title" "Foo Bar" ynh_write_var_in_file "$file" "title" "Foo Bar"
cat $file 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" test "$(ynh_read_var_in_file "$file" "title")" == "Foo Bar"
ynh_write_var_in_file "$file" "theme" "super-awesome-theme" ynh_write_var_in_file "$file" "theme" "super-awesome-theme"
cat $file 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" test "$(ynh_read_var_in_file "$file" "theme")" == "super-awesome-theme"
ynh_write_var_in_file "$file" "email" "sam@domain.tld" ynh_write_var_in_file "$file" "email" "sam@domain.tld"
cat $file 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" test "$(ynh_read_var_in_file "$file" "email")" == "sam@domain.tld"
#ynh_write_var_in_file "$file" "port" "5678" #ynh_write_var_in_file "$file" "port" "5678"
#cat $file #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" #test "$(ynh_read_var_in_file "$file" "port")" == "5678"
ynh_write_var_in_file "$file" "url" "https://domain.tld/foobar" 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" 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" 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 #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() { ynhtest_config_read_php() {
local dummy_dir="$(mktemp -d -p $VAR_WWW)" local dummy_dir="$(mktemp -d -p $VAR_WWW)"
@ -296,33 +547,33 @@ ynhtest_config_read_php() {
?> ?>
EOF 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_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_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_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_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_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_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" "url")" == "https://yunohost.org"
test "$(ynh_read_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_read_php_with_php "$file" "nonexistent" ! _read_php "$file" "nonexistent"
test "$(ynh_read_var_in_file "$file" "nonexistent")" == "YNH_NULL" 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" test "$(ynh_read_var_in_file "$file" "enable")" == "YNH_NULL"
} }
@ -350,36 +601,36 @@ EOF
#ynh_write_var_in_file "$file" "foo" "bar" #ynh_write_var_in_file "$file" "foo" "bar"
#cat $file #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 #test "$(ynh_read_var_in_file "$file" "foo")" == "bar" # FIXME FIXME FIXME
#ynh_write_var_in_file "$file" "enabled" "true" #ynh_write_var_in_file "$file" "enabled" "true"
#cat $file #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 #test "$(ynh_read_var_in_file "$file" "enabled")" == "true" # FIXME FIXME FIXME
ynh_write_var_in_file "$file" "title" "Foo Bar" ynh_write_var_in_file "$file" "title" "Foo Bar"
cat $file cat $file
test "$(_ynh_read_php_with_php "$file" "title")" == "Foo Bar" test "$(_read_php "$file" "title")" == "Foo Bar"
test "$(ynh_read_var_in_file "$file" "title")" == "Foo Bar" test "$(ynh_read_var_in_file "$file" "title")" == "Foo Bar"
ynh_write_var_in_file "$file" "theme" "super-awesome-theme" ynh_write_var_in_file "$file" "theme" "super-awesome-theme"
cat $file 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" test "$(ynh_read_var_in_file "$file" "theme")" == "super-awesome-theme"
ynh_write_var_in_file "$file" "email" "sam@domain.tld" ynh_write_var_in_file "$file" "email" "sam@domain.tld"
cat $file 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" test "$(ynh_read_var_in_file "$file" "email")" == "sam@domain.tld"
#ynh_write_var_in_file "$file" "port" "5678" #ynh_write_var_in_file "$file" "port" "5678"
#cat $file #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" #test "$(ynh_read_var_in_file "$file" "port")" == "5678"
ynh_write_var_in_file "$file" "url" "https://domain.tld/foobar" 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" 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" ynh_write_var_in_file "$file" "ldap_base" "ou=foobar,dc=domain,dc=tld"