Path: blob/main/components/gitpod-protocol/src/gitpod-file-parser.spec.ts
2498 views
/**1* Copyright (c) 2020 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { suite, test } from "@testdeck/mocha";7import * as chai from "chai";89import { WorkspaceConfig } from "./protocol";10import { GitpodFileParser } from "./gitpod-file-parser";1112const expect = chai.expect;1314const DEFAULT_IMAGE = "default-image";15const DEFAULT_CONFIG = <WorkspaceConfig>{ image: DEFAULT_IMAGE };1617@suite18class TestGitpodFileParser {19protected parser: GitpodFileParser;2021public before() {22this.parser = new GitpodFileParser();23}2425@test public testOnlyOnePort() {26const content = `ports:\n` + ` - port: 5555`;2728const result = this.parser.parse(content, {}, DEFAULT_CONFIG);29expect(result.config).to.deep.equal({30ports: [31{32port: 5555,33},34],35image: DEFAULT_IMAGE,36});37}3839@test public testPortRange() {40const content = `ports:\n` + ` - port: 5555\n` + ` - port: 3000-3999`; // should be filtered out by default4142const result = this.parser.parse(content, {}, DEFAULT_CONFIG);43expect(result.config).to.deep.equal({44ports: [45{46port: 5555,47},48],49image: DEFAULT_IMAGE,50});51}5253@test public testPortRangeAccepted() {54const content = `ports:\n` + ` - port: 5555\n` + ` - port: 3000-3999`; // should be included if explicitly supported5556const result = this.parser.parse(content, { acceptPortRanges: true }, DEFAULT_CONFIG);57expect(result.config).to.deep.equal({58ports: [59{60port: 5555,61},62{63port: "3000-3999",64},65],66image: DEFAULT_IMAGE,67});68}6970@test public testSimpleTask() {71const content = `tasks:\n` + ` - command: yarn`;7273const result = this.parser.parse(content, {}, DEFAULT_CONFIG);74expect(result.config).to.deep.equal({75tasks: [76{77command: "yarn",78},79],80image: DEFAULT_IMAGE,81});82}8384@test public testSimpleImage() {85const imageName = "my-test-org/my-test-image:some-tag";86const content = `image: "${imageName}"\n`;8788const result = this.parser.parse(content);89expect(result.config).to.deep.equal({90image: imageName,91});92}9394@test public testComplexImageWithoutContext() {95const dockerFileName = "Dockerfile";96const content = `image:\n file: ${dockerFileName}\n`;9798const result = this.parser.parse(content);99expect(result.config).to.deep.equal({100image: {101file: dockerFileName,102},103});104}105106@test public testComplexImageWithContext() {107const dockerFileName = "Dockerfile";108const dockerContext = "docker";109const content = `image:\n file: ${dockerFileName}\n context: ${dockerContext}\n`;110111const result = this.parser.parse(content);112expect(result.config).to.deep.equal({113image: {114file: dockerFileName,115context: dockerContext,116},117});118}119120@test public testGitconfig() {121const content = `122gitConfig:123core.autocrlf: input124`;125126const result = this.parser.parse(content, {}, DEFAULT_CONFIG);127expect(result.config).to.deep.equal({128gitConfig: {129"core.autocrlf": "input",130},131image: DEFAULT_IMAGE,132});133}134135@test public testBrokenConfig() {136const content = `image: 42\n`;137138const result = this.parser.parse(content, {}, DEFAULT_CONFIG);139expect(result.config).to.deep.equal({140image: DEFAULT_IMAGE,141});142}143}144module.exports = new TestGitpodFileParser(); // Only to circumvent no usage warning :-/145146147