-
Notifications
You must be signed in to change notification settings - Fork 1
/
import_func_test.go
65 lines (55 loc) · 1.57 KB
/
import_func_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package templit_test
import (
"fmt"
"os"
"strings"
"testing"
"github.com/euforic/templit"
)
// TestImportFunc tests the ImportFunc function.
func TestImportFunc(t *testing.T) {
tests := []struct {
name string
repoAndTag string
data interface{}
expectedError error
}{
{
// Add your test cases here
name: "Valid template processing",
repoAndTag: "https://test_data/templates/basic_test@main",
data: map[string]interface{}{
"Name": "John",
"Title": "Project",
"Description": "This is a test project.",
"Detail": "more info here.",
},
},
}
// Mocked GitClient
client := &MockGitClient{}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
destPath, err := os.MkdirTemp("", "test_output_"+strings.ReplaceAll(strings.ToLower(tt.name), " ", "_"))
if err != nil {
t.Fatal(fmt.Errorf("failed to create temp dir: %w", err))
}
defer os.RemoveAll(destPath) // Cleanup
executor := templit.NewExecutor(client)
fn := executor.ImportFunc(destPath)
if _, err := fn(tt.repoAndTag, "./", tt.data); err != nil {
if tt.expectedError == nil || err.Error() != tt.expectedError.Error() {
t.Fatalf("expected error %v, got %v", tt.expectedError, err)
}
return
}
// Compare generated files with expected outputs
repo := strings.Split(tt.repoAndTag, "@")[0]
expectedOutputPath := strings.Replace(repo, "templates", "outputs", 1)
err = compareDirs(destPath, strings.TrimPrefix(expectedOutputPath, "https://"))
if err != nil {
t.Fatal(err)
}
})
}
}