@@ -199,7 +199,7 @@ func AugmentFromEnv(info Info) Info {
199199}
200200
201201func ValidateStrict (versionInfo Info ) error {
202- fmt . Println ( versionInfo . ToPrettyJSON ())
202+ // Check if all fields are set
203203 infoType := reflect .ValueOf (versionInfo )
204204 for i := 0 ; i < infoType .NumField (); i ++ {
205205 fieldType := infoType .Type ().Field (i )
@@ -208,11 +208,25 @@ func ValidateStrict(versionInfo Info) error {
208208 }
209209 }
210210
211+ // Ensure that the git state is clean.
211212 if versionInfo .GitTreeState == GitTreeStateDirty {
212213 return errors .New ("goversion requires a clean git tree state in strict mode" )
213214 }
214215
215- // TODO validate date fields
216+ // Validate the format of GitCommitDate timestamp.
217+ if ts , err := time .Parse (time .RFC3339 , versionInfo .GitCommitDate ); err != nil {
218+ return fmt .Errorf ("date format in gitCommitDate is not a valid RFC3339 time: %v" , err )
219+ } else if ! ts .UTC ().Equal (ts ) {
220+ return errors .New ("buildDate is not a UTC time" )
221+ }
222+
223+ // Validate the format of BuildDate timestamp.
224+ if ts , err := time .Parse (time .RFC3339 , versionInfo .BuildDate ); err != nil {
225+ return fmt .Errorf ("date format in buildDate is not a a valid RFC3339 time: %v" , err )
226+ } else if ! ts .UTC ().Equal (ts ) {
227+ return errors .New ("buildDate is not a UTC time" )
228+ }
229+
216230 return nil
217231
218232}
0 commit comments