@@ -581,6 +581,82 @@ func Test_editRun(t *testing.T) {
581581 },
582582 wantErr : "no file in the gist" ,
583583 },
584+ {
585+ name : "edit gist with truncated file" ,
586+ opts : & EditOptions {
587+ Selector : "1234" ,
588+ },
589+ mockGist : & shared.Gist {
590+ ID : "1234" ,
591+ Files : map [string ]* shared.GistFile {
592+ "large.txt" : {
593+ Filename : "large.txt" ,
594+ Content : "This is truncated content..." ,
595+ Type : "text/plain" ,
596+ Truncated : true ,
597+ RawURL : "https://gist.githubusercontent.com/user/1234/raw/large.txt" ,
598+ },
599+ },
600+ Owner : & shared.GistOwner {Login : "octocat" },
601+ },
602+ httpStubs : func (reg * httpmock.Registry ) {
603+ reg .Register (httpmock .REST ("POST" , "gists/1234" ),
604+ httpmock .StatusStringResponse (201 , "{}" ))
605+ },
606+ wantLastRequestParameters : map [string ]interface {}{
607+ "description" : "" ,
608+ "files" : map [string ]interface {}{
609+ "large.txt" : map [string ]interface {}{
610+ "content" : "new file content" ,
611+ "filename" : "large.txt" ,
612+ },
613+ },
614+ },
615+ },
616+ {
617+ name : "edit specific truncated file in gist with multiple truncated files" ,
618+ opts : & EditOptions {
619+ Selector : "1234" ,
620+ EditFilename : "large.txt" ,
621+ },
622+ mockGist : & shared.Gist {
623+ ID : "1234" ,
624+ Files : map [string ]* shared.GistFile {
625+ "large.txt" : {
626+ Filename : "large.txt" ,
627+ Content : "This is truncated content..." ,
628+ Type : "text/plain" ,
629+ Truncated : true ,
630+ RawURL : "https://gist.githubusercontent.com/user/1234/raw/large.txt" ,
631+ },
632+ "also-truncated.txt" : {
633+ Filename : "also-truncated.txt" ,
634+ Content : "" , // Empty because GitHub truncates subsequent files
635+ Type : "text/plain" ,
636+ Truncated : true , // Subsequent files are also marked as truncated
637+ RawURL : "https://gist.githubusercontent.com/user/1234/raw/also-truncated.txt" ,
638+ },
639+ },
640+ Owner : & shared.GistOwner {Login : "octocat" },
641+ },
642+ httpStubs : func (reg * httpmock.Registry ) {
643+ reg .Register (httpmock .REST ("POST" , "gists/1234" ),
644+ httpmock .StatusStringResponse (201 , "{}" ))
645+ },
646+ wantLastRequestParameters : map [string ]interface {}{
647+ "description" : "" ,
648+ "files" : map [string ]interface {}{
649+ "large.txt" : map [string ]interface {}{
650+ "content" : "new file content" ,
651+ "filename" : "large.txt" ,
652+ },
653+ "also-truncated.txt" : map [string ]interface {}{
654+ "content" : "This is the full content of the also-truncated file retrieved from raw URL" ,
655+ "filename" : "also-truncated.txt" ,
656+ },
657+ },
658+ },
659+ },
584660 }
585661
586662 for _ , tt := range tests {
@@ -603,6 +679,20 @@ func Test_editRun(t *testing.T) {
603679 httpmock .JSONResponse (tt .mockGist ))
604680 reg .Register (httpmock .GraphQL (`query UserCurrent\b` ),
605681 httpmock .StringResponse (`{"data":{"viewer":{"login":"octocat"}}}` ))
682+
683+ // Register raw URL mocks for truncated files
684+ for filename , file := range tt .mockGist .Files {
685+ if file .Truncated && file .RawURL != "" {
686+ // Mock the raw URL response for GetRawGistFile calls
687+ if filename == "large.txt" {
688+ reg .Register (httpmock .REST ("GET" , "user/1234/raw/large.txt" ),
689+ httpmock .StringResponse ("This is the full content of the large file retrieved from raw URL" ))
690+ } else if filename == "also-truncated.txt" {
691+ reg .Register (httpmock .REST ("GET" , "user/1234/raw/also-truncated.txt" ),
692+ httpmock .StringResponse ("This is the full content of the also-truncated file retrieved from raw URL" ))
693+ }
694+ }
695+ }
606696 }
607697 }
608698
0 commit comments