Skip to content

Commit

Permalink
[server] Add SCM repo search integration tests (#20413)
Browse files Browse the repository at this point in the history
* [server] Add SCM repo search integration tests

* bbs prefix search test
  • Loading branch information
filiptronicek authored Dec 3, 2024
1 parent c4d64c0 commit 26d2b1c
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,30 @@ class TestBitbucketServerRepositoryProvider {
name: "browser-extension-test",
});
}

@test async test_searchRepos_ok() {
const result = await this.service.searchRepos(this.user, "2k-repos-1076", 100);
expect(result.length).to.be.eq(1);
}

@test async test_searchRepos_shortSearch() {
const resultA = await this.service.searchRepos(this.user, "2", 100);
expect(resultA).to.not.be.empty;

const resultB = await this.service.searchRepos(this.user, "2k", 100);
expect(resultB).to.not.be.empty;
}

// bitbucket searches for repo and project names, not for the full path
@test async test_searchRepos_pathSubstring() {
const result = await this.service.searchRepos(this.user, "/2k-repos-1076", 100);
expect(result).to.be.empty;
}

@test async test_searchRepos_nameSubstring() {
const result = await this.service.searchRepos(this.user, "repos-1076", 100);
expect(result).to.be.empty;
}
}

module.exports = new TestBitbucketServerRepositoryProvider();
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,30 @@ class TestBitbucketRepositoryProvider {
const result = await this.repoProvider.hasReadAccess(this.user, "foobar", "private-repo");
expect(result).to.be.false;
}

// In contrast to Bitbucket Server, bitbucket.org supports matching against a substring, not just a prefix.
@test public async testSearchRepos_matchesSubstring() {
const result = await this.repoProvider.searchRepos(this.user, "amp", 100);
expect(result).to.deep.include({
url: "https://bitbucket.org/gitpod-integration-tests/exampul-repo",
name: "exampul-repo",
});
}

// Bitbucket supports searching for repos with arbitrary length search strings.
@test public async testSearchRepos_shortSearchString() {
const resultA = await this.repoProvider.searchRepos(this.user, "e", 100);
expect(resultA.length).to.be.gt(0);

const resultB = await this.repoProvider.searchRepos(this.user, "ex", 100);
expect(resultB.length).to.be.gt(0);
}

// Bitbucket only searches for repositories by their name, not by their full path.
@test public async testSearchRepos_doesNotMatchPath() {
const result = await this.repoProvider.searchRepos(this.user, "gitpod-integration-tests/exampul-repo", 100);
expect(result).to.be.empty;
}
}

module.exports = new TestBitbucketRepositoryProvider();
24 changes: 23 additions & 1 deletion components/server/src/github/github-repository-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class TestGithubContextRepositoryProvider {
description: "",
icon: "",
host: "github.com",
oauth: "not-used" as any,
oauth: {
callBackUrl: "https://gitpod.example.com/auth/github/callback",
} as any,
};

@test public async testFetchCommitHistory() {
Expand All @@ -79,6 +81,26 @@ class TestGithubContextRepositoryProvider {
]);
}

@test public async testSearchRepos_onlyMatchesByPrefix() {
const resultA = await this.provider.searchRepos(this.user, "xample", 100);
expect(resultA.length).to.be.eq(0);

const resultB = await this.provider.searchRepos(this.user, "e", 100);
expect(resultB.length).to.be.eq(1);
}

@test public async testSearchRepos_matchesAgainstWholePath() {
const resultMatchesSuffix = await this.provider.searchRepos(this.user, "-integration-test/example", 100);
expect(resultMatchesSuffix.length).to.be.eq(1);

const resultDoesNotMatchSubstring = await this.provider.searchRepos(
this.user,
"gitpod-integration-test/exampl",
100,
);
expect(resultDoesNotMatchSubstring.length).to.be.eq(0);
}

@test public async testGetUserRepos() {
const result = await this.provider.getUserRepos(this.user);
expect(result).to.deep.include({ url: "https://github.com/gitpod-integration-test/example", name: "example" });
Expand Down
25 changes: 25 additions & 0 deletions components/server/src/gitlab/gitlab-repository-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,31 @@ class TestGitlabRepositoryProvider {
"f2d9790f2752a794517b949c65a773eb864844cd",
]);
}

@test public async testSearchRepos_matchesSubstring() {
const result = await this.repositoryProvider.searchRepos(this.user, "est", 100);
expect(result.length).to.be.eq(1);
}

// The minimum search string length is 3 characters (unless there is an exact match).
@test public async testSearchRepos_shortSearchString_looseMatch() {
const resultA = await this.repositoryProvider.searchRepos(this.user, "t", 100);
expect(resultA.length).to.be.eq(0);

const resultB = await this.repositoryProvider.searchRepos(this.user, "te", 100);
expect(resultB.length).to.be.eq(0);
}

@test public async testSearchRepos_shortSearchString_exactMatch() {
const result = await this.repositoryProvider.searchRepos(this.user, "g", 100);
expect(result.length).to.be.eq(1);
}

// GitLab API does not support searching for repositories by their full path, only by their name.
@test public async testSearchRepos_noMatchAgainstWholePath() {
const result = await this.repositoryProvider.searchRepos(this.user, "gitpod-integration-tests/test", 100);
expect(result.length).to.be.eq(0);
}
}

module.exports = new TestGitlabRepositoryProvider();

0 comments on commit 26d2b1c

Please sign in to comment.