Files
subtracks/tools/integration/subsonic.nu
T
austinried f79f26fed8 split the integration harness into server, api and util modules
tools/integration-test.nu is now just the entrypoint. The server lifecycle and fixture preparation live in tools/integration/servers.nu, the Subsonic request helpers in subsonic.nu, and shared waiting/port helpers in util.nu. No behaviour change; the assertions still live in the Kotlin tests.
2026-10-04 00:30:05 +00:00

44 lines
1.9 KiB
Nu

# Thin Subsonic API client used to inspect and prepare the test servers.
# Nextcloud's Music app reads repeated (array) parameters straight from the raw query string
# without URL-decoding them, so ids must be sent with their unreserved characters intact.
export def url-escape [value: string] {
$value
| url encode
| str replace --all '%2D' '-'
| str replace --all '%2d' '-'
| str replace --all '%2E' '.'
| str replace --all '%2e' '.'
| str replace --all '%5F' '_'
| str replace --all '%5f' '_'
| str replace --all '%7E' '~'
| str replace --all '%7e' '~'
}
export def sub-url [base: string, user: string, pass: string, method: string, params: list<any>] {
let all = ([["u" $user] ["p" $pass] ["v" "1.16.1"] ["c" "subtracks-test"] ["f" "json"]] | append $params)
let query = ($all | each {|p| $"($p.0)=(url-escape ($p.1 | into string))" } | str join "&")
$"($base)rest/($method).view?($query)"
}
export def sub-get [base: string, user: string, pass: string, method: string, params: list<any> = []] {
let response = (http get -m 10sec (sub-url $base $user $pass $method $params) | get "subsonic-response")
if $response.status == "failed" {
error make { msg: $"($method) failed: ($response.error.message? | default 'unknown error')" }
}
$response
}
export def named-id [entities: list<any>, name: string] {
$entities | where {|e| $e.name == $name } | first | get id
}
export def song-id [base: string, user: string, pass: string, album: string, track: int] {
sub-get $base $user $pass "getAlbum" [["id" $album]] | get album.song | where {|s| $s.track == $track } | first | get id
}
export def has-tracks [base: string, user: string, pass: string, album: string, tracks: list<int>] {
let found = sub-get $base $user $pass "getAlbum" [["id" $album]] | get album.song | get track
$tracks | all {|track| $found | any {|f| $f == $track } }
}