@@ -15,7 +15,7 @@ const wrapCallback = (func: { (callback: any): void }) => {
15
15
16
16
describe ( 'git' , ( ) => {
17
17
test ( 'create, push to, and clone a repo' , async ( ) => {
18
- expect . assertions ( 11 ) ;
18
+ expect . assertions ( 12 ) ;
19
19
20
20
let lastCommit : string ;
21
21
@@ -29,9 +29,11 @@ describe('git', () => {
29
29
fs . mkdirSync ( srcDir , '0700' ) ;
30
30
fs . mkdirSync ( dstDir , '0700' ) ;
31
31
32
- const repos = new Git < number > ( repoDir , {
32
+ const repos = new Git < string > ( repoDir , {
33
33
autoCreate : true ,
34
- authenticate : ( ) => 42 ,
34
+ authenticate : ( opts ) => {
35
+ return 'my request context' ;
36
+ } ,
35
37
} ) ;
36
38
const port = Math . floor ( Math . random ( ) * ( ( 1 << 16 ) - 1e4 ) ) + 1e4 ;
37
39
const server = http
@@ -43,7 +45,7 @@ describe('git', () => {
43
45
process . chdir ( srcDir ) ;
44
46
45
47
repos . on ( 'push' , ( push ) => {
46
- expect ( push . context ) . toBe ( 42 ) ;
48
+ expect ( push . context ) . toBe ( 'my request context' ) ;
47
49
48
50
expect ( push . repo ) . toBe ( 'xyz/doom' ) ;
49
51
expect ( push . commit ) . toBe ( lastCommit ) ;
@@ -658,9 +660,9 @@ describe('git', () => {
658
660
659
661
const repos = new Git ( repoDir , {
660
662
autoCreate : true ,
661
- authenticate : async ( { type, repo, user } ) => {
663
+ authenticate : async ( { type, repo, getUser } ) => {
662
664
if ( type === 'fetch' && repo === 'doom' ) {
663
- const [ username , password ] = await user ( ) ;
665
+ const [ username , password ] = await getUser ( ) ;
664
666
if ( username == 'root' && password == 'root' ) {
665
667
return ;
666
668
} else {
@@ -729,15 +731,15 @@ describe('git', () => {
729
731
730
732
const repos = new Git < Context > ( repoDir , {
731
733
autoCreate : true ,
732
- authenticate : async ( { type, repo, user , headers } ) => {
734
+ authenticate : async ( { type, repo, getUser , headers } ) => {
733
735
if ( type === 'fetch' && repo === 'doom' ) {
734
736
expect ( headers [ 'host' ] ) . toBeTruthy ( ) ;
735
737
expect ( headers [ 'user-agent' ] ) . toBeTruthy ( ) ;
736
738
expect ( headers [ 'accept' ] ) . toBeTruthy ( ) ;
737
739
expect ( headers [ 'pragma' ] ) . toBeTruthy ( ) ;
738
740
expect ( headers [ 'accept-encoding' ] ) . toBeTruthy ( ) ;
739
741
740
- const [ username , password ] = await user ( ) ;
742
+ const [ username , password ] = await getUser ( ) ;
741
743
if ( username == 'root' && password == 'root' ) {
742
744
return {
743
745
username : username ,
@@ -802,20 +804,14 @@ describe('git', () => {
802
804
803
805
const repos = new Git ( repoDir , {
804
806
autoCreate : true ,
805
- authenticate : ( { type, repo, user } ) => {
806
- return new Promise ( function ( resolve , reject ) {
807
- if ( type === 'fetch' && repo === 'doom' ) {
808
- user ( ( username , password ) => {
809
- if ( username == 'root' && password == 'root' ) {
810
- return resolve ( void 0 ) ;
811
- } else {
812
- return reject ( 'that is not the correct password' ) ;
813
- }
814
- } ) ;
815
- } else {
816
- return reject ( 'that is not the correct password' ) ;
807
+ authenticate : async ( { type, repo, getUser } ) => {
808
+ if ( type === 'fetch' && repo === 'doom' ) {
809
+ const [ username , password ] = await getUser ( ) ;
810
+ if ( username == 'root' && password == 'root' ) {
811
+ return ;
817
812
}
818
- } ) ;
813
+ }
814
+ throw new Error ( 'that is not the correct password' ) ;
819
815
} ,
820
816
} ) ;
821
817
const port = Math . floor ( Math . random ( ) * ( ( 1 << 16 ) - 1e4 ) ) + 1e4 ;
0 commit comments