@@ -18,26 +18,48 @@ import (
1818
1919const (
2020 metadata = `name: my-app
21- version: 1.0.0`
22- yaml = `version: "3.1"
23-
21+ version: 1.0.0
22+ `
23+ compose = `version: "3.1"
2424services:
2525 web:
26- image: nginx`
27- parameters = `foo: bar`
26+ image: nginx
27+ `
28+ params = `foo: bar
29+ `
2830)
2931
3032func TestLoadFromSingleFile (t * testing.T ) {
31- singlefile := fmt .Sprintf (`%s
32- ---
33- %s
34- ---
35- %s` , metadata , yaml , parameters )
36- app , err := LoadFromSingleFile ("my-app" , strings .NewReader (singlefile ))
37- assert .NilError (t , err )
38- assert .Assert (t , app != nil )
39- assert .Assert (t , is .Equal (app .Path , "my-app" ))
40- assertAppContent (t , app )
33+ testCases := []struct {
34+ name string
35+ file string
36+ }{
37+ {
38+ name : "line-feed" ,
39+ file : fmt .Sprintf ("%s\n ---\n %s\n ---\n %s" , metadata , compose , params ),
40+ },
41+ {
42+ name : "carriage-return-line-feed" ,
43+ file : fmt .Sprintf ("%s\r \n ---\r \n %s\r \n ---\r \n %s" , metadata , compose , params ),
44+ },
45+ {
46+ name : "mixed-carriage-return-line-feed" ,
47+ file : fmt .Sprintf ("%s\r \n ---\r \n %s\r \n ---\n %s" , metadata , compose , params ),
48+ },
49+ {
50+ name : "unordered-documents" ,
51+ file : fmt .Sprintf ("%s\n ---\n %s\n ---\n %s" , params , metadata , compose ),
52+ },
53+ }
54+ for _ , test := range testCases {
55+ t .Run (test .name , func (t * testing.T ) {
56+ app , err := LoadFromSingleFile ("my-app" , strings .NewReader (test .file ))
57+ assert .NilError (t , err )
58+ assert .Assert (t , app != nil )
59+ assert .Assert (t , is .Equal (app .Path , "my-app" ))
60+ assertAppContent (t , app )
61+ })
62+ }
4163}
4264
4365func TestLoadFromSingleFileInvalidReader (t * testing.T ) {
@@ -46,17 +68,17 @@ func TestLoadFromSingleFileInvalidReader(t *testing.T) {
4668}
4769
4870func TestLoadFromSingleFileMalformed (t * testing.T ) {
49- _ , err := LoadFromSingleFile ("my-app" , strings .NewReader (`foo
71+ _ , err := LoadFromSingleFile ("my-app" , strings .NewReader (`foo: foo
5072---
51- bar` ))
73+ bar: bar ` ))
5274 assert .ErrorContains (t , err , "malformed single-file application" )
5375}
5476
5577func TestLoadFromDirectory (t * testing.T ) {
5678 dir := fs .NewDir (t , "my-app" ,
5779 fs .WithFile (internal .MetadataFileName , metadata ),
58- fs .WithFile (internal .ParametersFileName , parameters ),
59- fs .WithFile (internal .ComposeFileName , yaml ),
80+ fs .WithFile (internal .ParametersFileName , params ),
81+ fs .WithFile (internal .ComposeFileName , compose ),
6082 )
6183 defer dir .Remove ()
6284 app , err := LoadFromDirectory (dir .Path ())
@@ -69,8 +91,8 @@ func TestLoadFromDirectory(t *testing.T) {
6991func TestLoadFromDirectoryDeprecatedSettings (t * testing.T ) {
7092 dir := fs .NewDir (t , "my-app" ,
7193 fs .WithFile (internal .MetadataFileName , metadata ),
72- fs .WithFile (internal .DeprecatedSettingsFileName , parameters ),
73- fs .WithFile (internal .ComposeFileName , yaml ),
94+ fs .WithFile (internal .DeprecatedSettingsFileName , params ),
95+ fs .WithFile (internal .ComposeFileName , compose ),
7496 )
7597 defer dir .Remove ()
7698 app , err := LoadFromDirectory (dir .Path ())
@@ -97,8 +119,8 @@ func createAppTar(t *testing.T) *fs.File {
97119 t .Helper ()
98120 dir := fs .NewDir (t , "my-app" ,
99121 fs .WithFile (internal .MetadataFileName , metadata ),
100- fs .WithFile (internal .ParametersFileName , parameters ),
101- fs .WithFile (internal .ComposeFileName , yaml ),
122+ fs .WithFile (internal .ParametersFileName , params ),
123+ fs .WithFile (internal .ComposeFileName , compose ),
102124 )
103125 defer dir .Remove ()
104126 r , err := archive .TarWithOptions (dir .Path (), & archive.TarOptions {
@@ -117,9 +139,9 @@ func assertContentIs(t *testing.T, actual []byte, expected string) {
117139
118140func assertAppContent (t * testing.T , app * types.App ) {
119141 assert .Assert (t , is .Len (app .ParametersRaw (), 1 ))
120- assertContentIs (t , app .ParametersRaw ()[0 ], parameters )
142+ assertContentIs (t , app .ParametersRaw ()[0 ], params )
121143 assert .Assert (t , is .Len (app .Composes (), 1 ))
122- assertContentIs (t , app .Composes ()[0 ], yaml )
144+ assertContentIs (t , app .Composes ()[0 ], compose )
123145 assertContentIs (t , app .MetadataRaw (), metadata )
124146}
125147
0 commit comments