-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove master.zip after unpacking templates from archive
1. Remove master.zip after pulling template directory 2. Tests template fetch with mock HTTP server Signed-off-by: Eric Stoekl <ems5311@gmail.com>
- Loading branch information
1 parent
64475ae
commit db425d5
Showing
4 changed files
with
74 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) Alex Ellis, Eric Stoekl 2017. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
package commands | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"os" | ||
"testing" | ||
) | ||
|
||
var SmallestZipFile = []byte{80, 75, 05, 06, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00} | ||
|
||
func Test_PullTemplates(t *testing.T) { | ||
// Remove existing master.zip file if it exists | ||
if _, err := os.Stat("master.zip"); err == nil { | ||
t.Log("Found a master.zip file, removing it...") | ||
|
||
err := os.Remove("master.zip") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
// Remove existing templates folder, if it exist | ||
if _, err := os.Stat("template/"); err == nil { | ||
t.Log("Found a template/ directory, removing it...") | ||
|
||
err := os.RemoveAll("template/") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
// Create fake server for testing. | ||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
|
||
// Write out the minimum number of bytes to make the response a valid .zip file | ||
w.Write(SmallestZipFile) | ||
|
||
})) | ||
defer ts.Close() | ||
|
||
err := PullTemplates(ts.URL) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters