@@ -1806,197 +1806,6 @@ func TestTaskSpecValidateErrorWithStepResultRef(t *testing.T) {
1806
1806
})
1807
1807
}
1808
1808
}
1809
- func TestTaskSpecValidateSuccessWithArtifactsRefFlagEnabled (t * testing.T ) {
1810
- tests := []struct {
1811
- name string
1812
- Steps []v1.Step
1813
- }{
1814
- {
1815
- name : "reference step artifacts in Env" ,
1816
- Steps : []v1.Step {{
1817
- Image : "busybox" ,
1818
- Env : []corev1.EnvVar {{Name : "AAA" , Value : "$(steps.aaa.outputs.image)" }},
1819
- }},
1820
- },
1821
- {
1822
- name : "reference step artifacts path in Env" ,
1823
- Steps : []v1.Step {{
1824
- Image : "busybox" ,
1825
- Env : []corev1.EnvVar {{Name : "AAA" , Value : "$(step.artifacts.path)" }},
1826
- }},
1827
- },
1828
- {
1829
- name : "reference step artifacts in Script" ,
1830
- Steps : []v1.Step {{
1831
- Image : "busybox" ,
1832
- Script : "echo $(steps.aaa.inputs.bbb)" ,
1833
- }},
1834
- },
1835
- {
1836
- name : "reference step artifacts path in Script" ,
1837
- Steps : []v1.Step {{
1838
- Image : "busybox" ,
1839
- Script : "echo 123 >> $(step.artifacts.path)" ,
1840
- }},
1841
- },
1842
- {
1843
- name : "reference step artifacts in Command" ,
1844
- Steps : []v1.Step {{
1845
- Image : "busybox" ,
1846
- Command : []string {"echo" , "$(steps.aaa.outputs.bbbb)" },
1847
- }},
1848
- },
1849
- {
1850
- name : "reference step artifacts path in Command" ,
1851
- Steps : []v1.Step {{
1852
- Image : "busybox" ,
1853
- Command : []string {"echo" , "$(step.artifacts.path)" },
1854
- }},
1855
- },
1856
- {
1857
- name : "reference step artifacts in Args" ,
1858
- Steps : []v1.Step {{
1859
- Image : "busybox" ,
1860
- Args : []string {"echo" , "$(steps.aaa.outputs.bbbb)" },
1861
- }},
1862
- },
1863
- {
1864
- name : "reference step artifacts path in Args" ,
1865
- Steps : []v1.Step {{
1866
- Image : "busybox" ,
1867
- Args : []string {"echo" , "$(step.artifacts.path)" },
1868
- }},
1869
- },
1870
- }
1871
- for _ , tt := range tests {
1872
- t .Run (tt .name , func (t * testing.T ) {
1873
- ts := v1.TaskSpec {
1874
- Steps : tt .Steps ,
1875
- }
1876
- ctx := config .ToContext (context .Background (), & config.Config {
1877
- FeatureFlags : & config.FeatureFlags {
1878
- EnableStepActions : true ,
1879
- EnableArtifacts : true ,
1880
- },
1881
- })
1882
- ctx = apis .WithinCreate (ctx )
1883
- ts .SetDefaults (ctx )
1884
- err := ts .Validate (ctx )
1885
- if err != nil {
1886
- t .Fatalf ("Expected no errors, got err for %v" , err )
1887
- }
1888
- })
1889
- }
1890
- }
1891
- func TestTaskSpecValidateErrorWithArtifactsRefFlagNotEnabled (t * testing.T ) {
1892
- tests := []struct {
1893
- name string
1894
- Steps []v1.Step
1895
- expectedError apis.FieldError
1896
- }{
1897
- {
1898
- name : "Cannot reference step artifacts in Env without setting enable-artifacts to true" ,
1899
- Steps : []v1.Step {{
1900
- Env : []corev1.EnvVar {{Name : "AAA" , Value : "$(steps.aaa.outputs.image)" }},
1901
- }},
1902
- expectedError : apis.FieldError {
1903
- Message : fmt .Sprintf ("feature flag %s should be set to true to use artifacts feature." , config .EnableArtifacts ),
1904
- Paths : []string {"steps[0]" },
1905
- },
1906
- },
1907
- {
1908
- name : "Cannot reference step artifacts path in Env without setting enable-artifacts to true" ,
1909
- Steps : []v1.Step {{
1910
- Env : []corev1.EnvVar {{Name : "AAA" , Value : "$(step.artifacts.path)" }},
1911
- }},
1912
- expectedError : apis.FieldError {
1913
- Message : fmt .Sprintf ("feature flag %s should be set to true to use artifacts feature." , config .EnableArtifacts ),
1914
- Paths : []string {"steps[0]" },
1915
- },
1916
- },
1917
- {
1918
- name : "Cannot reference step artifacts in Script without setting enable-artifacts to true" ,
1919
- Steps : []v1.Step {{
1920
- Script : "echo $(steps.aaa.inputs.bbb)" ,
1921
- }},
1922
- expectedError : apis.FieldError {
1923
- Message : fmt .Sprintf ("feature flag %s should be set to true to use artifacts feature." , config .EnableArtifacts ),
1924
- Paths : []string {"steps[0]" },
1925
- },
1926
- },
1927
- {
1928
- name : "Cannot reference step artifacts path in Script without setting enable-artifacts to true" ,
1929
- Steps : []v1.Step {{
1930
- Script : "echo 123 >> $(step.artifacts.path)" ,
1931
- }},
1932
- expectedError : apis.FieldError {
1933
- Message : fmt .Sprintf ("feature flag %s should be set to true to use artifacts feature." , config .EnableArtifacts ),
1934
- Paths : []string {"steps[0]" },
1935
- },
1936
- },
1937
- {
1938
- name : "Cannot reference step artifacts in Command without setting enable-artifacts to true" ,
1939
- Steps : []v1.Step {{
1940
- Command : []string {"echo" , "$(steps.aaa.outputs.bbbb)" },
1941
- }},
1942
- expectedError : apis.FieldError {
1943
- Message : fmt .Sprintf ("feature flag %s should be set to true to use artifacts feature." , config .EnableArtifacts ),
1944
- Paths : []string {"steps[0]" },
1945
- },
1946
- },
1947
- {
1948
- name : "Cannot reference step artifacts path in Command without setting enable-artifacts to true" ,
1949
- Steps : []v1.Step {{
1950
- Command : []string {"echo" , "$(step.artifacts.path)" },
1951
- }},
1952
- expectedError : apis.FieldError {
1953
- Message : fmt .Sprintf ("feature flag %s should be set to true to use artifacts feature." , config .EnableArtifacts ),
1954
- Paths : []string {"steps[0]" },
1955
- },
1956
- },
1957
- {
1958
- name : "Cannot reference step artifacts in Args without setting enable-artifacts to true" ,
1959
- Steps : []v1.Step {{
1960
- Args : []string {"echo" , "$(steps.aaa.outputs.bbbb)" },
1961
- }},
1962
- expectedError : apis.FieldError {
1963
- Message : fmt .Sprintf ("feature flag %s should be set to true to use artifacts feature." , config .EnableArtifacts ),
1964
- Paths : []string {"steps[0]" },
1965
- },
1966
- },
1967
- {
1968
- name : "Cannot reference step artifacts path in Args without setting enable-artifacts to true" ,
1969
- Steps : []v1.Step {{
1970
- Args : []string {"echo" , "$(step.artifacts.path)" },
1971
- }},
1972
- expectedError : apis.FieldError {
1973
- Message : fmt .Sprintf ("feature flag %s should be set to true to use artifacts feature." , config .EnableArtifacts ),
1974
- Paths : []string {"steps[0]" },
1975
- },
1976
- },
1977
- }
1978
- for _ , tt := range tests {
1979
- t .Run (tt .name , func (t * testing.T ) {
1980
- ts := v1.TaskSpec {
1981
- Steps : tt .Steps ,
1982
- }
1983
- ctx := config .ToContext (context .Background (), & config.Config {
1984
- FeatureFlags : & config.FeatureFlags {
1985
- EnableStepActions : true ,
1986
- },
1987
- })
1988
- ctx = apis .WithinCreate (ctx )
1989
- ts .SetDefaults (ctx )
1990
- err := ts .Validate (ctx )
1991
- if err == nil {
1992
- t .Fatalf ("Expected an error, got nothing for %v" , ts )
1993
- }
1994
- if d := cmp .Diff (tt .expectedError .Error (), err .Error (), cmpopts .IgnoreUnexported (apis.FieldError {})); d != "" {
1995
- t .Errorf ("TaskSpec.Validate() errors diff %s" , diff .PrintWantGot (d ))
1996
- }
1997
- })
1998
- }
1999
- }
2000
1809
2001
1810
func TestTaskSpecValidateErrorWithArtifactsRef (t * testing.T ) {
2002
1811
tests := []struct {
0 commit comments