summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2021-03-18 13:35:29 +0100
committerRicardo Wurmus <rekado@elephly.net>2021-03-18 13:35:29 +0100
commitfe7df8aa63856976730164562648622965c7b563 (patch)
treec9b0a7a8bb027e22cc0c44c44f52b43341a8f817 /tests
parentba29d0b6cb352169d3f961c40b301ccbcba96247 (diff)
Add serialization tests.
Diffstat (limited to 'tests')
-rw-r--r--tests/serialize.scm88
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/serialize.scm b/tests/serialize.scm
new file mode 100644
index 0000000..ef851ba
--- /dev/null
+++ b/tests/serialize.scm
@@ -0,0 +1,88 @@
+;;; guile-aws --- Scheme DSL for the AWS APIs
+;;; Copyright © 2021 Ricardo Wurmus <rekado@elephly.net>
+;;;
+;;; Guile-AWS is free software: you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published
+;;; by the Free Software Foundation, either version 3 of the License,
+;;; or (at your option) any later version.
+;;;
+;;; Guile-AWS is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;;; General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program. If not, see
+;;; <http://www.gnu.org/licenses/>.
+
+(define-module (test-serialize)
+ #:use-module (aws serialize)
+ #:use-module (aws api ec2-2016-11-15)
+ #:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-64))
+
+(test-begin "serialize")
+
+(define-syntax-rule (mock (module proc replacement) body ...)
+ "Within BODY, replace the definition of PROC from MODULE with the definition
+given by REPLACEMENT."
+ (let* ((m (resolve-module 'module))
+ (original (module-ref m 'proc)))
+ (dynamic-wind
+ (lambda () (module-set! m 'proc replacement))
+ (lambda () body ...)
+ (lambda () (module-set! m 'proc original)))))
+
+(test-equal "simple query serialization"
+ '("ImageId=ami-72aa081b" "MaxCount=1" "MinCount=1")
+ (serialize-aws-value (RunInstancesRequest
+ #:ImageId "ami-72aa081b"
+ #:MinCount 1
+ #:MaxCount 1)))
+
+(test-equal "simple query serialization with lists"
+ '("ImageId=ami-72aa081b" "MaxCount=1" "MinCount=1"
+ "SecurityGroupId.1=sg-a"
+ "SecurityGroupId.2=sg-b"
+ "SecurityGroupId.3=sg-c")
+ (serialize-aws-value (RunInstancesRequest
+ #:ImageId "ami-72aa081b"
+ #:MinCount 1
+ #:MaxCount 1
+ #:SecurityGroupIds
+ (list "sg-a" "sg-b" "sg-c"))))
+
+(test-equal "simple query serialization with nested structures"
+ '("ImageId=ami-72aa081b" "MaxCount=1" "MinCount=1"
+ "TagSpecification.1.resourceType=instance"
+ "TagSpecification.1.Tag.1.key=project"
+ "TagSpecification.1.Tag.1.value=pigx-web"
+ "TagSpecification.1.Tag.2.key=pigx-web:resource"
+ "TagSpecification.1.Tag.2.value=user-vm"
+ "TagSpecification.1.Tag.3.key=pigx-web:username"
+ "TagSpecification.1.Tag.3.value=username"
+ "TagSpecification.1.Tag.4.key=pigx-web:project"
+ "TagSpecification.1.Tag.4.value=project")
+ (serialize-aws-value (RunInstancesRequest
+ #:ImageId "ami-72aa081b"
+ #:MinCount 1
+ #:MaxCount 1
+ #:TagSpecifications
+ (list (TagSpecification
+ #:ResourceType "instance"
+ #:Tags (list (Tag #:Key "project"
+ #:Value "pigx-web")
+ (Tag #:Key "pigx-web:resource"
+ #:Value "user-vm")
+ (Tag #:Key "pigx-web:username"
+ #:Value "username")
+ (Tag #:Key "pigx-web:project"
+ #:Value "project")))))))
+
+;; TODO: awscli encodes things differently. They use uppercase names
+;; for the tags ("Key" and "Value" instead of "key" and "value" as
+;; specified in the locationName property).
+
+;; TODO: also test that colon is URL encoded.
+
+(test-end "serialize")