Skip to content

Commit

Permalink
Fix reading of converted template header (#2064)
Browse files Browse the repository at this point in the history
Also enabled the test
  • Loading branch information
amanya authored and Scott Bloch-Wehba-Seaward committed Apr 5, 2018
1 parent 274420a commit 144807b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,15 @@
*/
package com.netflix.spinnaker.orca.pipelinetemplate.v1schema.converter;

import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.google.common.io.Resources;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.representer.Representer;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -158,11 +155,11 @@ private List<Map<String, Object>> convertNotifications(List<Map<String, Object>>
}

private String loadTemplateHeader() {
try {
return Files.toString(new File(Resources.getResource("pipelineTemplateHeader.txt").toURI()), Charsets.UTF_8);
} catch (IOException | URISyntaxException e) {
log.error("Could not load pipeline template header resource", e);
return "GENERATED BY spinnaker";
InputStream is = getClass().getResourceAsStream("/pipelineTemplateHeader.txt");
if (is == null) {
log.error("Could not load pipeline template header resource");
return "# GENERATED BY spinnaker\n";
}
return new BufferedReader(new InputStreamReader(is)).lines().collect(Collectors.joining("\n"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
# * Best intentions are made to order configuration, but the list of stages
# themselves are not ordered: Rearrange the stages so that they're roughly
# chronological.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import groovy.json.JsonSlurper
import spock.lang.Ignore
import spock.lang.Specification

@Ignore
class PipelineTemplateConverterSpec extends Specification {

def "should convert a pipeline to an ordered pipeline template yaml document"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@ configuration:
- enabled: false
job: ZZ-demo
master: myMaster
name: unnamed0
type: jenkins
name: unnamed0
- cronExpression: 0 0/12 * * * ?
enabled: true
id: b2ba0819-dbe5-42bd-a8b0-0499c131711f
name: unnamed1
type: cron
name: unnamed1
parameters: []
notifications:
- address: example@example.com
level: pipeline
type: email
when:
- pipeline.failed
name: email0
expectedArtifacts:
- defaultArtifact:
kind: custom
Expand All @@ -48,14 +56,6 @@ configuration:
name: MyJenkinsJob
useDefaultArtifact: false
usePriorExecution: false
parameters: []
notifications:
- address: example@example.com
level: pipeline
name: email0
type: email
when:
- pipeline.failed
variables: []
stages:
- id: bake1
Expand Down

0 comments on commit 144807b

Please sign in to comment.