From fe7df8aa63856976730164562648622965c7b563 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Thu, 18 Mar 2021 13:35:29 +0100 Subject: Add serialization tests. --- tests/serialize.scm | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 tests/serialize.scm (limited to 'tests') 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 +;;; +;;; 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 +;;; . + +(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") -- cgit v1.2.3