dda-backup/test/dda/backup/cred_rot/domain_test.clj

51 lines
1.5 KiB
Clojure
Raw Normal View History

2024-10-25 10:08:51 +00:00
(ns dda.backup.cred-rot.domain-test
(:require
[clojure.test :refer [deftest is]]
[clojure.spec.alpha :as s]
[clojure.spec.test.alpha :as st]
[dda.backup.cred-rot.domain :as cut]))
2024-11-29 10:17:32 +00:00
(deftest test-parse-response
(is (= [] (cut/parse-response "[
{
\"current\": false,
\"id\": \"521e0760\",
\"userName\": \"root\",
\"hostName\": \"backup-restore-65bd9b6ff5-z69sn\",
\"created\": \"2024-10-18 13:08:16\"
},
{
\"current\": true,
\"id\": \"b67161fb\",
\"userName\": \"root\",
\"hostName\": \"backup-restore-65bd9b6ff5-z69sn\",
\"created\": \"2024-10-18 13:16:54\"
}
]"))))
2024-10-25 10:08:51 +00:00
(deftest test-spec-id
(is (s/valid? ::cut/id "521e0760"))
(is (s/valid? ::cut/id "test"))
(is (s/valid? ::cut/id "123456"))
(is (not (s/valid? ::cut/id "ROOT")))
(is (not (s/valid? ::cut/id "Test!"))))
(deftest test-spec-username
(is (s/valid? ::cut/userName "521e0760"))
(is (s/valid? ::cut/userName "Testuser"))
(is (s/valid? ::cut/userName "root"))
(is (s/valid? ::cut/userName "ROOT"))
(is (not (s/valid? ::cut/userName "test-user"))))
(deftest test-spec-hostName
(let [valid #(s/valid? ::cut/hostName %)]
(is (valid "test-some-combination-2"))
(is (valid "backup-restore-65bd9b6ff5-z69sn"))))
2024-11-29 10:17:32 +00:00
(deftest test-spec-timestamp
(let [valid #(s/valid? cut/timestamp? %)]
2024-10-25 10:08:51 +00:00
(is (valid "2024-10-18 13:08:16"))
(is (valid "2032-09-01 12:56:59"))
(is (not (valid "2024-13-5 13:08:16")))
(is (not (valid "2024-6-42 13:08:16")))
(is (not (valid "test")))))