@@ -42,8 +42,8 @@ describe('yaml', function() {
4242 property : 'version'
4343 }
4444 } ;
45- this . mockFs . expects ( 'readFileSync' ) . once ( ) . withExactArgs ( 'someplaybook.yaml' , 'UTF-8' ) . returns ( '{ " version" : "0.0.0" } ' ) ;
46- this . mockFs . expects ( 'writeFile' ) . once ( ) . withExactArgs ( 'someplaybook.yaml' , 'version : 1.2.3\n' , sinon . match . func ) . callsArgWith ( 2 , null ) ;
45+ this . mockFs . expects ( 'readFileSync' ) . once ( ) . withExactArgs ( 'someplaybook.yaml' , 'UTF-8' ) . returns ( 'version: "0.0.0"' ) ;
46+ this . mockFs . expects ( 'writeFile' ) . once ( ) . withExactArgs ( 'someplaybook.yaml' , '---\nversion : 1.2.3\n' , sinon . match . func ) . callsArgWith ( 2 , null ) ;
4747 function cb ( err , result ) {
4848 assert . equal ( err , null ) ;
4949 done ( ) ;
@@ -58,14 +58,30 @@ describe('yaml', function() {
5858 property : 'versions[1].minor'
5959 }
6060 } ;
61- this . mockFs . expects ( 'readFileSync' ) . once ( ) . withExactArgs ( 'someplaybook.yaml' , 'UTF-8' ) . returns ( '{ "versions": [{ " major" : 1, " minor" : 2, " patch" : 3 }, { " major" : 8, " minor" : 9, " patch" : 0 }] } ' ) ;
62- this . mockFs . expects ( 'writeFile' ) . once ( ) . withExactArgs ( 'someplaybook.yaml' , 'versions :\n - major: 1\n minor: 2\n patch: 3\n - major: 8\n minor: 9\n patch: 0\n' , sinon . match . func ) . callsArgWith ( 2 , null ) ;
61+ this . mockFs . expects ( 'readFileSync' ) . once ( ) . withExactArgs ( 'someplaybook.yaml' , 'UTF-8' ) . returns ( '---\nversions:\n - major: 1\n minor: 2\n patch: 3\n - major: 8\n minor: 9\n patch: 0\n ' ) ;
62+ this . mockFs . expects ( 'writeFile' ) . once ( ) . withExactArgs ( 'someplaybook.yaml' , '---\nversions :\n - major: 1\n minor: 2\n patch: 3\n - major: 8\n minor: 9\n patch: 0\n' , sinon . match . func ) . callsArgWith ( 2 , null ) ;
6363 function cb ( err , result ) {
6464 assert . equal ( err , null ) ;
6565 done ( ) ;
6666 }
6767 resourceType . setReleaseVersion ( 9 , resource , { dryRun : false } , cb ) ;
6868 } ) ;
69+ it ( 'should not double up document separator YAML header when it already exists' , function ( done ) {
70+ const resource = {
71+ path : 'someplaybook.yaml' ,
72+ type : 'yaml' ,
73+ params : {
74+ property : 'version'
75+ }
76+ } ;
77+ this . mockFs . expects ( 'readFileSync' ) . once ( ) . withExactArgs ( 'someplaybook.yaml' , 'UTF-8' ) . returns ( '---\nversion: "0.0.0"' ) ;
78+ this . mockFs . expects ( 'writeFile' ) . once ( ) . withExactArgs ( 'someplaybook.yaml' , '---\nversion: 1.2.3\n' , sinon . match . func ) . callsArgWith ( 2 , null ) ;
79+ function cb ( err , result ) {
80+ assert . equal ( err , null ) ;
81+ done ( ) ;
82+ }
83+ resourceType . setReleaseVersion ( '1.2.3' , resource , { dryRun : false } , cb ) ;
84+ } ) ;
6985 } ) ;
7086
7187 describe ( 'getVersion' , function ( ) {
@@ -77,7 +93,7 @@ describe('yaml', function() {
7793 property : 'version'
7894 }
7995 } ;
80- this . mockFs . expects ( 'readFile' ) . once ( ) . withExactArgs ( 'someplaybook.yaml' , 'UTF-8' , sinon . match . func ) . callsArgWith ( 2 , null , '{ " version" : "0.0.0" } ' ) ;
96+ this . mockFs . expects ( 'readFile' ) . once ( ) . withExactArgs ( 'someplaybook.yaml' , 'UTF-8' , sinon . match . func ) . callsArgWith ( 2 , null , 'version: "0.0.0"' ) ;
8197 function cb ( err , result ) {
8298 assert . equal ( err , null ) ;
8399 assert . equal ( result , '0.0.0' ) ;
@@ -93,7 +109,7 @@ describe('yaml', function() {
93109 property : 'versions[1].minor'
94110 }
95111 } ;
96- this . mockFs . expects ( 'readFile' ) . once ( ) . withExactArgs ( 'someplaybook.yaml' , 'UTF-8' , sinon . match . func ) . callsArgWith ( 2 , null , '{ "versions": [{ " major" : 1, " minor" : 2, " patch" : 3 }, { " major" : 8, " minor" : 9, " patch" : 0 }] } ' ) ;
112+ this . mockFs . expects ( 'readFile' ) . once ( ) . withExactArgs ( 'someplaybook.yaml' , 'UTF-8' , sinon . match . func ) . callsArgWith ( 2 , null , '---\nversions:\n - major: 1\n minor: 2\n patch: 3\n - major: 8\n minor: 9\n patch: 0\n ' ) ;
97113 function cb ( err , result ) {
98114 assert . equal ( err , null ) ;
99115 assert . equal ( result , 9 ) ;
0 commit comments