11package loader
22
33import (
4- "fmt"
54 "io/ioutil"
6- "strings"
75 "testing"
86
97 "github.com/docker/app/internal"
108 "github.com/docker/app/types"
119 "github.com/docker/docker/pkg/archive"
12- "github.com/pkg/errors"
13-
1410 "gotest.tools/assert"
1511 is "gotest.tools/assert/cmp"
1612 "gotest.tools/fs"
@@ -29,47 +25,6 @@ services:
2925`
3026)
3127
32- func TestLoadFromSingleFile (t * testing.T ) {
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- for _ , test := range testCases {
51- t .Run (test .name , func (t * testing.T ) {
52- app , err := LoadFromSingleFile ("my-app" , strings .NewReader (test .file ))
53- assert .NilError (t , err )
54- assert .Assert (t , app != nil )
55- assert .Assert (t , is .Equal (app .Path , "my-app" ))
56- assertAppContent (t , app )
57- })
58- }
59- }
60-
61- func TestLoadFromSingleFileInvalidReader (t * testing.T ) {
62- _ , err := LoadFromSingleFile ("my-app" , & faultyReader {})
63- assert .ErrorContains (t , err , "faulty reader" )
64- }
65-
66- func TestLoadFromSingleFileMalformed (t * testing.T ) {
67- _ , err := LoadFromSingleFile ("my-app" , strings .NewReader (`foo: foo
68- ---
69- bar: bar` ))
70- assert .ErrorContains (t , err , "malformed single-file application" )
71- }
72-
7328func TestLoadFromDirectory (t * testing.T ) {
7429 dir := fs .NewDir (t , "my-app" ,
7530 fs .WithFile (internal .MetadataFileName , metadata ),
@@ -140,9 +95,3 @@ func assertAppContent(t *testing.T, app *types.App) {
14095 assertContentIs (t , app .Composes ()[0 ], compose )
14196 assertContentIs (t , app .MetadataRaw (), metadata )
14297}
143-
144- type faultyReader struct {}
145-
146- func (r * faultyReader ) Read (_ []byte ) (int , error ) {
147- return 0 , errors .New ("faulty reader" )
148- }
0 commit comments