Skip to content

Commit

Permalink
Add detect git tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yuqu committed Apr 5, 2021
1 parent c8fd553 commit 6b163fc
Show file tree
Hide file tree
Showing 15 changed files with 342 additions and 0 deletions.
258 changes: 258 additions & 0 deletions test/service/git/detect-git.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
import { detectGit } from "../../../src/service/git";
import { BitbucketConfig } from "../../../src/commands/connect/interfaces/config";

describe("DetectGit", () => {
it("current repository", async () => {
const detected = await detectGit();

expect(detected).toBeDefined();
expect(detected?.config).toBeDefined();
expect(detected?.config.repository).toBe("zeplin/cli");
expect(detected?.config.path).toBeUndefined();
expect(detected?.config.branch).toBeUndefined();
expect(detected?.config.url).toBeUndefined();
expect(detected?.type).toBe("github");
});

describe("github", () => {
it("clone over ssh", async () => {
const detected = await detectGit({
path: `${__dirname}/repos/github-ssh.config`
});

expect(detected).toBeDefined();
expect(detected?.config).toBeDefined();
expect(detected?.config.repository).toBe("owner/example");
expect(detected?.config.path).toBeUndefined();
expect(detected?.config.branch).toBeUndefined();
expect(detected?.config.url).toBeUndefined();
expect(detected?.type).toBe("github");
});

it("clone over http", async () => {
const detected = await detectGit({
path: `${__dirname}/repos/github-http.config`
});

expect(detected).toBeDefined();
expect(detected?.config).toBeDefined();
expect(detected?.config.repository).toBe("owner/example");
expect(detected?.config.path).toBeUndefined();
expect(detected?.config.branch).toBeUndefined();
expect(detected?.config.url).toBeUndefined();
expect(detected?.type).toBe("github");
});

describe("selfhosted", () => {
it("clone over http", async () => {
const detected = await detectGit({
path: `${__dirname}/repos/github-selfhosted-http.config`
});

expect(detected).toBeDefined();
expect(detected?.config).toBeDefined();
expect(detected?.config.repository).toBe("owner/example");
expect(detected?.config.path).toBeUndefined();
expect(detected?.config.branch).toBeUndefined();
expect(detected?.config.url).toBe("https://github.example.com");
expect(detected?.type).toBe("github");
});

it("clone over ssh", async () => {
const detected = await detectGit({
path: `${__dirname}/repos/github-selfhosted-ssh.config`
});

expect(detected).toBeDefined();
expect(detected?.config).toBeDefined();
expect(detected?.config.repository).toBe("owner/example");
expect(detected?.config.path).toBeUndefined();
expect(detected?.config.branch).toBeUndefined();
expect(detected?.config.url).toBe("https://github.example.com");
expect(detected?.type).toBe("github");
});
});
});

describe("gitlab", () => {
it("clone over ssh", async () => {
const detected = await detectGit({
path: `${__dirname}/repos/gitlab-ssh.config`
});

expect(detected).toBeDefined();
expect(detected?.config).toBeDefined();
expect(detected?.config.repository).toBe("owner/example");
expect(detected?.config.path).toBeUndefined();
expect(detected?.config.branch).toBeUndefined();
expect(detected?.config.url).toBeUndefined();
expect(detected?.type).toBe("gitlab");
});

it("clone over http", async () => {
const detected = await detectGit({
path: `${__dirname}/repos/gitlab-http.config`
});

expect(detected).toBeDefined();
expect(detected?.config).toBeDefined();
expect(detected?.config.repository).toBe("owner/example");
expect(detected?.config.path).toBeUndefined();
expect(detected?.config.branch).toBeUndefined();
expect(detected?.config.url).toBeUndefined();
expect(detected?.type).toBe("gitlab");
});

describe("selfhosted", () => {
it("clone over http", async () => {
const detected = await detectGit({
path: `${__dirname}/repos/gitlab-selfhosted-http.config`
});

expect(detected).toBeDefined();
expect(detected?.config).toBeDefined();
expect(detected?.config.repository).toBe("owner/example");
expect(detected?.config.path).toBeUndefined();
expect(detected?.config.branch).toBeUndefined();
expect(detected?.config.url).toBe("https://gitlab.example.com");
expect(detected?.type).toBe("gitlab");
});

it("clone over ssh", async () => {
const detected = await detectGit({
path: `${__dirname}/repos/gitlab-selfhosted-ssh.config`
});

expect(detected).toBeDefined();
expect(detected?.config).toBeDefined();
expect(detected?.config.repository).toBe("owner/example");
expect(detected?.config.path).toBeUndefined();
expect(detected?.config.branch).toBeUndefined();
expect(detected?.config.url).toBe("https://gitlab.example.com");
expect(detected?.type).toBe("gitlab");
});
});
});

describe("bitbucket-cloud", () => {
it("clone over ssh", async () => {
const detected = await detectGit({
path: `${__dirname}/repos/bitbucket-cloud-ssh.config`
});

expect(detected).toBeDefined();
expect(detected?.config).toBeDefined();
expect(detected?.config.repository).toBe("owner/example");
expect(detected?.config.path).toBeUndefined();
expect(detected?.config.branch).toBeUndefined();
expect(detected?.config.url).toBeUndefined();
expect(detected?.type).toBe("bitbucket");
});

it("clone over http", async () => {
const detected = await detectGit({
path: `${__dirname}/repos/bitbucket-cloud-http.config`
});

expect(detected).toBeDefined();
expect(detected?.config).toBeDefined();
expect(detected?.config.repository).toBe("owner/example");
expect(detected?.config.path).toBeUndefined();
expect(detected?.config.branch).toBeUndefined();
expect(detected?.config.url).toBeUndefined();
expect(detected?.type).toBe("bitbucket");
});
});

describe("bitbucket-server", () => {
it("clone over http", async () => {
const detected = await detectGit({
path: `${__dirname}/repos/bitbucket-server-project-http.config`
});

expect(detected).toBeDefined();
expect(detected?.config).toBeDefined();
expect(detected?.type).toBe("bitbucket");

const bitbucketConfig = detected?.config as BitbucketConfig;
expect(bitbucketConfig.repository).toBe("example");
expect(bitbucketConfig.path).toBeUndefined();
expect(bitbucketConfig.branch).toBe("master");
expect(bitbucketConfig.url).toBe("https://bitbucket.example.com");
expect(bitbucketConfig.project).toBe("owner");
expect(bitbucketConfig.user).toBeUndefined();
});

it("personal clone over http", async () => {
const detected = await detectGit({
path: `${__dirname}/repos/bitbucket-server-user-http.config`
});

expect(detected).toBeDefined();
expect(detected?.config).toBeDefined();
expect(detected?.type).toBe("bitbucket");

const bitbucketConfig = detected?.config as BitbucketConfig;
expect(bitbucketConfig.repository).toBe("example");
expect(bitbucketConfig.path).toBeUndefined();
expect(bitbucketConfig.branch).toBe("master");
expect(bitbucketConfig.url).toBe("https://bitbucket.example.com");
expect(bitbucketConfig.project).toBeUndefined();
expect(bitbucketConfig.user).toBe("~owner");
});

it("clone over ssh", async () => {
const detected = await detectGit({
path: `${__dirname}/repos/bitbucket-server-project-ssh.config`
});

expect(detected).toBeDefined();
expect(detected?.config).toBeDefined();
expect(detected?.type).toBe("bitbucket");

const bitbucketConfig = detected?.config as BitbucketConfig;
expect(bitbucketConfig.repository).toBe("example");
expect(bitbucketConfig.path).toBeUndefined();
expect(bitbucketConfig.branch).toBe("master");
expect(bitbucketConfig.url).toBe("https://bitbucket.example.com");
expect(bitbucketConfig.project).toBe("owner");
expect(bitbucketConfig.user).toBeUndefined();
});

it("personal clone over http", async () => {
const detected = await detectGit({
path: `${__dirname}/repos/bitbucket-server-user-ssh.config`
});

expect(detected).toBeDefined();
expect(detected?.config).toBeDefined();
expect(detected?.type).toBe("bitbucket");

const bitbucketConfig = detected?.config as BitbucketConfig;
expect(bitbucketConfig.repository).toBe("example");
expect(bitbucketConfig.path).toBeUndefined();
expect(bitbucketConfig.branch).toBe("master");
expect(bitbucketConfig.url).toBe("https://bitbucket.example.com");
expect(bitbucketConfig.project).toBeUndefined();
expect(bitbucketConfig.user).toBe("~owner");
});
});

// it("bitbucket-server project repository", async () => {
// const detected = await detectGit({
// path: `${__dirname}/repos/bitbucket-server-project.config`
// });

// expect(detected).toBeDefined();
// expect(detected?.config).toBeDefined();
// expect(detected?.type).toBe("bitbucket");

// const bitbucketConfig = detected.config as BitbucketConfig;
// expect(bitbucketConfig.repository).toBe("owner/example");
// expect(bitbucketConfig.path).toBeUndefined();
// expect(bitbucketConfig.branch).toBeUndefined();
// expect(bitbucketConfig.url).toBeUndefined();
// expect(bitbucketConfig.project).toBeUndefined();
// expect(bitbucketConfig.user).toBeUndefined();
// });
});
6 changes: 6 additions & 0 deletions test/service/git/repos/bitbucket-cloud-http.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[remote "origin"]
url = [email protected]:owner/example.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
6 changes: 6 additions & 0 deletions test/service/git/repos/bitbucket-cloud-ssh.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[remote "origin"]
url = https://[email protected]/owner/example.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
6 changes: 6 additions & 0 deletions test/service/git/repos/bitbucket-server-project-http.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[remote "origin"]
url = https://[email protected]/scm/owner/example.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
6 changes: 6 additions & 0 deletions test/service/git/repos/bitbucket-server-project-ssh.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[remote "origin"]
url = ssh://[email protected]/owner/example.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
6 changes: 6 additions & 0 deletions test/service/git/repos/bitbucket-server-user-http.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[remote "origin"]
url = https://[email protected]/scm/~owner/example.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
6 changes: 6 additions & 0 deletions test/service/git/repos/bitbucket-server-user-ssh.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[remote "origin"]
url = ssh://[email protected]/~owner/example.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
6 changes: 6 additions & 0 deletions test/service/git/repos/github-http.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[remote "origin"]
url = https://[email protected]/owner/example
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
6 changes: 6 additions & 0 deletions test/service/git/repos/github-selfhosted-http.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[remote "origin"]
url = https://github.example.com/owner/example
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
6 changes: 6 additions & 0 deletions test/service/git/repos/github-selfhosted-ssh.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[remote "origin"]
url = [email protected]:owner/example
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
6 changes: 6 additions & 0 deletions test/service/git/repos/github-ssh.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[remote "origin"]
url = [email protected]:owner/example.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
6 changes: 6 additions & 0 deletions test/service/git/repos/gitlab-http.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[remote "origin"]
url = https://gitlab.com/owner/example
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
6 changes: 6 additions & 0 deletions test/service/git/repos/gitlab-selfhosted-http.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[remote "origin"]
url = https://gitlab.example.com/owner/example
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
6 changes: 6 additions & 0 deletions test/service/git/repos/gitlab-selfhosted-ssh.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[remote "origin"]
url = [email protected]:owner/example
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
6 changes: 6 additions & 0 deletions test/service/git/repos/gitlab-ssh.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[remote "origin"]
url = [email protected]:owner/example.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master

0 comments on commit 6b163fc

Please sign in to comment.