@@ -47,18 +47,71 @@ func TestBuildConfigStrategy(t *testing.T) {
4747 },
4848 },
4949 },
50+ Status : buildapi.BuildConfigStatus {
51+ LastVersion : 10 ,
52+ },
53+ }
54+ newBC := & buildapi.BuildConfig {
55+ ObjectMeta : kapi.ObjectMeta {Name : "config-id" , Namespace : "namespace" },
56+ Spec : buildapi.BuildConfigSpec {
57+ RunPolicy : buildapi .BuildRunPolicySerial ,
58+ Triggers : []buildapi.BuildTriggerPolicy {
59+ {
60+ GitHubWebHook : & buildapi.WebHookTrigger {Secret : "12345" },
61+ Type : buildapi .GitHubWebHookBuildTriggerType ,
62+ },
63+ {
64+ Type : "unknown" ,
65+ },
66+ },
67+ CommonSpec : buildapi.CommonSpec {
68+ Source : buildapi.BuildSource {
69+ Git : & buildapi.GitBuildSource {
70+ URI : "http://github.com/my/repository" ,
71+ },
72+ ContextDir : "context" ,
73+ },
74+ Strategy : buildapi.BuildStrategy {
75+ DockerStrategy : & buildapi.DockerBuildStrategy {},
76+ },
77+ Output : buildapi.BuildOutput {
78+ To : & kapi.ObjectReference {
79+ Kind : "DockerImage" ,
80+ Name : "repository/data" ,
81+ },
82+ },
83+ },
84+ },
85+ Status : buildapi.BuildConfigStatus {
86+ LastVersion : 9 ,
87+ },
5088 }
5189 Strategy .PrepareForCreate (buildConfig )
5290 errs := Strategy .Validate (ctx , buildConfig )
5391 if len (errs ) != 0 {
5492 t .Errorf ("Unexpected error validating %v" , errs )
5593 }
5694
57- buildConfig .ResourceVersion = "foo"
58- errs = Strategy .ValidateUpdate (ctx , buildConfig , buildConfig )
95+ // lastversion cannot go backwards
96+ newBC .Status .LastVersion = 9
97+ Strategy .PrepareForUpdate (newBC , buildConfig )
98+ if newBC .Status .LastVersion != buildConfig .Status .LastVersion {
99+ t .Errorf ("Expected version=%d, got %d" , buildConfig .Status .LastVersion , newBC .Status .LastVersion )
100+ }
101+
102+ // lastversion can go forwards
103+ newBC .Status .LastVersion = 11
104+ Strategy .PrepareForUpdate (newBC , buildConfig )
105+ if newBC .Status .LastVersion != 11 {
106+ t .Errorf ("Expected version=%d, got %d" , 11 , newBC .Status .LastVersion )
107+ }
108+
109+ Strategy .PrepareForCreate (buildConfig )
110+ errs = Strategy .Validate (ctx , buildConfig )
59111 if len (errs ) != 0 {
60112 t .Errorf ("Unexpected error validating %v" , errs )
61113 }
114+
62115 invalidBuildConfig := & buildapi.BuildConfig {}
63116 errs = Strategy .Validate (ctx , invalidBuildConfig )
64117 if len (errs ) == 0 {
0 commit comments