aboutsummaryrefslogtreecommitdiff
path: root/internal/gitutil/submodule_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/gitutil/submodule_test.go')
-rw-r--r--internal/gitutil/submodule_test.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/internal/gitutil/submodule_test.go b/internal/gitutil/submodule_test.go
new file mode 100644
index 00000000..2bfe5706
--- /dev/null
+++ b/internal/gitutil/submodule_test.go
@@ -0,0 +1,58 @@
+// 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 gitutil
+
+import (
+ "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://user@github.com: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: "git@github.com: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))
+ })
+ }
+}