Skip to content
This repository has been archived by the owner on Jun 15, 2024. It is now read-only.

Commit

Permalink
Implement NextBuildNumberSource #131
Browse files Browse the repository at this point in the history
  • Loading branch information
flosell committed Oct 17, 2016
1 parent 49e13d0 commit bb191b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/clj/lambdacd/internal/default_pipeline_state.clj
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
@state-atom)
(get-internal-state [self]
state-atom)
(next-build-number [self]
(inc (most-recent-build-number-in-state @state-atom)))

protocols/PipelineStructureConsumer
(consume-pipeline-structure [self build-number pipeline-structure-representation]
Expand All @@ -64,7 +62,10 @@
(persistence/write-build-history home-dir build-number new-state)))
protocols/QueryStepResultsSource
(get-step-results [self build-number]
(get @state-atom build-number)))
(get @state-atom build-number))
protocols/NextBuildNumberSource
(next-build-number [self]
(inc (most-recent-build-number-in-state @state-atom))))

(defn new-default-pipeline-state [config & {:keys [initial-state-for-testing]}]
(let [home-dir (:home-dir config)
Expand Down
15 changes: 5 additions & 10 deletions test/clj/lambdacd/internal/default_pipeline_state_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@
(:use [lambdacd.testsupport.test-util])
(:require [clojure.test :refer :all]
[lambdacd.internal.default-pipeline-state :refer :all]
[lambdacd.internal.pipeline-state :refer [next-build-number] :as pipeline-state-record]
[lambdacd.internal.pipeline-state :refer [next-build-number]]
[lambdacd.util :as utils]
[clj-time.core :as t]
[lambdacd.testsupport.test-util :as tu]
[lambdacd.testsupport.data :refer [some-ctx-with some-ctx]]
[clojure.java.io :as io]
[clojure.edn :as edn]
[lambdacd.state.protocols :as protocols])
(:import (java.util Date)))
[lambdacd.state.protocols :as protocols]))

(def no-home-dir nil)
(def keep-all-builds Integer/MAX_VALUE)

(deftest general-pipeline-state-test
(deftest next-build-number-test
(testing "that the next buildnumber is the highest build-number currently in the pipeline-state"
(is (= 5 (next-build-number (->DefaultPipelineState (atom { 3 {} 4 {} 1 {}}) (atom {}) no-home-dir keep-all-builds))))
(is (= 1 (next-build-number (->DefaultPipelineState (atom clean-pipeline-state) (atom {}) no-home-dir keep-all-builds))))))
(is (= 1 (next-build-number (new-default-pipeline-state {:home-dir (utils/create-temp-dir)}))))
(is (= 5 (next-build-number (new-default-pipeline-state {:home-dir (utils/create-temp-dir)} :initial-state-for-testing { 3 {} 4 {} 1 {}}))))))

(deftest pipeline-structure-state-test
(testing "that we can consume and retrieve pipeline-structure"
Expand Down

0 comments on commit bb191b0

Please sign in to comment.