@@ -21,8 +21,11 @@ import (
21
21
"encoding/json"
22
22
"fmt"
23
23
"strings"
24
+ "testing"
24
25
"time"
25
26
27
+ "github.com/go-git/go-git/v5"
28
+ "github.com/go-git/go-git/v5/plumbing"
26
29
"github.com/pkg/errors"
27
30
28
31
"github.com/dgraph-io/dgo/v210"
@@ -43,6 +46,7 @@ type Cluster interface {
43
46
AdminPost (body []byte ) ([]byte , error )
44
47
AlphasHealth () ([]string , error )
45
48
AssignUids (num uint64 ) error
49
+ GetVersion () string
46
50
}
47
51
48
52
func SetupSchema (c Cluster , dbSchema string ) error {
@@ -239,3 +243,52 @@ loop:
239
243
return nil
240
244
}
241
245
}
246
+
247
+ func ShouldSkipTest (t * testing.T , minVersion , clusterVersion string ) error {
248
+ if clusterVersion == localVersion {
249
+ return nil
250
+ }
251
+
252
+ isParentCommit , err := isParent (minVersion , clusterVersion )
253
+ if err != nil {
254
+ t .Fatal (err )
255
+ }
256
+ if isParentCommit {
257
+ t .Skipf ("test is valid for commits greater than [%v]" , minVersion )
258
+ }
259
+
260
+ return nil
261
+ }
262
+
263
+ // isParent checks whether ancestor is the ancestor commit of the given descendant commit.
264
+ func isParent (ancestor , descendant string ) (bool , error ) {
265
+ repo , err := git .PlainOpen (repoDir )
266
+ if err != nil {
267
+ return false , errors .Wrap (err , "error opening git repo" )
268
+ }
269
+
270
+ ancestorHash , err := repo .ResolveRevision (plumbing .Revision (ancestor ))
271
+ if err != nil {
272
+ return false , errors .Wrapf (err , "error while getting reference of [%v]" , ancestor )
273
+ }
274
+ ancestorCommit , err := repo .CommitObject (* ancestorHash )
275
+ if err != nil {
276
+ return false , errors .Wrapf (err , "error finding commit object [%v]" , ancestor )
277
+ }
278
+
279
+ descendantHash , err := repo .ResolveRevision (plumbing .Revision (descendant ))
280
+ if err != nil {
281
+ return false , err
282
+ }
283
+ descendantCommit , err := repo .CommitObject (* descendantHash )
284
+ if err != nil {
285
+ return false , errors .Wrapf (err , "error finding commit object [%v]" , descendant )
286
+ }
287
+
288
+ isParentCommit , err := descendantCommit .IsAncestor (ancestorCommit )
289
+ if err != nil {
290
+ return false , errors .Wrapf (err , "unable to compare commit [%v] to commit [%v]" ,
291
+ descendant , ancestor )
292
+ }
293
+ return isParentCommit , nil
294
+ }
0 commit comments