code.gitea.io/gitea@v1.22.3/tests/integration/goget_test.go (about)

     1  // Copyright 2021 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package integration
     5  
     6  import (
     7  	"fmt"
     8  	"net/http"
     9  	"testing"
    10  
    11  	"code.gitea.io/gitea/modules/setting"
    12  	"code.gitea.io/gitea/tests"
    13  
    14  	"github.com/stretchr/testify/assert"
    15  )
    16  
    17  func TestGoGet(t *testing.T) {
    18  	defer tests.PrepareTestEnv(t)()
    19  
    20  	req := NewRequest(t, "GET", "/blah/glah/plah?go-get=1")
    21  	resp := MakeRequest(t, req, http.StatusOK)
    22  
    23  	expected := fmt.Sprintf(`<!doctype html>
    24  <html>
    25  	<head>
    26  		<meta name="go-import" content="%[1]s:%[2]s/blah/glah git %[3]sblah/glah.git">
    27  		<meta name="go-source" content="%[1]s:%[2]s/blah/glah _ %[3]sblah/glah/src/branch/master{/dir} %[3]sblah/glah/src/branch/master{/dir}/{file}#L{line}">
    28  	</head>
    29  	<body>
    30  		go get --insecure %[1]s:%[2]s/blah/glah
    31  	</body>
    32  </html>`, setting.Domain, setting.HTTPPort, setting.AppURL)
    33  
    34  	assert.Equal(t, expected, resp.Body.String())
    35  }
    36  
    37  func TestGoGetForSSH(t *testing.T) {
    38  	defer tests.PrepareTestEnv(t)()
    39  
    40  	old := setting.Repository.GoGetCloneURLProtocol
    41  	defer func() {
    42  		setting.Repository.GoGetCloneURLProtocol = old
    43  	}()
    44  	setting.Repository.GoGetCloneURLProtocol = "ssh"
    45  
    46  	req := NewRequest(t, "GET", "/blah/glah/plah?go-get=1")
    47  	resp := MakeRequest(t, req, http.StatusOK)
    48  
    49  	expected := fmt.Sprintf(`<!doctype html>
    50  <html>
    51  	<head>
    52  		<meta name="go-import" content="%[1]s:%[2]s/blah/glah git ssh://git@%[4]s:%[5]d/blah/glah.git">
    53  		<meta name="go-source" content="%[1]s:%[2]s/blah/glah _ %[3]sblah/glah/src/branch/master{/dir} %[3]sblah/glah/src/branch/master{/dir}/{file}#L{line}">
    54  	</head>
    55  	<body>
    56  		go get --insecure %[1]s:%[2]s/blah/glah
    57  	</body>
    58  </html>`, setting.Domain, setting.HTTPPort, setting.AppURL, setting.SSH.Domain, setting.SSH.Port)
    59  
    60  	assert.Equal(t, expected, resp.Body.String())
    61  }