1
1
import * as assert from 'assert'
2
2
import * as utils from '../support/utils'
3
+ import { randomBytes } from 'crypto'
3
4
import { BundleServerWorld , User } from '../support/world'
4
5
import { Given , When , Then } from '@cucumber/cucumber'
5
6
@@ -9,10 +10,51 @@ import { Given, When, Then } from '@cucumber/cucumber'
9
10
* test steps will live here.
10
11
*/
11
12
13
+ Given ( 'another user pushed {int} commits to {string}' , async function ( this : BundleServerWorld , commitNum : number , branch : string ) {
14
+ const clonedRepo = this . getRepoAtBranch ( User . Another , branch )
15
+
16
+ for ( let i = 0 ; i < commitNum ; i ++ ) {
17
+ utils . assertStatus ( 0 , clonedRepo . runShell ( `echo ${ randomBytes ( 16 ) . toString ( 'hex' ) } >README.md` ) )
18
+ utils . assertStatus ( 0 , clonedRepo . runGit ( "add" , "README.md" ) )
19
+ utils . assertStatus ( 0 , clonedRepo . runGit ( "commit" , "-m" , `test ${ i + 1 } ` ) )
20
+ }
21
+ utils . assertStatus ( 0 , clonedRepo . runGit ( "push" , "origin" , branch ) )
22
+ } )
23
+
24
+ Given ( 'another user removed {int} commits and added {int} commits to {string}' ,
25
+ async function ( this : BundleServerWorld , removeCommits : number , addCommits : number , branch : string ) {
26
+ const clonedRepo = this . getRepoAtBranch ( User . Another , branch )
27
+
28
+ // First, reset
29
+ utils . assertStatus ( 0 , clonedRepo . runGit ( "reset" , "--hard" , `HEAD~${ removeCommits } ` ) )
30
+
31
+ // Then, add new commits
32
+ for ( let i = 0 ; i < addCommits ; i ++ ) {
33
+ utils . assertStatus ( 0 , clonedRepo . runShell ( `echo ${ randomBytes ( 16 ) . toString ( 'hex' ) } >README.md` ) )
34
+ utils . assertStatus ( 0 , clonedRepo . runGit ( "add" , "README.md" ) )
35
+ utils . assertStatus ( 0 , clonedRepo . runGit ( "commit" , "-m" , `test ${ i + 1 } ` ) )
36
+ }
37
+
38
+ // Finally, force push
39
+ utils . assertStatus ( 0 , clonedRepo . runGit ( "push" , "-f" , "origin" , branch ) )
40
+ }
41
+ )
42
+
43
+ Given ( 'I cloned from the remote repo with a bundle URI' , async function ( this : BundleServerWorld ) {
44
+ const user = User . Me
45
+ this . cloneRepositoryFor ( user , this . bundleServer . bundleUri ( ) )
46
+ utils . assertStatus ( 0 , this . getRepo ( user ) . cloneResult )
47
+ } )
48
+
12
49
When ( 'I clone from the remote repo with a bundle URI' , async function ( this : BundleServerWorld ) {
13
50
this . cloneRepositoryFor ( User . Me , this . bundleServer . bundleUri ( ) )
14
51
} )
15
52
53
+ When ( 'I fetch from the remote' , async function ( this : BundleServerWorld ) {
54
+ const clonedRepo = this . getRepo ( User . Me )
55
+ utils . assertStatus ( 0 , clonedRepo . runGit ( "fetch" , "origin" ) )
56
+ } )
57
+
16
58
Then ( 'bundles are downloaded and used' , async function ( this : BundleServerWorld ) {
17
59
const clonedRepo = this . getRepo ( User . Me )
18
60
@@ -40,3 +82,28 @@ Then('bundles are downloaded and used', async function (this: BundleServerWorld)
40
82
} )
41
83
assert . strict ( bundleRefs . length > 0 , "No bundle refs found in the repo" )
42
84
} )
85
+
86
+ Then ( 'I am up-to-date with {string}' , async function ( this : BundleServerWorld , branch : string ) {
87
+ const clonedRepo = this . getRepo ( User . Me )
88
+ const result = clonedRepo . runGit ( "rev-parse" , `refs/remotes/origin/${ branch } ` )
89
+ utils . assertStatus ( 0 , result )
90
+ const actualOid = result . stdout . toString ( ) . trim ( )
91
+ const expectedOid = this . remote ?. getBranchTipOid ( branch )
92
+ assert . strictEqual ( actualOid , expectedOid , `branch '${ branch } ' is not up-to-date` )
93
+ } )
94
+
95
+ Then ( 'my repo\'s bundles {boolean} up-to-date with {string}' ,
96
+ async function ( this : BundleServerWorld , expectedUpToDate : boolean , branch : string ) {
97
+ const clonedRepo = this . getRepo ( User . Me )
98
+ const result = clonedRepo . runGit ( "rev-parse" , `refs/bundles/${ branch } ` )
99
+ utils . assertStatus ( 0 , result )
100
+ const actualOid = result . stdout . toString ( ) . trim ( )
101
+ const expectedOid = this . remote ?. getBranchTipOid ( branch )
102
+
103
+ if ( expectedUpToDate ) {
104
+ assert . strictEqual ( actualOid , expectedOid , `bundle ref for '${ branch } ' is not up-to-date` )
105
+ } else {
106
+ assert . notStrictEqual ( actualOid , expectedOid , `bundle ref for '${ branch } ' is up-to-date, but should not be` )
107
+ }
108
+ }
109
+ )
0 commit comments