|
| 1 | +/** |
| 2 | + * Copyright (c) 2022 Gitpod GmbH. All rights reserved. |
| 3 | + * Licensed under the GNU Affero General Public License (AGPL). |
| 4 | + * See License-AGPL.txt in the project root for license information. |
| 5 | + */ |
| 6 | + |
| 7 | +import { User } from "@gitpod/gitpod-protocol"; |
| 8 | +import { skipIfEnvVarNotSet } from "@gitpod/gitpod-protocol/lib/util/skip-if"; |
| 9 | +import { expect } from "chai"; |
| 10 | +import { Container, ContainerModule } from "inversify"; |
| 11 | +import { suite, retries, test, timeout } from "mocha-typescript"; |
| 12 | +import { AuthProviderParams } from "../auth/auth-provider"; |
| 13 | +import { DevData } from "../dev/dev-data"; |
| 14 | +import { TokenProvider } from "../user/token-provider"; |
| 15 | +import { GitHubRestApi } from "./api"; |
| 16 | + |
| 17 | +import { GithubFileProvider } from "./file-provider"; |
| 18 | +import { GitHubTokenHelper } from "./github-token-helper"; |
| 19 | + |
| 20 | +@suite(timeout(10000), retries(2), skipIfEnvVarNotSet("GITPOD_TEST_TOKEN_GITHUB")) |
| 21 | +class TestFileProvider { |
| 22 | + static readonly AUTH_HOST_CONFIG: Partial<AuthProviderParams> = { |
| 23 | + id: "Public-GitHub", |
| 24 | + type: "GitHub", |
| 25 | + verified: true, |
| 26 | + description: "", |
| 27 | + icon: "", |
| 28 | + host: "github.com", |
| 29 | + }; |
| 30 | + |
| 31 | + protected fileProvider: GithubFileProvider; |
| 32 | + protected user: User; |
| 33 | + protected container: Container; |
| 34 | + |
| 35 | + public before() { |
| 36 | + this.container = new Container(); |
| 37 | + this.container.load( |
| 38 | + new ContainerModule((bind, unbind, isBound, rebind) => { |
| 39 | + bind(GitHubRestApi).toSelf().inSingletonScope(); |
| 40 | + bind(AuthProviderParams).toConstantValue(TestFileProvider.AUTH_HOST_CONFIG); |
| 41 | + bind(GitHubTokenHelper).toSelf().inSingletonScope(); |
| 42 | + bind(TokenProvider).toConstantValue(<TokenProvider>{ |
| 43 | + getTokenForHost: async () => DevData.createGitHubTestToken(), |
| 44 | + getFreshPortAuthenticationToken: async (user: User, workspaceId: string) => |
| 45 | + DevData.createPortAuthTestToken(workspaceId), |
| 46 | + }); |
| 47 | + bind(GithubFileProvider).toSelf().inSingletonScope(); |
| 48 | + }), |
| 49 | + ); |
| 50 | + this.fileProvider = this.container.get(GithubFileProvider); |
| 51 | + this.user = DevData.createTestUser(); |
| 52 | + } |
| 53 | + |
| 54 | + @test public async testFileContent() { |
| 55 | + const result = await this.fileProvider.getFileContent( |
| 56 | + { |
| 57 | + repository: { |
| 58 | + owner: "gitpod-io", |
| 59 | + name: "gitpod", |
| 60 | + host: "github.com", |
| 61 | + cloneUrl: "unused in test", |
| 62 | + }, |
| 63 | + revision: "af51739d341bb2245598e275336ae9f730e3b41a", |
| 64 | + }, |
| 65 | + this.user, |
| 66 | + "License.txt", |
| 67 | + ); |
| 68 | + expect(result).to.not.be.undefined; |
| 69 | + expect(result).to.contain(`To determine under which license you may use a file from the Gitpod source code, |
| 70 | +please resort to the header of that file.`); |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +module.exports = new TestFileProvider(); |
0 commit comments