| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 | // Copyright 2020 The Gogs 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 gitutilimport (	"testing"	"github.com/gogs/git-module"	"github.com/stretchr/testify/assert")func TestInferSubmoduleURL(t *testing.T) {	tests := []struct {		name      string		submodule *git.Submodule		expURL    string	}{		{			name: "HTTPS URL",			submodule: &git.Submodule{				URL:    "https://github.com/gogs/docs-api.git",				Commit: "6b08f76a5313fa3d26859515b30aa17a5faa2807",			},			expURL: "https://github.com/gogs/docs-api/commit/6b08f76a5313fa3d26859515b30aa17a5faa2807",		},		{			name: "SSH URL with port",			submodule: &git.Submodule{				URL:    "ssh://[email protected]:22/gogs/docs-api.git",				Commit: "6b08f76a5313fa3d26859515b30aa17a5faa2807",			},			expURL: "http://github.com:22/gogs/docs-api/commit/6b08f76a5313fa3d26859515b30aa17a5faa2807",		},		{			name: "SSH URL in SCP syntax",			submodule: &git.Submodule{				URL:    "[email protected]:gogs/docs-api.git",				Commit: "6b08f76a5313fa3d26859515b30aa17a5faa2807",			},			expURL: "http://github.com/gogs/docs-api/commit/6b08f76a5313fa3d26859515b30aa17a5faa2807",		},		{			name: "bad URL",			submodule: &git.Submodule{				URL:    "ftp://example.com",				Commit: "6b08f76a5313fa3d26859515b30aa17a5faa2807",			},			expURL: "ftp://example.com",		},	}	for _, test := range tests {		t.Run(test.name, func(t *testing.T) {			assert.Equal(t, test.expURL, InferSubmoduleURL(test.submodule))		})	}}
 |