|
1 | 1 | package commands |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "os" |
| 5 | + "path/filepath" |
4 | 6 | "reflect" |
5 | 7 | "testing" |
6 | 8 |
|
| 9 | + "github.com/openfaas/faas-cli/builder" |
7 | 10 | "github.com/openfaas/faas-cli/stack" |
8 | 11 | ) |
9 | 12 |
|
@@ -105,3 +108,31 @@ func Test_pullAllTemplates(t *testing.T) { |
105 | 108 | }) |
106 | 109 | } |
107 | 110 | } |
| 111 | + |
| 112 | +func Test_filterExistingTemplates(t *testing.T) { |
| 113 | + templatesDir := "./template" |
| 114 | + defer os.RemoveAll(templatesDir) |
| 115 | + |
| 116 | + templates := []stack.TemplateSource{ |
| 117 | + {Name: "dockerfile", Source: "https://github.com/openfaas-incubator/powershell-http-template"}, |
| 118 | + {Name: "ruby", Source: "https://github.com/openfaas-incubator/openfaas-rust-template"}, |
| 119 | + {Name: "perl", Source: "https://github.com/openfaas-incubator/perl-template"}, |
| 120 | + } |
| 121 | + |
| 122 | + // Copy the submodule to temp directory to avoid altering it during tests |
| 123 | + testRepoGit := filepath.Join("testdata", "templates", "template") |
| 124 | + builder.CopyFiles(testRepoGit, templatesDir) |
| 125 | + |
| 126 | + newTemplateInfos, err := filterExistingTemplates(templates, templatesDir) |
| 127 | + if err != nil { |
| 128 | + t.Errorf("Unexpected error: %s", err.Error()) |
| 129 | + } |
| 130 | + |
| 131 | + if len(newTemplateInfos) != 1 { |
| 132 | + t.Errorf("Wanted new templates: `%d` got `%d`", 1, len(newTemplateInfos)) |
| 133 | + } |
| 134 | + |
| 135 | + if newTemplateInfos[0].Name != "perl" { |
| 136 | + t.Errorf("Wanted template: `%s` got `%s`", "perl", newTemplateInfos[0].Name) |
| 137 | + } |
| 138 | +} |
0 commit comments