@@ -47,18 +47,71 @@ func TestBuildConfigStrategy(t *testing.T) {
47
47
},
48
48
},
49
49
},
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
+ },
50
88
}
51
89
Strategy .PrepareForCreate (buildConfig )
52
90
errs := Strategy .Validate (ctx , buildConfig )
53
91
if len (errs ) != 0 {
54
92
t .Errorf ("Unexpected error validating %v" , errs )
55
93
}
56
94
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 )
59
111
if len (errs ) != 0 {
60
112
t .Errorf ("Unexpected error validating %v" , errs )
61
113
}
114
+
62
115
invalidBuildConfig := & buildapi.BuildConfig {}
63
116
errs = Strategy .Validate (ctx , invalidBuildConfig )
64
117
if len (errs ) == 0 {
0 commit comments