spec: Import make-date from srfi-19.
[software/guile-aws.git] / tests / serialize.scm
1 ;;; guile-aws --- Scheme DSL for the AWS APIs
2 ;;; Copyright © 2021 Ricardo Wurmus <rekado@elephly.net>
3 ;;;
4 ;;; Guile-AWS is free software: you can redistribute it and/or modify
5 ;;; it under the terms of the GNU General Public License as published
6 ;;; by the Free Software Foundation, either version 3 of the License,
7 ;;; or (at your option) any later version.
8 ;;;
9 ;;; Guile-AWS is distributed in the hope that it will be useful, but
10 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ;;; General Public License for more details.
13 ;;;
14 ;;; You should have received a copy of the GNU General Public License
15 ;;; along with this program. If not, see
16 ;;; <http://www.gnu.org/licenses/>.
17
18 (define-module (test-serialize)
19 #:use-module (aws serialize)
20 #:use-module (aws api ec2-2016-11-15)
21 #:use-module (srfi srfi-1)
22 #:use-module (srfi srfi-64))
23
24 (test-begin "serialize")
25
26 (define-syntax-rule (mock (module proc replacement) body ...)
27 "Within BODY, replace the definition of PROC from MODULE with the definition
28 given by REPLACEMENT."
29 (let* ((m (resolve-module 'module))
30 (original (module-ref m 'proc)))
31 (dynamic-wind
32 (lambda () (module-set! m 'proc replacement))
33 (lambda () body ...)
34 (lambda () (module-set! m 'proc original)))))
35
36 (test-equal "simple query serialization"
37 '("ImageId=ami-72aa081b" "MaxCount=1" "MinCount=1")
38 (serialize-aws-value (RunInstancesRequest
39 #:ImageId "ami-72aa081b"
40 #:MinCount 1
41 #:MaxCount 1)))
42
43 (test-equal "simple query serialization with lists"
44 '("ImageId=ami-72aa081b" "MaxCount=1" "MinCount=1"
45 "SecurityGroupId.1=sg-a"
46 "SecurityGroupId.2=sg-b"
47 "SecurityGroupId.3=sg-c")
48 (serialize-aws-value (RunInstancesRequest
49 #:ImageId "ami-72aa081b"
50 #:MinCount 1
51 #:MaxCount 1
52 #:SecurityGroupIds
53 (list "sg-a" "sg-b" "sg-c"))))
54
55 (test-equal "simple query serialization with nested structures"
56 '("ImageId=ami-72aa081b" "MaxCount=1" "MinCount=1"
57 "TagSpecification.1.ResourceType=instance"
58 "TagSpecification.1.Tag.1.Key=project"
59 "TagSpecification.1.Tag.1.Value=pigx-web"
60 "TagSpecification.1.Tag.2.Key=pigx-web:resource"
61 "TagSpecification.1.Tag.2.Value=user-vm"
62 "TagSpecification.1.Tag.3.Key=pigx-web:username"
63 "TagSpecification.1.Tag.3.Value=username"
64 "TagSpecification.1.Tag.4.Key=pigx-web:project"
65 "TagSpecification.1.Tag.4.Value=project")
66 (serialize-aws-value (RunInstancesRequest
67 #:ImageId "ami-72aa081b"
68 #:MinCount 1
69 #:MaxCount 1
70 #:TagSpecifications
71 (list (TagSpecification
72 #:ResourceType "instance"
73 #:Tags (list (Tag #:Key "project"
74 #:Value "pigx-web")
75 (Tag #:Key "pigx-web:resource"
76 #:Value "user-vm")
77 (Tag #:Key "pigx-web:username"
78 #:Value "username")
79 (Tag #:Key "pigx-web:project"
80 #:Value "project")))))))
81
82 ;; TODO: awscli encodes things differently. They use uppercase names
83 ;; for the tags ("Key" and "Value" instead of "key" and "value" as
84 ;; specified in the locationName property).
85
86 ;; TODO: also test that colon is URL encoded.
87
88 (test-end "serialize")