Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: b76f36a08c
Fetching contributors…

Cannot retrieve contributors at this time

file 210 lines (185 sloc) 7.873 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
;; Copyright (c) 2010 Haphazard House LLC

;; Permission is hereby granted, free of charge, to any person obtaining a copy
;; of this software and associated documentation files (the "Software"), to deal
;; in the Software without restriction, including without limitation the rights
;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
;; copies of the Software, and to permit persons to whom the Software is
;; furnished to do so, subject to the following conditions:

;; The above copyright notice and this permission notice shall be included in
;; all copies or substantial portions of the Software.

;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
;; THE SOFTWARE.

(defpackage :hh-aws-tests
  (:use :cl :asdf :lisp-unit :hh-aws)
   )

(in-package :hh-aws-tests)

(defun uuid-string ()
  (string-trim '(#\Space #\NewLine #\Tab)
                                     (with-output-to-string (os)
                                       (print (uuid:make-v4-uuid) os)
                                       )
                                     )
  )

(define-test create-list-delete-domain-test
  (let (
        (new-domain-name (hh-aws::detokenize (list
                                               (uuid-string)
                                               "unittest"
                                               "codeplume.com"
                                               ) "."
                                              )
                         )
        )
    (assert-true (hh-aws::string-ends-with new-domain-name ".unittest.codeplume.com"))
    (assert-true (db-create-domain new-domain-name))
    (assert-true (member new-domain-name
                         (db-list-domains)
                         :test #'equal
                         )
                 )

    (assert-true (db-delete-domain new-domain-name))
    (assert-false (member new-domain-name
                         (db-list-domains)
                         :test #'equal
                         )
                 )
    )
  )

(define-test put-get-query-delete-attributes-test
  (let (
        (domain-name (hh-aws::detokenize (list
                                           (uuid-string)
                                           "unittest"
                                           "codeplume.com"
                                           ) "."
                                          )
                     )
        (item-name-1 (uuid-string))
        )
    (assert-true (hh-aws::string-ends-with domain-name ".unittest.codeplume.com"))
    (assert-true (db-create-domain domain-name))
    
    (assert-true (db-put-attributes domain-name item-name-1
                                    `(
                                      ("foo" "bar")
                                      ("baz" "wazoo")
                                      )
                                    )
                 )
    (let ( (attributes (db-get-attributes domain-name item-name-1)) )
      (assert-true (every (lambda (a)
                            (member a attributes :test #'equal)
                            )
                          `(
                            ("foo" "bar")
                            ("baz" "wazoo")
                            )
                          )
                   )
      )
    
    (assert-equal (db-query domain-name "['foo'='bar']")
                  `( ,item-name-1 )
                  )
    
    (let ( (item (car (db-query-with-attributes domain-name "" ()))) )
      (assert-true (every (lambda (a)
                            (member a item :test #'equal)
                            )
                          `(,item-name-1 ("foo" "bar")
                                         ("baz" "wazoo")
                                         )
                          )
                   )
      )
    
    (let (
          (item (car (db-query-with-attributes domain-name "" '("foo"))) )
          )
      (assert-true (every (lambda (a)
                            (member a item :test #'equal)
                            )
                          `(,item-name-1 ("foo" "bar")
                                         )
                          )
                   )
      (assert-false (member '("baz" "wazoo") item :test #'equal))
      )
    
    (let (
          (item (car (db-select (hh-aws::format-string "select foo from `~a`"
                                               domain-name)
                                )
                     )
                )
          )
      (assert-true (every (lambda (a)
                            (member a item :test #'equal)
                            )
                          `(,item-name-1 ("foo" "bar")
                                         )
                          )
                   )
      (assert-false (member '("baz" "wazoo") item :test #'equal))
      )
    
    (assert-true (db-delete-attributes domain-name item-name-1 ()))
    
    (assert-false (db-get-attributes domain-name item-name-1))
    
    (db-delete-domain domain-name)
    (assert-false (member domain-name
                          (db-list-domains)
                          :test #'equal
                          )
                  )
    )
  )

(define-test create-delete-bucket-test
  (let (
        (bucket-name (hh-aws::detokenize (list
                                           (hh-aws::format-string "~4,'0D" (random 1000))
                                           "unittest"
                                           "codeplume-com"
                                           ) "-"
                                          )
                     )
        )
    (assert-true (s3-create-bucket bucket-name))
    (assert-true (member bucket-name (s3-list-buckets) :test #'equal))
    (assert-true (s3-delete-bucket bucket-name))
    (assert-false (member bucket-name (s3-list-buckets) :test #'equal))
    )
  )

(define-test put-get-delete-bucket-object-test
  (let (
        (bucket-name (hh-aws::detokenize (list
                                           (hh-aws::format-string "~4,'0D" (random 1000))
                                           "unittest"
                                           "codeplume-com"
                                           ) "-"
                                          )
                     )
        (object-name (hh-aws::detokenize (list
                                           "object"
                                           (hh-aws::format-string "~4,'0D" (random 1000))
                                           ) "-"
                                          )
                     )
        )
    (assert-true (s3-create-bucket bucket-name))
    (assert-true (member bucket-name (s3-list-buckets) :test #'equal))
    
    (assert-true (s3-put-bucket-object bucket-name object-name "foo!"))
    (assert-equal (s3-get-bucket-object bucket-name object-name)
                  "foo!"
                  )
    
    (assert-error 'hh-aws::bucket-not-empty
                  (s3-delete-bucket bucket-name)
                  )
    
    (assert-true (s3-delete-bucket-object bucket-name object-name))
    
    (assert-true (s3-delete-bucket bucket-name))
    (assert-false (member bucket-name (s3-list-buckets) :test #'equal))
    )
  )

(define-test ec2-basics-test
    (assert-true (ec2-list-regions))
  (assert-true (ec2-list-availability-zones))
  )

(run-tests)
Something went wrong with that request. Please try again.