diff --git a/stdlib/http/http.cue b/stdlib/http/http.cue index fb1949a5..48672474 100644 --- a/stdlib/http/http.cue +++ b/stdlib/http/http.cue @@ -2,7 +2,7 @@ package http import ( "encoding/json" - "strconv" + // "strconv" "alpha.dagger.io/alpine" "alpha.dagger.io/dagger" @@ -32,6 +32,7 @@ import ( shell: path: "/bin/bash" always: true + env: { METHOD: method HEADERS: json.Marshal(request.header) @@ -47,15 +48,15 @@ import ( -L --fail --silent --show-error --write-out "%{http_code}" -X "$METHOD" - -d "$BODY" -o /response ) + [ -n "$BODY" ] && curlArgs+=("-d" "'$BODY'") + headers="$(echo $HEADERS | jq -r 'to_entries | map(.key + ": " + (.value | tostring) + "\n") | add')" while read h; do - curlArgs+=("-H" "$h") + curlArgs+=("-H" "'$h'") done <<< "$headers" - if [ -e /token ]; then curlArgs+=("-H" "Authorization: bearer $(cat /token)") fi @@ -71,11 +72,11 @@ import ( path: "/response" } }.contents @dagger(output) - statusCode: strconv.Atoi({ + statusCode: { os.#File & { from: ctr path: "/status" } - }.contents) @dagger(output) + }.contents @dagger(output) } } diff --git a/stdlib/http/tests/http.cue b/stdlib/http/tests/http.cue index feea0ce4..a4506ef4 100644 --- a/stdlib/http/tests/http.cue +++ b/stdlib/http/tests/http.cue @@ -1,7 +1,8 @@ package http import ( - "encoding/json" + // "encoding/json" + // "strconv" "alpha.dagger.io/alpine" "alpha.dagger.io/os" @@ -12,31 +13,27 @@ TestRequest: { url: "https://api.github.com/" request: header: { Accept: "application/json" - Test: ["A", "B"] } } testRaw: os.#Container & { image: alpine.#Image & { package: jq: "~=1.6" + package: bash: true } env: STATUS: "\(req.response.statusCode)" files: "/content.json": { content: req.response.body mode: 0o500 } - command: #""" - test "$STATUS" = 200 - test "$(cat /content.json | jq -r .current_user_url)" = "https://api.github.com/user" - """# - } - - testJSON: os.#Container & { - env: STATUS: "\(req.response.statusCode)" - env: CONTENT: json.Unmarshal(req.response.body).current_user_url - command: """ - test "$STATUS" = 200 - test "$CONTENT" = "https://api.github.com/user" - """ + shell: { + args: ["--noprofile", "--norc", "-eo", "pipefail", "-c"] + } + command: #Command } } + +#Command: #""" + test "$(cat /content.json | jq -r .current_user_url)" = 'https://api.github.com/user' + test "$STATUS" = "200" + """#