gitech

Форк
0
/
endpoint_test.go 
74 строки · 1.4 Кб
1
// Copyright 2021 The Gitea Authors. All rights reserved.
2
// SPDX-License-Identifier: MIT
3

4
package lfs
5

6
import (
7
	"net/url"
8
	"testing"
9

10
	"github.com/stretchr/testify/assert"
11
)
12

13
func str2url(raw string) *url.URL {
14
	u, _ := url.Parse(raw)
15
	return u
16
}
17

18
func TestDetermineEndpoint(t *testing.T) {
19
	// Test cases
20
	cases := []struct {
21
		cloneurl string
22
		lfsurl   string
23
		expected *url.URL
24
	}{
25
		// case 0
26
		{
27
			cloneurl: "",
28
			lfsurl:   "",
29
			expected: nil,
30
		},
31
		// case 1
32
		{
33
			cloneurl: "https://git.com/repo",
34
			lfsurl:   "",
35
			expected: str2url("https://git.com/repo.git/info/lfs"),
36
		},
37
		// case 2
38
		{
39
			cloneurl: "https://git.com/repo.git",
40
			lfsurl:   "",
41
			expected: str2url("https://git.com/repo.git/info/lfs"),
42
		},
43
		// case 3
44
		{
45
			cloneurl: "",
46
			lfsurl:   "https://gitlfs.com/repo",
47
			expected: str2url("https://gitlfs.com/repo"),
48
		},
49
		// case 4
50
		{
51
			cloneurl: "https://git.com/repo.git",
52
			lfsurl:   "https://gitlfs.com/repo",
53
			expected: str2url("https://gitlfs.com/repo"),
54
		},
55
		// case 5
56
		{
57
			cloneurl: "git://git.com/repo.git",
58
			lfsurl:   "",
59
			expected: str2url("https://git.com/repo.git/info/lfs"),
60
		},
61
		// case 6
62
		{
63
			cloneurl: "",
64
			lfsurl:   "git://gitlfs.com/repo",
65
			expected: str2url("https://gitlfs.com/repo"),
66
		},
67
	}
68

69
	for n, c := range cases {
70
		ep := DetermineEndpoint(c.cloneurl, c.lfsurl)
71

72
		assert.Equal(t, c.expected, ep, "case %d: error should match", n)
73
	}
74
}
75

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.