@@ -445,17 +445,17 @@ func TestManager_UpgradeExtension_BinaryExtension(t *testing.T) {
445445 assert .Equal (t , "" , stderr .String ())
446446}
447447
448- func TestManager_UpgradeExtension_PinnedBinaryExtension (t * testing.T ) {
448+ func TestManager_UpgradeExtension_BinaryExtension_Pinned (t * testing.T ) {
449449 tempDir := t .TempDir ()
450450
451451 assert .NoError (t , stubBinaryExtension (
452452 filepath .Join (tempDir , "extensions" , "gh-bin-ext" ),
453453 binManifest {
454- Owner : "owner" ,
455- Name : "gh-bin-ext" ,
456- Host : "example.com" ,
457- Tag : "v1.6.3" ,
458- Pinned : true ,
454+ Owner : "owner" ,
455+ Name : "gh-bin-ext" ,
456+ Host : "example.com" ,
457+ Tag : "v1.6.3" ,
458+ IsPinned : true ,
459459 }))
460460
461461 io , _ , _ , _ := iostreams .Test ()
@@ -470,19 +470,19 @@ func TestManager_UpgradeExtension_PinnedBinaryExtension(t *testing.T) {
470470 assert .Equal (t , err , pinnedExtensionUpgradeError )
471471}
472472
473- func TestManager_UpgradeExtenion_PinnedGitExtension (t * testing.T ) {
473+ func TestManager_UpgradeExtenion_GitExtension_Pinned (t * testing.T ) {
474474 tempDir := t .TempDir ()
475475 extDir := filepath .Join (tempDir , "extensions" , "gh-remote" )
476- assert .NoError (t , stubPinnedExtension (filepath .Join (extDir , "gh-remote" ), "abc1234 " ))
476+ assert .NoError (t , stubPinnedExtension (filepath .Join (extDir , "gh-remote" ), "abcd1234 " ))
477477
478478 io , _ , _ , _ := iostreams .Test ()
479479 m := newTestManager (tempDir , nil , io )
480480 exts , err := m .list (false )
481481 assert .NoError (t , err )
482482 assert .Equal (t , 1 , len (exts ))
483483 ext := exts [0 ]
484+ ext .isPinned = true
484485 ext .latestVersion = "new version"
485- ext .pin = "abc1234"
486486
487487 err = m .upgradeExtension (ext , false )
488488 assert .NotNil (t , err )
@@ -522,6 +522,107 @@ func TestManager_Install_git(t *testing.T) {
522522 assert .Equal (t , "" , stderr .String ())
523523}
524524
525+ func TestManager_Install_git_pinned (t * testing.T ) {
526+ tempDir := t .TempDir ()
527+
528+ reg := httpmock.Registry {}
529+ defer reg .Verify (t )
530+ client := http.Client {Transport : & reg }
531+
532+ io , _ , _ , stderr := iostreams .Test ()
533+ m := newTestManager (tempDir , & client , io )
534+
535+ reg .Register (
536+ httpmock .REST ("GET" , "repos/owner/gh-cool-ext/releases/latest" ),
537+ httpmock .JSONResponse (
538+ release {
539+ Assets : []releaseAsset {
540+ {
541+ Name : "not-a-binary" ,
542+ APIURL : "https://example.com/release/cool" ,
543+ },
544+ },
545+ }))
546+ reg .Register (
547+ httpmock .REST ("GET" , "repos/owner/gh-cool-ext/commits/some-ref" ),
548+ httpmock .StringResponse ("abcd1234" ))
549+ reg .Register (
550+ httpmock .REST ("GET" , "repos/owner/gh-cool-ext/contents/gh-cool-ext" ),
551+ httpmock .StringResponse ("script" ))
552+
553+ _ = os .MkdirAll (filepath .Join (m .installDir (), "gh-cool-ext" ), 0700 )
554+ repo := ghrepo .New ("owner" , "gh-cool-ext" )
555+ err := m .Install (repo , "some-ref" )
556+ assert .NoError (t , err )
557+ assert .Equal (t , "" , stderr .String ())
558+ }
559+
560+ func TestManager_Install_binary_pinned (t * testing.T ) {
561+ repo := ghrepo .NewWithHost ("owner" , "gh-bin-ext" , "example.com" )
562+
563+ reg := httpmock.Registry {}
564+ defer reg .Verify (t )
565+
566+ reg .Register (
567+ httpmock .REST ("GET" , "api/v3/repos/owner/gh-bin-ext/releases/latest" ),
568+ httpmock .JSONResponse (
569+ release {
570+ Assets : []releaseAsset {
571+ {
572+ Name : "gh-bin-ext-windows-amd64.exe" ,
573+ APIURL : "https://example.com/release/cool" ,
574+ },
575+ },
576+ }))
577+ reg .Register (
578+ httpmock .REST ("GET" , "api/v3/repos/owner/gh-bin-ext/releases/tags/v1.6.3-pre" ),
579+ httpmock .JSONResponse (
580+ release {
581+ Tag : "v1.6.3-pre" ,
582+ Assets : []releaseAsset {
583+ {
584+ Name : "gh-bin-ext-windows-amd64.exe" ,
585+ APIURL : "https://example.com/release/cool" ,
586+ },
587+ },
588+ }))
589+ reg .Register (
590+ httpmock .REST ("GET" , "release/cool" ),
591+ httpmock .StringResponse ("FAKE BINARY" ))
592+
593+ io , _ , stdout , stderr := iostreams .Test ()
594+ tempDir := t .TempDir ()
595+
596+ m := newTestManager (tempDir , & http.Client {Transport : & reg }, io )
597+
598+ err := m .Install (repo , "v1.6.3-pre" )
599+ assert .NoError (t , err )
600+
601+ manifest , err := os .ReadFile (filepath .Join (tempDir , "extensions/gh-bin-ext" , manifestName ))
602+ assert .NoError (t , err )
603+
604+ var bm binManifest
605+ err = yaml .Unmarshal (manifest , & bm )
606+ assert .NoError (t , err )
607+
608+ assert .Equal (t , binManifest {
609+ Name : "gh-bin-ext" ,
610+ Owner : "owner" ,
611+ Host : "example.com" ,
612+ Tag : "v1.6.3-pre" ,
613+ IsPinned : true ,
614+ Path : filepath .Join (tempDir , "extensions/gh-bin-ext/gh-bin-ext.exe" ),
615+ }, bm )
616+
617+ fakeBin , err := os .ReadFile (filepath .Join (tempDir , "extensions/gh-bin-ext/gh-bin-ext.exe" ))
618+ assert .NoError (t , err )
619+ assert .Equal (t , "FAKE BINARY" , string (fakeBin ))
620+
621+ assert .Equal (t , "" , stdout .String ())
622+ assert .Equal (t , "" , stderr .String ())
623+
624+ }
625+
525626func TestManager_Install_binary_unsupported (t * testing.T ) {
526627 repo := ghrepo .NewWithHost ("owner" , "gh-bin-ext" , "example.com" )
527628
0 commit comments