76 lines
2.2 KiB
Plaintext
76 lines
2.2 KiB
Plaintext
|
|
use sc.nu
|
|
use xs.nu
|
|
use bm.nu
|
|
use progress.nu
|
|
use std assert
|
|
|
|
def "assert record contains" [record, key:string, msg:string] {
|
|
assert (($record | get -i $key | is-empty) == false) $msg --error-label {
|
|
start: (metadata $record).span.start,
|
|
end: (metadata $record).span.end,
|
|
text: $"the record does not contains the key ($key)",
|
|
}
|
|
}
|
|
|
|
def "not" [value:bool] {
|
|
return !($value)
|
|
}
|
|
|
|
def "assert is not empty" [list, msg:string] {
|
|
assert (not ($list | is-empty)) $msg --error-label {
|
|
start: (metadata $list).span.start,
|
|
end: (metadata $list).span.end,
|
|
text: $"the list is not empty but it is",
|
|
}
|
|
|
|
}
|
|
|
|
def test [name: string, call] {
|
|
let accum = $in
|
|
print $"Executing: ($name)..."
|
|
let next = (try {
|
|
let result = ($accum | do $call ($accum | last | get -i result | default {}))
|
|
print "PASS"
|
|
{
|
|
name: $name,
|
|
status: PASS,
|
|
result: $result,
|
|
}
|
|
} catch { |e|
|
|
throw $e.raw
|
|
{
|
|
name: $name,
|
|
status: FAIL,
|
|
error: $e.msg,
|
|
}
|
|
})
|
|
$accum | append $next
|
|
}
|
|
|
|
export def main [] {
|
|
[{}]
|
|
| test "can login into smart cloud" { |_|
|
|
let response = (sc request-token)
|
|
assert record contains $response "token" "Token response does not contains a token"
|
|
}
|
|
| test "can create a service" { |_|
|
|
xs service ([(bm find xs-reg), "00001.jpg"] | path join) | last
|
|
}
|
|
| test "service is in pending state" { |new_service|
|
|
print $new_service.externalId
|
|
let services = (xs list-service | where externalId == $new_service.externalId)
|
|
assert is not empty $services $"the new create service ($new_service | select name externalId ) can be listed"
|
|
$new_service
|
|
}
|
|
| test "service will be in success state eventually" { |new_service|
|
|
assert (progress wait-until {
|
|
print $"check status for ($new_service.externalId)"
|
|
let status = (xs list-service | where externalId == $new_service.externalId | last | get -i status | default "")
|
|
print $"Has status ($status)"
|
|
$status == "SUCCESS"
|
|
} --step-time 1sec --overall 20sec
|
|
)
|
|
$new_service
|
|
}
|
|
} |