summaryrefslogtreecommitdiff
path: root/tests/transport/register.c
blob: 937194c1cfbd8fa58bb9a9403b31f7f48289f8f6 (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "clar_libgit2.h"
#include "git2/sys/transport.h"

static git_transport _transport = GIT_TRANSPORT_INIT;

static int dummy_transport(git_transport **transport, git_remote *owner, void *param)
{
	*transport = &_transport;
	GIT_UNUSED(owner);
	GIT_UNUSED(param);
	return 0;
}

void test_transport_register__custom_transport(void)
{
	git_transport *transport;

	cl_git_pass(git_transport_register("something", dummy_transport, NULL));

	cl_git_pass(git_transport_new(&transport, NULL, "something://somepath"));

	cl_assert(transport == &_transport);

	cl_git_pass(git_transport_unregister("something"));
}

void test_transport_register__custom_transport_error_doubleregister(void)
{
	cl_git_pass(git_transport_register("something", dummy_transport, NULL));

	cl_git_fail_with(git_transport_register("something", dummy_transport, NULL), GIT_EEXISTS);

	cl_git_pass(git_transport_unregister("something"));
}

void test_transport_register__custom_transport_error_remove_non_existing(void)
{
	cl_git_fail_with(git_transport_unregister("something"), GIT_ENOTFOUND);
}

void test_transport_register__custom_transport_ssh(void)
{
	git_transport *transport;

#ifndef GIT_SSH
	cl_git_fail_with(git_transport_new(&transport, NULL, "ssh://somehost:somepath"), -1);
	cl_git_fail_with(git_transport_new(&transport, NULL, "git@somehost:somepath"), -1);
#else
	cl_git_pass(git_transport_new(&transport, NULL, "git@somehost:somepath"));
#endif

	cl_git_pass(git_transport_register("ssh", dummy_transport, NULL));

	cl_git_pass(git_transport_new(&transport, NULL, "git@somehost:somepath"));

	cl_assert(transport == &_transport);

	cl_git_pass(git_transport_unregister("ssh"));

#ifndef GIT_SSH
	cl_git_fail_with(git_transport_new(&transport, NULL, "ssh://somehost:somepath"), -1);
	cl_git_fail_with(git_transport_new(&transport, NULL, "git@somehost:somepath"), -1);
#else
	cl_git_pass(git_transport_new(&transport, NULL, "git@somehost:somepath"));
#endif
}