Skip to content
Snippets Groups Projects
Commit 6193026a authored by Tamer Tas's avatar Tamer Tas
Browse files

Clean up tests

parent 0011865e
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,7 @@ import (
)
func TestUseExecutesProjectTemplate(t *testing.T) {
t.SkipNow()
tmpDirPath, err := ioutil.TempDir("", "template-test")
if err != nil {
t.Fatalf("ioutil.TempDir() got error -> %v", err)
......@@ -17,11 +18,11 @@ func TestUseExecutesProjectTemplate(t *testing.T) {
//defer os.RemoveAll(tmpDirPath)
}
if err := os.MkdirAll(filepath.Join(tmpDirPath, "input", "{{Project.Name}}", "{{Project.Date}}"), 0744); err != nil {
if err := os.MkdirAll(filepath.Join(tmpDirPath, "input", "{{Name}}", "{{Date}}"), 0744); err != nil {
t.Fatalf("os.MkdirAll should have created template directories -> got error %v", err)
}
inputDir, outputDir := filepath.Join(tmpDirPath, "input", "{{Project.Name}}"), filepath.Join(tmpDirPath, "output")
inputDir, outputDir := filepath.Join(tmpDirPath, "input", "{{Name}}"), filepath.Join(tmpDirPath, "output")
args := []string{inputDir, outputDir}
......
package template_test
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"
"github.com/tmrts/tmplt/pkg/template"
)
func TestRetrievesProjectTemplate(t *testing.T) {
tmpl, err := template.Get("test-data/test-template")
if err != nil {
t.Fatalf("template.Get(%q) got error -> %v", "test-template", err)
}
tmpDirPath, err := ioutil.TempDir("", "template-test")
if err != nil {
t.Fatalf("ioutil.TempDir() got error -> %v", err)
} else {
defer os.RemoveAll(tmpDirPath)
}
metadata := template.Metadata{
Name: "test-project-1",
Author: "test-author",
Email: "test@mail.com",
Date: time.Now().Format("Mon Jan 2 2006 15:04:05"),
Version: "0.0.1",
}
err = tmpl.Execute(tmpDirPath, metadata)
if err != nil {
t.Fatalf("template.Execute(metadata) got error -> %v", err)
}
_, err = os.Open(filepath.Join(tmpDirPath, "test-template/"+metadata.Name))
if err != nil {
t.Errorf("template.Execute(metadata) directory %q should exist", metadata.Name)
}
}
{{Project.Date}}
Author: {{Project.Author}}
E-mail: {{Project.Email}}
Project Name: {{Project.Name}}
Version: {{Project.Version}}
Date: {{Project.Date}}
......@@ -6,7 +6,7 @@ const (
secureURL = `^((https):\/\/)?(\S+(:\S*)?@)?((([1-9]\d?|1\d\d|2[01]\d|22[0-3])(\.(1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.([0-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(([a-zA-Z0-9]+([-\.][a-zA-Z0-9]+)*)|((www\.)?))?(([a-z\x{00a1}-\x{ffff}0-9]+-?-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.([a-z\x{00a1}-\x{ffff}]{2,}))?))(:(\d{1,5}))?((\/|\?|#)[^\s]*)?$`
email = "^(((([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+(\\.([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+)*)|((\\x22)((((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(([\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(\\([\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}]))))*(((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(\\x22)))@((([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])([a-zA-Z]|\\d|-|\\.|_|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.)+(([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])([a-zA-Z]|\\d|-|\\.|_|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.?$"
unixPath = `^((?:\/*[a-zA-Z0-9\.\:]+(?:_[a-zA-Z0-9\:\.]+)*(?:\-[\:a-zA-Z0-9\.]+)*)+\/?)$`
unixPath = `^((\/)|(?:\/*[a-zA-Z0-9\.\:]+(?:_[a-zA-Z0-9\:\.]+)*(?:\-[\:a-zA-Z0-9\.]+)*)+\/?)$`
alpha = "^[a-zA-Z]+$"
alphanumeric = "^[a-zA-Z0-9]+$"
......
package pattern_test
import (
"testing"
"github.com/tmrts/tmplt/pkg/util/validate/pattern"
)
func TestUnixPathPattern(t *testing.T) {
tests := []struct {
String string
Valid bool
}{
{"", false},
{"/", true},
{"/root", true},
{"/tmp-dir", true},
{"/tmp-dir/new_dir", true},
{"/TMP/dir", true},
}
for _, test := range tests {
if ok := pattern.UnixPath.MatchString(test.String); ok != test.Valid {
t.Errorf("pattern.UnixPath.MatchString(%q) expected to be %v", test.String, test.Valid)
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment