File: context_test.go

package info (click to toggle)
tea-cli 0.11.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,648 kB
  • sloc: makefile: 116; sh: 17
file content (47 lines) | stat: -rw-r--r-- 1,245 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package context

import (
	"testing"

	"code.gitea.io/tea/modules/config"
)

func Test_MatchLogins(t *testing.T) {
	kases := []struct {
		remoteURL        string
		logins           []config.Login
		matchedLoginName string
		expectedRepoPath string
		hasError         bool
	}{
		{
			remoteURL:        "https://gitea.com/owner/repo.git",
			logins:           []config.Login{{Name: "gitea.com", URL: "https://gitea.com"}},
			matchedLoginName: "gitea.com",
			expectedRepoPath: "owner/repo",
			hasError:         false,
		},
		{
			remoteURL:        "git@gitea.com:owner/repo.git",
			logins:           []config.Login{{Name: "gitea.com", URL: "https://gitea.com"}},
			matchedLoginName: "gitea.com",
			expectedRepoPath: "owner/repo",
			hasError:         false,
		},
	}

	for _, kase := range kases {
		t.Run(kase.remoteURL, func(t *testing.T) {
			_, repoPath, err := MatchLogins(kase.remoteURL, kase.logins)
			if (err != nil) != kase.hasError {
				t.Errorf("Expected error: %v, got: %v", kase.hasError, err)
			}
			if repoPath != kase.expectedRepoPath {
				t.Errorf("Expected repo path: %s, got: %s", kase.expectedRepoPath, repoPath)
			}
		})
	}
}