This repository has been archived by the owner on Jun 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move to new pipeline-state interface for consuming step-result updates (
#131)
- Loading branch information
Showing
5 changed files
with
55 additions
and
11 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
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(ns lambdacd.state.core | ||
"Facade for all functions related to dealing with LambdaCDs state. Wraps the related interfaces to simplify compatibility and API." | ||
(:require [lambdacd.state.protocols :as protocols] | ||
[lambdacd.internal.pipeline-state :as legacy-pipeline-state])) | ||
|
||
(defn state-component [ctx] | ||
(:pipeline-state-component ctx)) | ||
|
||
(defn consume-step-result-update | ||
"update a step-result in the state" | ||
[ctx build-number step-id step-result] | ||
(let [component (state-component ctx)] | ||
(if (satisfies? lambdacd.state.protocols/StepResultUpdateConsumer component) | ||
(protocols/consume-step-result-update component build-number step-id step-result) | ||
(legacy-pipeline-state/update component build-number step-id step-result)))) |
20 changes: 9 additions & 11 deletions
20
src/clj/lambdacd/state/internal/pipeline_state_updater.clj
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(ns lambdacd.state.protocols | ||
"defines protocols that need to be implemented by a state component") | ||
|
||
(defprotocol StepResultUpdateConsumer | ||
"components implementing this protocol can provide the state of a pipeline" | ||
(consume-step-result-update [self build-number step-id step-result])) | ||
|
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
(ns lambdacd.state.core-test | ||
(:require [clojure.test :refer :all] | ||
[shrubbery.core :refer [mock received?]] | ||
[lambdacd.state.core :as s] | ||
[lambdacd.testsupport.data :refer [some-ctx-with]] | ||
[lambdacd.state.protocols :as state-protocols] | ||
[lambdacd.internal.pipeline-state :as legacy-pipeline-state])) | ||
|
||
(def some-build-number 42) | ||
(def some-step-id [0]) | ||
(def some-step-result {:foo :bat}) | ||
|
||
(deftest consume-step-result-update-test | ||
(testing "that calls to a StepResultUpdateConsumer will just pass through" | ||
(let [component (mock state-protocols/StepResultUpdateConsumer)] | ||
(s/consume-step-result-update (some-ctx-with :pipeline-state-component component) | ||
some-build-number some-step-id some-step-result) | ||
(is (received? component state-protocols/consume-step-result-update [some-build-number some-step-id some-step-result])))) | ||
(testing "that calls to a legacy PipelineStateComponent be mapped to that method" | ||
(let [component (mock legacy-pipeline-state/PipelineStateComponent)] | ||
(s/consume-step-result-update (some-ctx-with :pipeline-state-component component) | ||
some-build-number some-step-id some-step-result) | ||
(is (received? component legacy-pipeline-state/update [some-build-number some-step-id some-step-result]))))) |