|
2 | 2 | (:use [lambdacd.testsupport.test-util])
|
3 | 3 | (:require [clojure.test :refer :all]
|
4 | 4 | [lambdacd.internal.default-pipeline-state-persistence :refer :all]
|
| 5 | + [lambdacd.presentation.pipeline-structure-test :as pipeline-structure-test] |
5 | 6 | [clj-time.core :as t]
|
6 | 7 | [lambdacd.util :as utils]
|
7 | 8 | [clojure.java.io :as io]))
|
8 | 9 |
|
9 | 10 | (deftest roundtrip-persistence-test
|
10 |
| - (testing "the standard case" |
11 |
| - (let [some-pipeline-state {3 {'(0) {:status :success :most-recent-update-at (t/epoch)} |
12 |
| - '(0 1 2) {:status :failure :out "something went wrong"}}} |
13 |
| - home-dir (utils/create-temp-dir)] |
14 |
| - (write-build-history home-dir 3 some-pipeline-state) |
15 |
| - (is (= some-pipeline-state (read-build-history-from home-dir))))) |
16 |
| - (testing "that string-keys in a step result are suppored as well (#101)" |
17 |
| - (let [some-pipeline-state {3 {'(0) {:status :success :_git-last-seen-revisions {"refs/heads/master" "some-sha"}}}} |
18 |
| - home-dir (utils/create-temp-dir)] |
19 |
| - (write-build-history home-dir 3 some-pipeline-state) |
20 |
| - (is (= some-pipeline-state (read-build-history-from home-dir))))) |
21 |
| - (testing "that keyworded values in a step result are suppored as well (#101)" |
22 |
| - (let [some-pipeline-state {3 {'(0) {:status :success :v :x}}} |
23 |
| - home-dir (utils/create-temp-dir)] |
24 |
| - (write-build-history home-dir 3 some-pipeline-state) |
25 |
| - (is (= some-pipeline-state (read-build-history-from home-dir))))) |
| 11 | + (testing "pipeline-state" |
| 12 | + (testing "the standard case" |
| 13 | + (let [some-pipeline-state {3 {'(0) {:status :success :most-recent-update-at (t/epoch)} |
| 14 | + '(0 1 2) {:status :failure :out "something went wrong"}}} |
| 15 | + home-dir (utils/create-temp-dir)] |
| 16 | + (write-build-history home-dir 3 some-pipeline-state) |
| 17 | + (is (= some-pipeline-state (read-build-history-from home-dir))))) |
| 18 | + (testing "that string-keys in a step result are supported as well (#101)" |
| 19 | + (let [some-pipeline-state {3 {'(0) {:status :success :_git-last-seen-revisions {"refs/heads/master" "some-sha"}}}} |
| 20 | + home-dir (utils/create-temp-dir)] |
| 21 | + (write-build-history home-dir 3 some-pipeline-state) |
| 22 | + (is (= some-pipeline-state (read-build-history-from home-dir))))) |
| 23 | + (testing "that keyworded values in a step result are suppored as well (#101)" |
| 24 | + (let [some-pipeline-state {3 {'(0) {:status :success :v :x}}} |
| 25 | + home-dir (utils/create-temp-dir)] |
| 26 | + (write-build-history home-dir 3 some-pipeline-state) |
| 27 | + (is (= some-pipeline-state (read-build-history-from home-dir)))))) |
| 28 | + (testing "pipeline-structure" |
| 29 | + (testing "the standard case" |
| 30 | + (let [home-dir (utils/create-temp-dir) |
| 31 | + some-pipeline-structure pipeline-structure-test/foo-pipeline-display-representation] |
| 32 | + (write-pipeline-structure home-dir 1 some-pipeline-structure) |
| 33 | + (write-pipeline-structure home-dir 2 some-pipeline-structure) |
| 34 | + (is (= some-pipeline-structure (get (read-pipeline-structures home-dir) 1))) |
| 35 | + (is (= some-pipeline-structure (get (read-pipeline-structures home-dir) 2))))))) |
| 36 | + |
| 37 | +(deftest clean-up-old-builds-test |
26 | 38 | (testing "cleaning up old history"
|
27 |
| - (testing "that build-directories will be deleted if they no longer exist in the build-state" |
28 |
| - (let [some-pipeline-state {0 {'(0) {:status :success}} |
29 |
| - 1 {'(0) {:status :success}} |
30 |
| - 2 {'(0) {:status :success}}} |
31 |
| - truncated-pipeline-state {1 {'(0) {:status :success}} |
| 39 | + (testing "that given build-directories will be deleted" |
| 40 | + (let [some-pipeline-state {0 {'(0) {:status :success}} |
| 41 | + 1 {'(0) {:status :success}} |
32 | 42 | 2 {'(0) {:status :success}}}
|
33 |
| - home-dir (utils/create-temp-dir)] |
| 43 | + home-dir (utils/create-temp-dir)] |
34 | 44 | (doall (for [build (range 0 3)]
|
35 | 45 | (write-build-history home-dir build some-pipeline-state)))
|
36 | 46 | (doall (for [build (range 0 3)]
|
|
39 | 49 | (is (.exists (io/file home-dir "build-0")))
|
40 | 50 | (is (.exists (io/file home-dir "build-1")))
|
41 | 51 | (is (.exists (io/file home-dir "build-2")))
|
42 |
| - (clean-up-old-history home-dir truncated-pipeline-state) |
| 52 | + (clean-up-old-builds home-dir [0]) |
43 | 53 |
|
44 | 54 | (is (not (.exists (io/file home-dir "build-0"))))
|
45 | 55 | (is (.exists (io/file home-dir "build-1")))
|
46 | 56 | (is (.exists (io/file home-dir "build-2")))))
|
47 | 57 | (testing "that it does not clean up things other than build directories"
|
48 |
| - (let [truncated-pipeline-state {} |
49 |
| - home-dir (utils/create-temp-dir)] |
| 58 | + (let [home-dir (utils/create-temp-dir)] |
50 | 59 | (.mkdirs (io/file home-dir "helloworld"))
|
51 | 60 | (is (.exists (io/file home-dir "helloworld")))
|
52 |
| - (clean-up-old-history home-dir truncated-pipeline-state) |
| 61 | + (clean-up-old-builds home-dir [0]) |
53 | 62 | (is (.exists (io/file home-dir "helloworld")))))))
|
54 | 63 |
|
| 64 | +(deftest read-build-history-from-test ; covers only edge-cases that aren't coverd by roundtrip |
| 65 | + (testing "that it will return an empty history if no state has been written yet" |
| 66 | + (let [home-dir (utils/create-temp-dir)] |
| 67 | + (is (= {} (read-build-history-from home-dir))))) |
| 68 | + (testing "that it ignores build directories with no build state (e.g. because only structure has been written yet" |
| 69 | + (let [home-dir (utils/create-temp-dir)] |
| 70 | + (.mkdirs (io/file home-dir "build-1")) |
| 71 | + (is (= {} (read-build-history-from home-dir)))))) |
| 72 | + |
| 73 | +(deftest read-pipeline-structures-test ; covers only edge-cases that aren't covered by roundtrip |
| 74 | + (testing "that it will return an empty data if no state has been written yet" |
| 75 | + (let [home-dir (utils/create-temp-dir)] |
| 76 | + (is (= {} (read-pipeline-structures home-dir))))) |
| 77 | + (testing "that it ignores build directories with no pipeline structure (e.g. because they were created before this feature was available)" |
| 78 | + (let [home-dir (utils/create-temp-dir)] |
| 79 | + (.mkdirs (io/file home-dir "build-1")) |
| 80 | + (is (= {} (read-pipeline-structures home-dir)))))) |
| 81 | + |
55 | 82 | (defn- roundtrip-date-time [data]
|
56 | 83 | (dates->clj-times
|
57 | 84 | (clj-times->dates data)))
|
|
0 commit comments