@@ -65,6 +65,74 @@ func TestCreateReleaseFileCreatesTgz(t *testing.T) {
6565 }
6666}
6767
68+ func TestCreateReleaseFileCreatesTgzWithEnvFile (t * testing.T ) {
69+ tmpDir := t .TempDir ()
70+ mockConfig (tmpDir , t , []byte ("services:\n foo:\n image: bar\n env:\n source: 'foo.env'\n " ))
71+
72+ if err := os .WriteFile (filepath .Join (tmpDir , "foo.env" ), []byte ("FOO=BAR" ), os .ModePerm ); err != nil {
73+ t .Fatal (err )
74+ }
75+
76+ fake := fakeKoolDeploy (tmpDir )
77+ fake .env .Set ("PWD" , tmpDir )
78+
79+ if err := fake .loadAndValidateConfig (); err != nil {
80+ t .Errorf ("unexpected error on loadAndValidateConfig; got: %v" , err )
81+ }
82+
83+ if tg , err := fake .createReleaseFile (); err != nil {
84+ t .Errorf ("unexpected error on createReleaseFile; got: %v" , err )
85+ } else if _ , err := os .Stat (tg ); err != nil {
86+ t .Errorf ("expected tgz file to be created; got: %v" , err )
87+ }
88+
89+ if ! fake .shell .(* shell.FakeShell ).CalledPrintln {
90+ t .Error ("expected Println to have been called on shell" )
91+ } else if ! strings .Contains (fake .shell .(* shell.FakeShell ).OutLines [0 ], "Compressing files:" ) {
92+ t .Error ("expected to print 'Compressing files:'" )
93+ } else if ! strings .Contains (fake .shell .(* shell.FakeShell ).OutLines [1 ], "- " + filepath .Join (tmpDir , "kool.cloud.yml" )) {
94+ t .Error ("expected to print '- " + filepath .Join (tmpDir , "kool.cloud.yml" ) + "'" )
95+ } else if ! strings .Contains (fake .shell .(* shell.FakeShell ).OutLines [2 ], "- " + filepath .Join (tmpDir , "docker-compose.yml" )) {
96+ t .Error ("expected to print '- " + filepath .Join (tmpDir , "docker-compose.yml" ) + "'" )
97+ } else if ! strings .Contains (fake .shell .(* shell.FakeShell ).OutLines [3 ], "- " + filepath .Join (tmpDir , "foo.env" )) {
98+ t .Error ("expected to print '- " + filepath .Join (tmpDir , "foo.env" ) + "'" )
99+ }
100+ }
101+
102+ func TestCreateReleaseFileCreatesTgzWithEnvironmentFile (t * testing.T ) {
103+ tmpDir := t .TempDir ()
104+ mockConfig (tmpDir , t , []byte ("services:\n foo:\n image: bar\n environment: 'bar.env'\n " ))
105+
106+ if err := os .WriteFile (filepath .Join (tmpDir , "bar.env" ), []byte ("BAR=FOO" ), os .ModePerm ); err != nil {
107+ t .Fatal (err )
108+ }
109+
110+ fake := fakeKoolDeploy (tmpDir )
111+ fake .env .Set ("PWD" , tmpDir )
112+
113+ if err := fake .loadAndValidateConfig (); err != nil {
114+ t .Errorf ("unexpected error on loadAndValidateConfig; got: %v" , err )
115+ }
116+
117+ if tg , err := fake .createReleaseFile (); err != nil {
118+ t .Errorf ("unexpected error on createReleaseFile; got: %v" , err )
119+ } else if _ , err := os .Stat (tg ); err != nil {
120+ t .Errorf ("expected tgz file to be created; got: %v" , err )
121+ }
122+
123+ if ! fake .shell .(* shell.FakeShell ).CalledPrintln {
124+ t .Error ("expected Println to have been called on shell" )
125+ } else if ! strings .Contains (fake .shell .(* shell.FakeShell ).OutLines [0 ], "Compressing files:" ) {
126+ t .Error ("expected to print 'Compressing files:'" )
127+ } else if ! strings .Contains (fake .shell .(* shell.FakeShell ).OutLines [1 ], "- " + filepath .Join (tmpDir , "kool.cloud.yml" )) {
128+ t .Error ("expected to print '- " + filepath .Join (tmpDir , "kool.cloud.yml" ) + "'" )
129+ } else if ! strings .Contains (fake .shell .(* shell.FakeShell ).OutLines [2 ], "- " + filepath .Join (tmpDir , "docker-compose.yml" )) {
130+ t .Error ("expected to print '- " + filepath .Join (tmpDir , "docker-compose.yml" ) + "'" )
131+ } else if ! strings .Contains (fake .shell .(* shell.FakeShell ).OutLines [3 ], "- " + filepath .Join (tmpDir , "bar.env" )) {
132+ t .Error ("expected to print '- " + filepath .Join (tmpDir , "bar.env" ) + "'" )
133+ }
134+ }
135+
68136func TestCleanupReleaseFile (t * testing.T ) {
69137 tmpDir := t .TempDir ()
70138 mockConfig (tmpDir , t , nil )
0 commit comments