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
|
2024-11-29 14:14:01 +00:00
|
|
|
(is (=
|
|
|
|
[{:current true,
|
|
|
|
:id "b67161fb",
|
|
|
|
:userName "root",
|
|
|
|
:hostName "backup-restore-65bd9b6ff5-z69sn",
|
|
|
|
:created "2024-10-18 13:16:54"}
|
|
|
|
{:current false,
|
|
|
|
:id "521e0760",
|
|
|
|
:userName "root",
|
|
|
|
:hostName "backup-restore-65bd9b6ff5-z69sn",
|
|
|
|
:created "2024-11-18 13:08:16"}]
|
|
|
|
(cut/parse-response "[
|
2024-11-29 10:17:32 +00:00
|
|
|
{
|
|
|
|
\"current\": false,
|
|
|
|
\"id\": \"521e0760\",
|
|
|
|
\"userName\": \"root\",
|
|
|
|
\"hostName\": \"backup-restore-65bd9b6ff5-z69sn\",
|
2024-11-29 14:14:01 +00:00
|
|
|
\"created\": \"2024-11-18 13:08:16\"
|
2024-11-29 10:17:32 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
\"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")))))
|