@@ -1519,7 +1519,7 @@ func Test_postWorkflowRunHandlerWithoutRightConditionsOnHook(t *testing.T) {
1519
1519
assert .Equal (t , 400 , rec .Code )
1520
1520
}
1521
1521
1522
- func Test_postWorkflowRunHandlerWithMutex (t * testing.T ) {
1522
+ func Test_postWorkflowRunHandlerHookWithMutex (t * testing.T ) {
1523
1523
api , db , router , end := newTestAPI (t , bootstrap .InitiliazeDB )
1524
1524
defer end ()
1525
1525
u , pass := assets .InsertAdminUser (api .mustDB ())
@@ -1750,6 +1750,99 @@ func Test_postWorkflowRunHandler_Forbidden(t *testing.T) {
1750
1750
router .Mux .ServeHTTP (rec , req )
1751
1751
assert .Equal (t , 404 , rec .Code )
1752
1752
}
1753
+
1754
+ func Test_postWorkflowRunHandler_ConditionNotOK (t * testing.T ) {
1755
+ api , db , router , end := newTestAPI (t , bootstrap .InitiliazeDB )
1756
+ defer end ()
1757
+ u , pass := assets .InsertAdminUser (api .mustDB ())
1758
+ key := sdk .RandomString (10 )
1759
+ proj := assets .InsertTestProject (t , db , api .Cache , key , key , u )
1760
+
1761
+ gr := & sdk.Group {
1762
+ Name : sdk .RandomString (10 ),
1763
+ }
1764
+ test .NoError (t , group .InsertGroup (db , gr ))
1765
+ test .NoError (t , group .InsertGroupInProject (api .mustDB (), proj .ID , gr .ID , 7 ))
1766
+
1767
+ //First pipeline
1768
+ pip := sdk.Pipeline {
1769
+ ProjectID : proj .ID ,
1770
+ ProjectKey : proj .Key ,
1771
+ Name : "pip1" ,
1772
+ }
1773
+ test .NoError (t , pipeline .InsertPipeline (api .mustDB (), api .Cache , proj , & pip , u ))
1774
+
1775
+ env := & sdk.Environment {
1776
+ Name : sdk .RandomString (10 ),
1777
+ ProjectKey : proj .Key ,
1778
+ ProjectID : proj .ID ,
1779
+ }
1780
+ test .NoError (t , environment .InsertEnvironment (api .mustDB (), env ))
1781
+
1782
+ proj2 , errp := project .Load (api .mustDB (), api .Cache , proj .Key , u , project .LoadOptions .WithPipelines , project .LoadOptions .WithEnvironments )
1783
+ test .NoError (t , errp )
1784
+
1785
+ w := sdk.Workflow {
1786
+ Name : "test_1" ,
1787
+ ProjectID : proj .ID ,
1788
+ ProjectKey : proj .Key ,
1789
+ WorkflowData : & sdk.WorkflowData {
1790
+ Node : sdk.Node {
1791
+ Name : "root" ,
1792
+ Type : sdk .NodeTypePipeline ,
1793
+ Context : & sdk.NodeContext {
1794
+ PipelineID : pip .ID ,
1795
+ EnvironmentID : env .ID ,
1796
+ Conditions : sdk.WorkflowNodeConditions {
1797
+ LuaScript : "return false" ,
1798
+ },
1799
+ },
1800
+ },
1801
+ },
1802
+ }
1803
+
1804
+ test .NoError (t , workflow .Insert (api .mustDB (), api .Cache , & w , proj2 , u ))
1805
+
1806
+ test .NoError (t , user .UpdateUser (api .mustDB (), * u ))
1807
+
1808
+ //Prepare request
1809
+ vars := map [string ]string {
1810
+ "key" : proj .Key ,
1811
+ "permWorkflowName" : w .Name ,
1812
+ }
1813
+ uri := router .GetRoute ("POST" , api .postWorkflowRunHandler , vars )
1814
+ test .NotEmpty (t , uri )
1815
+
1816
+ opts := & sdk.WorkflowRunPostHandlerOption {
1817
+ Manual : & sdk.WorkflowNodeRunManual {
1818
+ Payload : map [string ]string {"foo" : "bar" },
1819
+ },
1820
+ }
1821
+ req := assets .NewAuthentifiedRequest (t , u , pass , "POST" , uri , opts )
1822
+
1823
+ //Do the request
1824
+ rec := httptest .NewRecorder ()
1825
+ router .Mux .ServeHTTP (rec , req )
1826
+
1827
+ assert .Equal (t , 202 , rec .Code )
1828
+
1829
+ // it's an async call, wait a bit the let cds take care of the previous request
1830
+ time .Sleep (3 * time .Second )
1831
+
1832
+ lastRun , err := workflow .LoadLastRun (api .mustDB (), proj .Key , w .Name , workflow.LoadRunOptions {})
1833
+ test .NoError (t , err )
1834
+ assert .Equal (t , int64 (1 ), lastRun .Number )
1835
+ assert .Equal (t , sdk .StatusNeverBuilt .String (), lastRun .Status )
1836
+ // check "Run conditions aren't ok" info
1837
+ var found bool
1838
+ for _ , info := range lastRun .Infos {
1839
+ if info .Message .ID == sdk .MsgWorkflowConditionError .ID {
1840
+ found = true
1841
+ }
1842
+ }
1843
+ assert .Equal (t , true , found )
1844
+ }
1845
+
1753
1846
func Test_postWorkflowRunHandler_BadPayload (t * testing.T ) {
1754
1847
api , db , router , end := newTestAPI (t , bootstrap .InitiliazeDB )
1755
1848
defer end ()
0 commit comments