Skip to content

Commit 26d2b1c

Browse files
[server] Add SCM repo search integration tests (#20413)
* [server] Add SCM repo search integration tests * bbs prefix search test
1 parent c4d64c0 commit 26d2b1c

File tree

4 files changed

+96
-1
lines changed

4 files changed

+96
-1
lines changed

components/server/src/bitbucket-server/bitbucket-server-repository-provider.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,30 @@ class TestBitbucketServerRepositoryProvider {
153153
name: "browser-extension-test",
154154
});
155155
}
156+
157+
@test async test_searchRepos_ok() {
158+
const result = await this.service.searchRepos(this.user, "2k-repos-1076", 100);
159+
expect(result.length).to.be.eq(1);
160+
}
161+
162+
@test async test_searchRepos_shortSearch() {
163+
const resultA = await this.service.searchRepos(this.user, "2", 100);
164+
expect(resultA).to.not.be.empty;
165+
166+
const resultB = await this.service.searchRepos(this.user, "2k", 100);
167+
expect(resultB).to.not.be.empty;
168+
}
169+
170+
// bitbucket searches for repo and project names, not for the full path
171+
@test async test_searchRepos_pathSubstring() {
172+
const result = await this.service.searchRepos(this.user, "/2k-repos-1076", 100);
173+
expect(result).to.be.empty;
174+
}
175+
176+
@test async test_searchRepos_nameSubstring() {
177+
const result = await this.service.searchRepos(this.user, "repos-1076", 100);
178+
expect(result).to.be.empty;
179+
}
156180
}
157181

158182
module.exports = new TestBitbucketServerRepositoryProvider();

components/server/src/bitbucket/bitbucket-repository-provider.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,30 @@ class TestBitbucketRepositoryProvider {
9696
const result = await this.repoProvider.hasReadAccess(this.user, "foobar", "private-repo");
9797
expect(result).to.be.false;
9898
}
99+
100+
// In contrast to Bitbucket Server, bitbucket.org supports matching against a substring, not just a prefix.
101+
@test public async testSearchRepos_matchesSubstring() {
102+
const result = await this.repoProvider.searchRepos(this.user, "amp", 100);
103+
expect(result).to.deep.include({
104+
url: "https://bitbucket.org/gitpod-integration-tests/exampul-repo",
105+
name: "exampul-repo",
106+
});
107+
}
108+
109+
// Bitbucket supports searching for repos with arbitrary length search strings.
110+
@test public async testSearchRepos_shortSearchString() {
111+
const resultA = await this.repoProvider.searchRepos(this.user, "e", 100);
112+
expect(resultA.length).to.be.gt(0);
113+
114+
const resultB = await this.repoProvider.searchRepos(this.user, "ex", 100);
115+
expect(resultB.length).to.be.gt(0);
116+
}
117+
118+
// Bitbucket only searches for repositories by their name, not by their full path.
119+
@test public async testSearchRepos_doesNotMatchPath() {
120+
const result = await this.repoProvider.searchRepos(this.user, "gitpod-integration-tests/exampul-repo", 100);
121+
expect(result).to.be.empty;
122+
}
99123
}
100124

101125
module.exports = new TestBitbucketRepositoryProvider();

components/server/src/github/github-repository-provider.spec.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ class TestGithubContextRepositoryProvider {
6262
description: "",
6363
icon: "",
6464
host: "github.com",
65-
oauth: "not-used" as any,
65+
oauth: {
66+
callBackUrl: "https://gitpod.example.com/auth/github/callback",
67+
} as any,
6668
};
6769

6870
@test public async testFetchCommitHistory() {
@@ -79,6 +81,26 @@ class TestGithubContextRepositoryProvider {
7981
]);
8082
}
8183

84+
@test public async testSearchRepos_onlyMatchesByPrefix() {
85+
const resultA = await this.provider.searchRepos(this.user, "xample", 100);
86+
expect(resultA.length).to.be.eq(0);
87+
88+
const resultB = await this.provider.searchRepos(this.user, "e", 100);
89+
expect(resultB.length).to.be.eq(1);
90+
}
91+
92+
@test public async testSearchRepos_matchesAgainstWholePath() {
93+
const resultMatchesSuffix = await this.provider.searchRepos(this.user, "-integration-test/example", 100);
94+
expect(resultMatchesSuffix.length).to.be.eq(1);
95+
96+
const resultDoesNotMatchSubstring = await this.provider.searchRepos(
97+
this.user,
98+
"gitpod-integration-test/exampl",
99+
100,
100+
);
101+
expect(resultDoesNotMatchSubstring.length).to.be.eq(0);
102+
}
103+
82104
@test public async testGetUserRepos() {
83105
const result = await this.provider.getUserRepos(this.user);
84106
expect(result).to.deep.include({ url: "https://github.com/gitpod-integration-test/example", name: "example" });

components/server/src/gitlab/gitlab-repository-provider.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,31 @@ class TestGitlabRepositoryProvider {
6464
"f2d9790f2752a794517b949c65a773eb864844cd",
6565
]);
6666
}
67+
68+
@test public async testSearchRepos_matchesSubstring() {
69+
const result = await this.repositoryProvider.searchRepos(this.user, "est", 100);
70+
expect(result.length).to.be.eq(1);
71+
}
72+
73+
// The minimum search string length is 3 characters (unless there is an exact match).
74+
@test public async testSearchRepos_shortSearchString_looseMatch() {
75+
const resultA = await this.repositoryProvider.searchRepos(this.user, "t", 100);
76+
expect(resultA.length).to.be.eq(0);
77+
78+
const resultB = await this.repositoryProvider.searchRepos(this.user, "te", 100);
79+
expect(resultB.length).to.be.eq(0);
80+
}
81+
82+
@test public async testSearchRepos_shortSearchString_exactMatch() {
83+
const result = await this.repositoryProvider.searchRepos(this.user, "g", 100);
84+
expect(result.length).to.be.eq(1);
85+
}
86+
87+
// GitLab API does not support searching for repositories by their full path, only by their name.
88+
@test public async testSearchRepos_noMatchAgainstWholePath() {
89+
const result = await this.repositoryProvider.searchRepos(this.user, "gitpod-integration-tests/test", 100);
90+
expect(result.length).to.be.eq(0);
91+
}
6792
}
6893

6994
module.exports = new TestGitlabRepositoryProvider();

0 commit comments

Comments
 (0)