mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-11-04 01:34:27 +00:00 
			
		
		
		
	Add git clone test on integration test (#1682)
This commit is contained in:
		
				
					committed by
					
						
						Kim "BKC" Carlbäcker
					
				
			
			
				
	
			
			
			
						parent
						
							eecaba2031
						
					
				
				
					commit
					f70758dec9
				
			
							
								
								
									
										60
									
								
								integrations/git_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								integrations/git_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,60 @@
 | 
				
			|||||||
 | 
					// Copyright 2017 The Gitea Authors. All rights reserved.
 | 
				
			||||||
 | 
					// Use of this source code is governed by a MIT-style
 | 
				
			||||||
 | 
					// license that can be found in the LICENSE file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					package integrations
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"context"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"io/ioutil"
 | 
				
			||||||
 | 
						"net"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"path/filepath"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"code.gitea.io/git"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/Unknwon/com"
 | 
				
			||||||
 | 
						"github.com/stretchr/testify/assert"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func onGiteaWebRun(t *testing.T, callback func(*testing.T, string)) {
 | 
				
			||||||
 | 
						s := http.Server{
 | 
				
			||||||
 | 
							Handler: mac,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						listener, err := net.Listen("tcp", "")
 | 
				
			||||||
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
 | 
				
			||||||
 | 
							s.Shutdown(ctx)
 | 
				
			||||||
 | 
							cancel()
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						go s.Serve(listener)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, port, err := net.SplitHostPort(listener.Addr().String())
 | 
				
			||||||
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						callback(t, fmt.Sprintf("http://localhost:%s/", port))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestClone_ViaHTTP_NoLogin(t *testing.T) {
 | 
				
			||||||
 | 
						prepareTestEnv(t)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						onGiteaWebRun(t, func(t *testing.T, urlPrefix string) {
 | 
				
			||||||
 | 
							dstPath, err := ioutil.TempDir("", "repo1")
 | 
				
			||||||
 | 
							assert.NoError(t, err)
 | 
				
			||||||
 | 
							defer os.RemoveAll(dstPath)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							err = git.Clone(fmt.Sprintf("%suser2/repo1.git", urlPrefix),
 | 
				
			||||||
 | 
								dstPath, git.CloneRepoOptions{})
 | 
				
			||||||
 | 
							assert.NoError(t, err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							assert.True(t, com.IsExist(filepath.Join(dstPath, "README.md")))
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -16,6 +16,7 @@ import (
 | 
				
			|||||||
	"net/url"
 | 
						"net/url"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"path"
 | 
						"path"
 | 
				
			||||||
 | 
						"path/filepath"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -51,7 +52,7 @@ func TestMain(m *testing.M) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	err := models.InitFixtures(
 | 
						err := models.InitFixtures(
 | 
				
			||||||
		helper,
 | 
							helper,
 | 
				
			||||||
		"models/fixtures/",
 | 
							path.Join(filepath.Dir(setting.AppPath), "models/fixtures/"),
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		fmt.Printf("Error initializing test database: %v\n", err)
 | 
							fmt.Printf("Error initializing test database: %v\n", err)
 | 
				
			||||||
@@ -134,7 +135,9 @@ func initIntegrationTest() {
 | 
				
			|||||||
func prepareTestEnv(t testing.TB) {
 | 
					func prepareTestEnv(t testing.TB) {
 | 
				
			||||||
	assert.NoError(t, models.LoadFixtures())
 | 
						assert.NoError(t, models.LoadFixtures())
 | 
				
			||||||
	assert.NoError(t, os.RemoveAll(setting.RepoRootPath))
 | 
						assert.NoError(t, os.RemoveAll(setting.RepoRootPath))
 | 
				
			||||||
	assert.NoError(t, com.CopyDir("integrations/gitea-repositories-meta", setting.RepoRootPath))
 | 
					
 | 
				
			||||||
 | 
						assert.NoError(t, com.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"),
 | 
				
			||||||
 | 
							setting.RepoRootPath))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type TestSession struct {
 | 
					type TestSession struct {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user