github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/lfs/endpoint_test.go (about)

     1  // Copyright 2023 The GitBundle Inc. All rights reserved.
     2  // Copyright 2017 The Gitea Authors. All rights reserved.
     3  // Use of this source code is governed by a MIT-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package lfs
     7  
     8  import (
     9  	"net/url"
    10  	"testing"
    11  
    12  	"github.com/stretchr/testify/assert"
    13  )
    14  
    15  func str2url(raw string) *url.URL {
    16  	u, _ := url.Parse(raw)
    17  	return u
    18  }
    19  
    20  func TestDetermineEndpoint(t *testing.T) {
    21  	// Test cases
    22  	cases := []struct {
    23  		cloneurl string
    24  		lfsurl   string
    25  		expected *url.URL
    26  	}{
    27  		// case 0
    28  		{
    29  			cloneurl: "",
    30  			lfsurl:   "",
    31  			expected: nil,
    32  		},
    33  		// case 1
    34  		{
    35  			cloneurl: "https://git.com/repo",
    36  			lfsurl:   "",
    37  			expected: str2url("https://git.com/repo.git/info/lfs"),
    38  		},
    39  		// case 2
    40  		{
    41  			cloneurl: "https://git.com/repo.git",
    42  			lfsurl:   "",
    43  			expected: str2url("https://git.com/repo.git/info/lfs"),
    44  		},
    45  		// case 3
    46  		{
    47  			cloneurl: "",
    48  			lfsurl:   "https://gitlfs.com/repo",
    49  			expected: str2url("https://gitlfs.com/repo"),
    50  		},
    51  		// case 4
    52  		{
    53  			cloneurl: "https://git.com/repo.git",
    54  			lfsurl:   "https://gitlfs.com/repo",
    55  			expected: str2url("https://gitlfs.com/repo"),
    56  		},
    57  		// case 5
    58  		{
    59  			cloneurl: "git://git.com/repo.git",
    60  			lfsurl:   "",
    61  			expected: str2url("https://git.com/repo.git/info/lfs"),
    62  		},
    63  		// case 6
    64  		{
    65  			cloneurl: "",
    66  			lfsurl:   "git://gitlfs.com/repo",
    67  			expected: str2url("https://gitlfs.com/repo"),
    68  		},
    69  	}
    70  
    71  	for n, c := range cases {
    72  		ep := DetermineEndpoint(c.cloneurl, c.lfsurl)
    73  
    74  		assert.Equal(t, c.expected, ep, "case %d: error should match", n)
    75  	}
    76  }