create http universe package

Signed-off-by: jffarge <slumbering.pierrot@gmail.com>
This commit is contained in:
jffarge
2021-10-19 15:06:14 +02:00
committed by guillaume
parent fa334f4a86
commit b94b8c0c70
7 changed files with 227 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
package http
import (
"encoding/json"
"alpha.dagger.io/alpine"
"alpha.dagger.io/os"
)
TestRequest: {
req: #Get & {
url: "https://api.github.com/"
request: header: {
Accept: "application/json"
Test: ["A", "B"]
}
}
testRaw: os.#Container & {
image: alpine.#Image & {
package: jq: "~=1.6"
}
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"
"""
}
}