@@ -5,6 +5,8 @@ package integration
55
66import (
77 "net/url"
8+ "os"
9+ "path/filepath"
810 "slices"
911 "strings"
1012 "sync"
@@ -23,7 +25,8 @@ import (
2325
2426func TestGitLFSSSH (t * testing.T ) {
2527 onGiteaRun (t , func (t * testing.T , u * url.URL ) {
26- dstPath := t .TempDir ()
28+ localRepoForUpload := filepath .Join (t .TempDir (), "test-upload" )
29+ localRepoForDownload := filepath .Join (t .TempDir (), "test-download" )
2730 apiTestContext := NewAPITestContext (t , "user2" , "repo1" , auth_model .AccessTokenScopeWriteRepository , auth_model .AccessTokenScopeWriteUser )
2831
2932 var mu sync.Mutex
@@ -37,17 +40,24 @@ func TestGitLFSSSH(t *testing.T) {
3740 withKeyFile (t , "my-testing-key" , func (keyFile string ) {
3841 t .Run ("CreateUserKey" , doAPICreateUserKey (apiTestContext , "test-key" , keyFile ))
3942 cloneURL := createSSHUrl (apiTestContext .GitPath (), u )
40- t .Run ("Clone " , doGitClone (dstPath , cloneURL ))
43+ t .Run ("CloneOrigin " , doGitClone (localRepoForUpload , cloneURL ))
4144
4245 cfg , err := setting .CfgProvider .PrepareSaving ()
4346 require .NoError (t , err )
4447 cfg .Section ("server" ).Key ("LFS_ALLOW_PURE_SSH" ).SetValue ("true" )
4548 setting .LFS .AllowPureSSH = true
4649 require .NoError (t , cfg .Save ())
4750
48- _ , _ , cmdErr := gitcmd .NewCommand ("config" , "lfs.sshtransfer" , "always" ).RunStdString (t .Context (), & gitcmd.RunOpts {Dir : dstPath })
51+ _ , _ , cmdErr := gitcmd .NewCommand ("config" , "lfs.sshtransfer" , "always" ).
52+ WithDir (localRepoForUpload ).
53+ RunStdString (t .Context ())
4954 assert .NoError (t , cmdErr )
50- lfsCommitAndPushTest (t , dstPath , 10 )
55+ pushedFiles := lfsCommitAndPushTest (t , localRepoForUpload , 10 )
56+
57+ t .Run ("CloneLFS" , doGitClone (localRepoForDownload , cloneURL ))
58+ content , err := os .ReadFile (filepath .Join (localRepoForDownload , pushedFiles [0 ]))
59+ assert .NoError (t , err )
60+ assert .Len (t , content , 10 )
5161 })
5262
5363 countBatch := slices .ContainsFunc (routerCalls , func (s string ) bool {
@@ -56,12 +66,16 @@ func TestGitLFSSSH(t *testing.T) {
5666 countUpload := slices .ContainsFunc (routerCalls , func (s string ) bool {
5767 return strings .Contains (s , "PUT /api/internal/repo/user2/repo1.git/info/lfs/objects/" )
5868 })
69+ countDownload := slices .ContainsFunc (routerCalls , func (s string ) bool {
70+ return strings .Contains (s , "GET /api/internal/repo/user2/repo1.git/info/lfs/objects/" )
71+ })
5972 nonAPIRequests := slices .ContainsFunc (routerCalls , func (s string ) bool {
6073 fields := strings .Fields (s )
6174 return ! strings .HasPrefix (fields [1 ], "/api/" )
6275 })
6376 assert .NotZero (t , countBatch )
6477 assert .NotZero (t , countUpload )
78+ assert .NotZero (t , countDownload )
6579 assert .Zero (t , nonAPIRequests )
6680 })
6781}
0 commit comments