-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added needed documentation, coments and some refactoring.
- Loading branch information
Tim Hawes
committed
Jun 12, 2024
1 parent
14a5b3f
commit f51a633
Showing
3 changed files
with
69 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,21 @@ | ||
(ns cljaws.dynamo-spec) | ||
(ns cljaws.dynamo-spec | ||
(:require [clojure.spec.alpha :as s] | ||
[clojure.spec.gen.alpha :as gen])) | ||
|
||
(require '[clojure.spec.alpha :as s]) | ||
|
||
;; Define the acceptable value types | ||
(s/def ::value (s/or :string string? | ||
:number number? | ||
:bytes bytes?)) | ||
|
||
;; Define the spec for the DynamoDB key map | ||
(s/def ::dynamodb-key | ||
(s/and (s/map-of (s/and keyword? #{:pk :sk}) ::value :count 1))) | ||
|
||
;; Examples of validating maps | ||
(s/valid? ::dynamodb-key {:pk "some string"}) ;; true | ||
(s/valid? ::dynamodb-key {:sk 123}) ;; true | ||
(s/valid? ::dynamodb-key {:pk (byte-array 10)}) ;; true | ||
(s/valid? ::dynamodb-key {:pk "some string" :sk 123}) ;; false, only one key allowed | ||
(s/valid? ::dynamodb-key {:pk [1 2 3]}) ;; false, value is not string, number, or bytes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,40 +106,40 @@ | |
(sut/format-update-item "jira-resource-manager" {:entity-type "group"} {:entity-id "Intern"} | ||
{:resources ["AWS SSO Dev" "AWS SSO Test" "Databricks"]} ["no-op"]))))) | ||
|
||
(deftest test-format-put | ||
(testing "Test format-put" | ||
(deftest test-format-batch-put | ||
(testing "Test format-batch-put" | ||
(is (= {:PutRequest | ||
{:Item | ||
{"AccountId" {:S "key1"}, | ||
"Email" {:S "[email protected]"}, | ||
"description" {:S "Something"}, | ||
"resources" {:L [{:S "resource1"} {:S "resource2"}]}}}} | ||
(sut/format-put {:pk {:AccountId "key1"} | ||
:sk {:Email "[email protected]"} | ||
:attributes {:description "Something" | ||
:resources ["resource1" "resource2"]}}))))) | ||
(sut/format-batch-put {:pk {:AccountId "key1"} | ||
:sk {:Email "[email protected]"} | ||
:attributes {:description "Something" | ||
:resources ["resource1" "resource2"]}}))))) | ||
|
||
(deftest test-format-delete | ||
(testing "Test format-delete" | ||
(deftest test-format-batch-delete | ||
(testing "Test format-batch-delete" | ||
(is (= {:DeleteRequest {:Key {"AccountId" {:S "jfdjd"}, "Email" {:S "[email protected]"}}}} | ||
(sut/format-delete {:pk {:AccountId "jfdjd"} | ||
:sk {:Email "[email protected]"}}))))) | ||
(sut/format-batch-delete {:pk {:AccountId "jfdjd"} | ||
:sk {:Email "[email protected]"}}))))) | ||
|
||
(deftest test-format-operations | ||
(testing "Test format-operations" | ||
(deftest test-format-batch-operations | ||
(testing "Test format-batch-operations" | ||
(is (= [{:PutRequest | ||
{:Item | ||
{"description" {:S "Something"}, | ||
"resources" {:L [{:S "resource1"} {:S "resource2"}]}, | ||
"AccountId" {:S "key1"}, | ||
"Email" {:S "[email protected]"}}}} | ||
{:DeleteRequest {:Key {"AccountId" {:S "jfdjd"}, "Email" {:S "[email protected]"}}}}] | ||
(sut/format-operations {:put [{:pk {:AccountId "key1"} | ||
:sk {:Email "[email protected]"} | ||
:attributes {:description "Something" | ||
:resources ["resource1" "resource2"]}}] | ||
:delete [{:pk {:AccountId "jfdjd"} | ||
:sk {:Email "[email protected]"}}]}))))) | ||
(sut/format-batch-operations {:put [{:pk {:AccountId "key1"} | ||
:sk {:Email "[email protected]"} | ||
:attributes {:description "Something" | ||
:resources ["resource1" "resource2"]}}] | ||
:delete [{:pk {:AccountId "jfdjd"} | ||
:sk {:Email "[email protected]"}}]}))))) | ||
|
||
(deftest test-format-batch-write | ||
(testing "Multiple tables with put and delete items." | ||
|