@@ -3,6 +3,7 @@ package app
3
3
import (
4
4
"flag"
5
5
"io/ioutil"
6
+ "os"
6
7
"path/filepath"
7
8
"testing"
8
9
@@ -55,3 +56,88 @@ func TestProjectFactoryProjectNameIsNormalized(t *testing.T) {
55
56
}
56
57
}
57
58
}
59
+
60
+ func TestProjectFactoryFileArgMayContainMultipleFiles (t * testing.T ) {
61
+ sep := string (os .PathListSeparator )
62
+ fileCases := []struct {
63
+ requested []string
64
+ available []string
65
+ expected []string
66
+ }{
67
+ {
68
+ requested : []string {},
69
+ available : []string {"docker-compose.yml" },
70
+ expected : []string {"docker-compose.yml" },
71
+ },
72
+ {
73
+ requested : []string {},
74
+ available : []string {"docker-compose.yml" , "docker-compose.override.yml" },
75
+ expected : []string {"docker-compose.yml" , "docker-compose.override.yml" },
76
+ },
77
+ {
78
+ requested : []string {"one.yml" },
79
+ available : []string {"one.yml" },
80
+ expected : []string {"one.yml" },
81
+ },
82
+ {
83
+ requested : []string {"one.yml" },
84
+ available : []string {"docker-compose.yml" , "one.yml" },
85
+ expected : []string {"one.yml" },
86
+ },
87
+ {
88
+ requested : []string {"one.yml" , "two.yml" , "three.yml" },
89
+ available : []string {"one.yml" , "two.yml" , "three.yml" },
90
+ expected : []string {"one.yml" , "two.yml" , "three.yml" },
91
+ },
92
+ {
93
+ requested : []string {"one.yml" + sep + "two.yml" + sep + "three.yml" },
94
+ available : []string {"one.yml" , "two.yml" , "three.yml" },
95
+ expected : []string {"one.yml" , "two.yml" , "three.yml" },
96
+ },
97
+ {
98
+ requested : []string {"one.yml" + sep + "two.yml" , "three.yml" + sep + "four.yml" },
99
+ available : []string {"one.yml" , "two.yml" , "three.yml" , "four.yml" },
100
+ expected : []string {"one.yml" , "two.yml" , "three.yml" , "four.yml" },
101
+ },
102
+ {
103
+ requested : []string {"one.yml" , "two.yml" + sep + "three.yml" },
104
+ available : []string {"one.yml" , "two.yml" , "three.yml" },
105
+ expected : []string {"one.yml" , "two.yml" , "three.yml" },
106
+ },
107
+ }
108
+
109
+ for _ , fileCase := range fileCases {
110
+ tmpDir , err := ioutil .TempDir ("" , "project-factory-test" )
111
+ if err != nil {
112
+ t .Fatal (err )
113
+ }
114
+ defer os .RemoveAll (tmpDir )
115
+ if err = os .Chdir (tmpDir ); err != nil {
116
+ t .Fatal (err )
117
+ }
118
+
119
+ for _ , file := range fileCase .available {
120
+ ioutil .WriteFile (file , []byte (`hello:
121
+ image: busybox` ), 0700 )
122
+ }
123
+ globalSet := flag .NewFlagSet ("test" , 0 )
124
+ // Set the project-name flag
125
+ globalSet .String ("project-name" , "example" , "doc" )
126
+ // Set the compose file flag
127
+ fcr := cli .StringSlice (fileCase .requested )
128
+ globalSet .Var (& fcr , "file" , "doc" )
129
+ c := cli .NewContext (nil , globalSet , nil )
130
+ factory := & ProjectFactory {}
131
+ p , err := factory .Create (c )
132
+ if err != nil {
133
+ t .Fatal (err )
134
+ }
135
+
136
+ for i , v := range p .(* project.Project ).Files {
137
+ if v != fileCase .expected [i ] {
138
+ t .Fatalf ("requested %s, available %s, expected %s, got %s" ,
139
+ fileCase .requested , fileCase .available , fileCase .expected , p .(* project.Project ).Files )
140
+ }
141
+ }
142
+ }
143
+ }
0 commit comments