Skip to content

Commit

Permalink
remove '&' from module tests
Browse files Browse the repository at this point in the history
and mandate tmpl_require_enum=yes for them.
  • Loading branch information
alandekok committed Jan 19, 2025
1 parent ee093de commit 9f2f449
Show file tree
Hide file tree
Showing 168 changed files with 1,582 additions and 1,575 deletions.
4 changes: 2 additions & 2 deletions src/tests/modules/all.mk
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ $(OUTPUT)/%: $(DIR)/%.unlang $(TEST_BIN_DIR)/unit_test_module | build.raddb
@echo "MODULE-TEST $(TEST)"
${Q}mkdir -p $(dir $@)
${Q}cp $(if $(wildcard $(basename $<).attrs),$(basename $<).attrs,src/tests/modules/default-input.attrs) $@.attrs
${Q}if ! MODULE_TEST_DIR=$(dir $<) MODULE_TEST_UNLANG=$< TEST="$(TEST)" $(TEST_BIN)/unit_test_module -D share/dictionary -d src/tests/modules/ -i "$@.attrs" -f "$@.attrs" -r "$@" -xxx > "$@.log" 2>&1 || ! test -f "$@"; then \
${Q}if ! MODULE_TEST_DIR=$(dir $<) MODULE_TEST_UNLANG=$< TEST="$(TEST)" $(TEST_BIN)/unit_test_module -D share/dictionary -d src/tests/modules/ -i "$@.attrs" -f "$@.attrs" -r "$@" -xxx -S require_enum_prefix=yes > "$@.log" 2>&1 || ! test -f "$@"; then \
if ! grep ERROR $< 2>&1 > /dev/null; then \
if grep 'LeakSanitizer has encountered a fatal error' $@.log 2>&1 > /dev/null; then \
echo "MODULE-TEST $(TEST) - ignoring LeakSanitizer fatal error."; \
exit 0; \
fi; \
cat "$@.log"; \
echo "# $@.log"; \
echo "MODULE_TEST_DIR=$(dir $<) MODULE_TEST_UNLANG=$< $(TEST_BIN)/unit_test_module -D share/dictionary -d src/tests/modules/ -i \"$@.attrs\" -f \"$@.attrs\" -r \"$@\" -xx"; \
echo "MODULE_TEST_DIR=$(dir $<) MODULE_TEST_UNLANG=$< $(TEST_BIN)/unit_test_module -D share/dictionary -d src/tests/modules/ -i \"$@.attrs\" -f \"$@.attrs\" -r \"$@\" -S require_enum_prefix=yes -xx"; \
exit 1; \
fi; \
FOUND=$$(grep -E 'Error : $<' $@.log | head -1 | sed 's/.*\[//;s/\].*//'); \
Expand Down
16 changes: 8 additions & 8 deletions src/tests/modules/always/set_rcode.unlang
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Set status to "notfound". xlat should expand to previous status, "alive"
#
if (%db_status('notfound') != "alive") {
&reply += {
&Reply-Message = "Failure in test at line %interpreter(...line)"
reply += {
Reply-Message = "Failure in test at line %interpreter(...line)"
}
}

Expand All @@ -12,8 +12,8 @@ if (%db_status('notfound') != "alive") {
#
db_status
if (!notfound) {
&reply += {
&Reply-Message = "Failure in test at line %interpreter(...line)"
reply += {
Reply-Message = "Failure in test at line %interpreter(...line)"
}
}

Expand All @@ -22,8 +22,8 @@ if (!notfound) {
# Fetch status using xlat without setting the status
#
if (%db_status() != "notfound") {
&reply += {
&Reply-Message = "Failure in test at line %interpreter(...line)"
reply += {
Reply-Message = "Failure in test at line %interpreter(...line)"
}
}

Expand All @@ -33,8 +33,8 @@ if (%db_status() != "notfound") {
#
db_status
if (notfound) {
&reply += {
&Reply-Message = "success"
reply += {
Reply-Message = "success"
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tests/modules/always/set_status_dead.unlang
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ db_status {
}

if (fail) {
&reply.Reply-Message := "success"
reply.Reply-Message := "success"
}

&control.Password.Cleartext := "hello"
8 changes: 4 additions & 4 deletions src/tests/modules/always/set_status_revive.unlang
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ db_status {
fail = 1
}
if (!fail) {
&reply += {
&Reply-Message = "Failure in test at line %interpreter(...line)"
reply += {
Reply-Message = "Failure in test at line %interpreter(...line)"
}
}

Expand All @@ -18,8 +18,8 @@ if (!fail) {
%db_status('alive')
db_status
if (ok) {
&reply += {
&Reply-Message = "success"
reply += {
Reply-Message = "success"
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tests/modules/attr_filter/bob.unlang
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ attr_filter
&control.Password.Cleartext := "goodbye"

&reply += {
&Reply-Message = "success"
Reply-Message = "success"
}
22 changes: 11 additions & 11 deletions src/tests/modules/attr_filter/operators.unlang
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
# Copy request to reply for later
&reply := &request
&reply := request

attr_filter

if ((!&NAS-Port) || (&NAS-Port != 10)) {
if ((!NAS-Port) || (NAS-Port != 10)) {
test_fail
}

if (&Idle-Timeout) {
if (Idle-Timeout) {
test_fail
}

if ((&Called-Station-Id != "bar") || (&Called-Station-Id[1])) {
if ((Called-Station-Id != "bar") || (Called-Station-Id[1])) {
test_fail
}

if ((&Service-Type != 5) || (&Service-Type[1])) {
if ((Service-Type != 5) || (Service-Type[1])) {
test_fail
}

if ((&Framed-IP-Address != 192.168.10.20) || (&Framed-IP-Address[1])) {
if ((Framed-IP-Address != 192.168.10.20) || (Framed-IP-Address[1])) {
test_fail
}

if ((&Calling-Station-Id != "bob") || (&Calling-Station-Id[1] != "jim") || (&Calling-Station-Id[2])) {
if ((Calling-Station-Id != "bob") || (Calling-Station-Id[1] != "jim") || (Calling-Station-Id[2])) {
test_fail
}

if (!&reply.Idle-Timeout) {
if (!reply.Idle-Timeout) {
test_fail
}

Expand All @@ -36,15 +36,15 @@ if (!&reply.Idle-Timeout) {
#
attr_filter.reply

if (!&NAS-Port || &NAS-Port != 10) {
if (!NAS-Port || NAS-Port != 10) {
test_fail
}

if (&reply.Idle-Timeout) {
if (reply.Idle-Timeout) {
test_fail
}

&reply := {}

&control.Password.Cleartext := "goodbye"
&reply.Reply-Message := &Reply-Message
&reply.Reply-Message := Reply-Message
16 changes: 8 additions & 8 deletions src/tests/modules/brotli/compress-decompress.unlang
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ group {
string compressed
string decompressed

&uncompressed := "cn=subscriber12345,ou=subscribers,dc=example,dc=com"
&compressed := %brotli.compress(%{uncompressed})
uncompressed := "cn=subscriber12345,ou=subscribers,dc=example,dc=com"
compressed := %brotli.compress(%{uncompressed})

if (%length(%{compressed}) == 0) {
test_fail
Expand All @@ -20,8 +20,8 @@ group {
test_fail
}

&decompressed := %brotli.decompress(%{compressed})
if (&decompressed != &uncompressed) {
decompressed := %brotli.decompress(%{compressed})
if (decompressed != uncompressed) {
test_fail
}
}
Expand All @@ -32,8 +32,8 @@ group {
string compressed
string decompressed

&uncompressed := ""
&compressed := %brotli.compress(%{uncompressed})
uncompressed := ""
compressed := %brotli.compress(%{uncompressed})

# Should have a brotli header
if (%length(%{compressed}) != 1) {
Expand All @@ -44,8 +44,8 @@ group {
test_fail
}

&decompressed := %brotli.decompress(%{compressed})
if (&decompressed != &uncompressed) {
decompressed := %brotli.decompress(%{compressed})
if (decompressed != uncompressed) {
test_fail
}

Expand Down
38 changes: 19 additions & 19 deletions src/tests/modules/cache_memcached/module.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ cache {
ttl = 5

update {
&Callback-Id := &control.Callback-Id[0]
&NAS-Port := &control.NAS-Port[0]
&control += &reply
Callback-Id := control.Callback-Id[0]
NAS-Port := control.NAS-Port[0]
control += reply
}

add_stats = yes
Expand All @@ -36,27 +36,27 @@ cache cache_update {
#
update {
# Copy reply to session-state
&session-state += &reply
session-state += reply

# Implicit cast between types (and multivalue copy)
&Filter-Id += &NAS-Port[*]
Filter-Id += NAS-Port[*]

# Cache the result of an exec
&Callback-Id := `/bin/echo 'echo test'`
Callback-Id := `/bin/echo 'echo test'`

# Create three string values and overwrite the middle one
&Login-LAT-Service += 'foo'
&Login-LAT-Service += 'bar'
&Login-LAT-Service += 'baz'
Login-LAT-Service += 'foo'
Login-LAT-Service += 'bar'
Login-LAT-Service += 'baz'

&Login-LAT-Service[1] := 'rab'
Login-LAT-Service[1] := 'rab'

# Create three string values, then remove one
&Login-LAT-Node += 'foo'
&Login-LAT-Node += 'bar'
&Login-LAT-Node += 'baz'
Login-LAT-Node += 'foo'
Login-LAT-Node += 'bar'
Login-LAT-Node += 'baz'

&Login-LAT-Node -= 'bar'
Login-LAT-Node -= 'bar'
}
}

Expand All @@ -71,11 +71,11 @@ cache cache_update {
# options = "--SERVER=$ENV{CACHE_MEMCACHED_TEST_SERVER}"
# }

# key = &Class
# key = Class
# ttl = 5

# update {
# &Callback-Id := &Callback-Id[0]
# Callback-Id := Callback-Id[0]
# }
#}

Expand All @@ -86,11 +86,11 @@ cache cache_update {
# options = "--SERVER=$ENV{CACHE_MEMCACHED_TEST_SERVER}"
# }

# key = &Framed-IP-Address
# key = Framed-IP-Address
# ttl = 5

# update {
# &Callback-Id := &Callback-Id[0]
# Callback-Id := Callback-Id[0]
# }
#}

Expand All @@ -117,6 +117,6 @@ cache static_key {
ttl = 5

update {
&Callback-Id := &Callback-Id[0]
Callback-Id := Callback-Id[0]
}
}
22 changes: 11 additions & 11 deletions src/tests/modules/cache_rbtree/cache-bin.unlang
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
&Callback-Id := "foo\000bar\000baz"

# 0. Sanity check
if (&Callback-Id != "foo\000bar\000baz") {
if (Callback-Id != "foo\000bar\000baz") {
test_fail
}

Expand All @@ -30,7 +30,7 @@ if (!updated) {
test_fail
}

&request -= &Callback-Id[*]
&request -= Callback-Id[*]

# If the key is binary safe, we should now be able to retrieve the first entry
# if it's not, the above test will likely fail, or we'll get the second entry.
Expand All @@ -45,11 +45,11 @@ if (%length(%{Callback-Id}) != 11) {
test_fail
}

if (&Callback-Id != "foo\000bar\000baz") {
if (Callback-Id != "foo\000bar\000baz") {
test_fail
}

&request -= &Callback-Id[*]
&request -= Callback-Id[*]

# Now try and get the second entry
&Class := 0xaa00bb00cc00ee00
Expand All @@ -63,11 +63,11 @@ if (%length(%{Callback-Id}) != 7) {
test_fail
}

if (&Callback-Id != "bar\000baz") {
if (Callback-Id != "bar\000baz") {
test_fail
}

&request -= &Callback-Id[*]
&request -= Callback-Id[*]

#
# We should also be able to use any fixed length data type as a key
Expand All @@ -90,7 +90,7 @@ if (!ok) {
test_fail
}

&request -= &Callback-Id[*]
&request -= Callback-Id[*]

# Now retrieve the first entry
&Framed-IP-Address := 192.168.0.1
Expand All @@ -104,11 +104,11 @@ if (%length(%{Callback-Id}) != 11) {
test_fail
}

if (&Callback-Id != "foo\000bar\000baz") {
if (Callback-Id != "foo\000bar\000baz") {
test_fail
}

&request -= &Callback-Id[*]
&request -= Callback-Id[*]

# Now try and get the second entry
&Framed-IP-Address := 192.168.0.2
Expand All @@ -122,10 +122,10 @@ if (%length(%{Callback-Id}) != 7) {
test_fail
}

if (&Callback-Id != "bar\000baz") {
if (Callback-Id != "bar\000baz") {
test_fail
}

&request -= &Callback-Id[*]
&request -= Callback-Id[*]

test_pass
Loading

0 comments on commit 9f2f449

Please sign in to comment.