func TestQuero(t *testing.T) { db, err := sql.Open("mysql", "root:@tcp(localhost:3306)/test") if err != nil { flux.FatalFailed(t, "Creating sql connection: %+s", err) } defer db.Close() prepareTable(t, db) var ws sync.WaitGroup ws.Add(1) reader := flux.FileLoader() qo := Quero(db) reader.Bind(qo, true) qo.React(func(r flux.Reactor, err error, d interface{}) { ws.Done() if err != nil { flux.FatalFailed(t, "Failed in Building sql.Statement, Error Received: %+s", err) } log.Printf("Model data: %+q", d) flux.LogPassed(t, "Successful created sql.Statement") }, true) reader.Send("./../../fixtures/models.dq") defer qo.Close() ws.Wait() dropTables(t, db) }
func TestTemplateDir(t *testing.T) { dir := NewTemplateDir(&TemplateConfig{ Dir: "./fixtures", Extension: ".tmpl", }) dirs := []string{"base"} asst, err := dir.Create("base.tmpl", dirs, nil) if err != nil { flux.FatalFailed(t, "Failed to load: %s", err.Error()) } if len(asst.Funcs) < 1 { flux.FatalFailed(t, "AssetTemplate Func map is empty") } buf := bytes.NewBuffer([]byte{}) do := &dataPack{ Name: "alex", Title: "flabber", } err = asst.Tmpl.ExecuteTemplate(buf, "base", do) if err != nil { flux.FatalFailed(t, "Unable to exec templates: %+s", err) } flux.LogPassed(t, "Loaded Template succesfully") }
func TestChunkParserCombo(t *testing.T) { var ws sync.WaitGroup ws.Add(1) fs := ChunkFileScanAdaptor() ps := ParseAdaptor(parser.DefaultInspectionFactory) fs.Bind(ps, true) fs.React(func(rs flux.Reactor, err error, data interface{}) { ws.Done() if err != nil { flux.FatalFailed(t, "Error occured string: %v", err.Error()) } if _, ok := data.(ds.Graphs); ok { flux.FatalFailed(t, "Expected type ds.Graphs: %v", data) } flux.LogPassed(t, "Completed with parser Graph from ChunckFileScanner and Parser Combo") }, true) fs.Send("./../fixtures/dataset.dq") ws.Wait() fs.Close() }
func TestMarkFriday(t *testing.T) { ws := new(sync.WaitGroup) ws.Add(1) mark := MarkFriday(MarkConfig{ SaveDir: "../fixtures/templates", Ext: ".mdr", }) mark.React((func(root flux.Reactor, err error, data interface{}) { if err != nil { flux.FatalFailed(t, "Error occured %+s", err) } if rf, ok := data.(*fs.FileWrite); ok { flux.LogPassed(t, "Markdown Rendered: %+s -> %+s", rf.Data, rf) } else { flux.FatalFailed(t, "Failure in receiving Correct Response: %+s", data) } ws.Done() }), true) mark.Send("../fixtures/markdown/base.md") ws.Wait() mark.Close() }
// TestModelPassAndFailure sets up a new map model and validates that the wrong data fails func TestModelPassAndFailure(t *testing.T) { mo := NewModels(map[string]interface{}{ "name": "", "age": 0, "date": time.Now(), }) key, err := mo.Validate(map[string]interface{}{ "name": "alex ewetumo", "age": 20, "date": time.Now(), }) if err != nil { flux.FatalFailed(t, "Validation key failed: %s : %s", key, err.Error()) } flux.LogPassed(t, "Validation passed!") key, err = mo.Validate(map[string]interface{}{ "name": "alex ewetumo", "age": 20, "date": time.Duration(300) * time.Minute, }) if err == nil { flux.FatalFailed(t, "Validation key did not failed: %s", "date") } flux.LogPassed(t, "Validation failed as expected: %s : %s", key, err.Error()) }
func TestMarkdownStream(t *testing.T) { ws := new(sync.WaitGroup) ws.Add(2) mark, err := MarkFridayStream(MarkStreamConfig{ InputDir: "../fixtures/markdown", SaveDir: "../fixtures/templates", Ext: ".html", }) if err != nil { flux.FatalFailed(t, "Failed to build list streamer", err) } mark.React((func(root flux.Reactor, err error, data interface{}) { if err != nil { flux.FatalFailed(t, "Error occured %+s", err) } ws.Done() }), true) mark.Send(true) ws.Wait() mark.Close() }
func TestMarkdown(t *testing.T) { ws := new(sync.WaitGroup) ws.Add(1) mark := BlackFriday() mark.React((func(root flux.Reactor, err error, data interface{}) { if err != nil { flux.FatalFailed(t, "Error occured %+s", err) } if rf, ok := data.(*RenderFile); ok { flux.LogPassed(t, "Markdown Rendered: %+s", rf.Data) } else { flux.FatalFailed(t, "Failure in receiving Correct Response: %+s", data) } ws.Done() }), true) mark.Send(&RenderFile{ Path: "./slug.md", Data: []byte("# Slug Passive Aggressive -> SPA"), }) ws.Wait() mark.Close() }
func TestModelFileParser(t *testing.T) { ps := NewParser(DefaultInspectionFactory) fs, err := os.Open("./../fixtures/models.dq") if err != nil { flux.FatalFailed(t, "File.Error occured: %+s", err) } g, err := ps.Scan(fs) if err != nil { flux.FatalFailed(t, "Parser.Error occured: %+s", err) } itr, err := ds.CreateGraphTransversor(ds.DFPreOrderDirective(nil, nil)) if err != nil { t.Fatal(err) } itr.Use(g.Get("user")) for itr.Next() == nil { node := itr.Node().(*ParseNode) t.Logf("Node-Attr: %s %+s", node.Name(), node.Attr) t.Logf("Node-Record: %s %+s", node.Name(), node.Records.Keys()) t.Logf("Node-Rules: %s %+s", node.Name(), node.Rules) } flux.LogPassed(t, "Successfully passed model query file properly") }
func TestGoodFileParser(t *testing.T) { ps := NewParser(DefaultInspectionFactory) fs, err := os.Open("./../fixtures/dataset.dq") if err != nil { flux.FatalFailed(t, "File.Error occured: %+s", err) } g, err := ps.Scan(fs) if err != nil { flux.FatalFailed(t, "Parser.Error: ", err) } flux.LogPassed(t, "Generated query graph successfully: %t", g != nil) itr, err := ds.CreateGraphTransversor(ds.DFPreOrderDirective(nil, nil)) if err != nil { flux.FatalFailed(t, "Transverso.Error occured: %+s", err) } itr.Use(g.Get("user")) for itr.Next() == nil { node := itr.Node().(*ParseNode) t.Logf("Node-Attr: %s %+s", node.Name(), node.Attr) t.Logf("Node-Record: %s %+s", node.Name(), node.Records.Keys()) t.Logf("Node-Rules: %s %+s", node.Name(), node.Rules) } flux.LogPassed(t, "Graph Iterator works properly") }
func TestAssetMap(t *testing.T) { tree, err := AssetTree("./", []string{".go"}, nil) if err != nil { flux.FatalFailed(t, "Unable to create asset map: %s", err.Error()) } if len(tree) <= 0 { flux.FatalFailed(t, "expected one key atleast: %s") } flux.LogPassed(t, "Succesfully created asset map tree") }
func TestVirtualDir(t *testing.T) { if _, err := RootDirectory.GetDir("/"); err != nil { flux.FatalFailed(t, "Unable to located asset dir in dirCollection") } if _, err := RootDirectory.GetDir("/fixtures"); err != nil { flux.FatalFailed(t, "Unable to located /fixtures dir in dirCollection") } to, err := RootDirectory.GetDir("/fixtures/base") if err != nil { flux.FatalFailed(t, "Unable to located fixtures/base directory: %s", err) } al, err := to.GetFile("basic.tmpl") if err != nil { flux.FatalFailed(t, "Unable to located /fixtures/base/basic.tmpl file: %s", err) } if data, err := al.Data(); err != nil { flux.FatalFailed(t, "failed to load /fixtures/base/basic.tmpl contents: %s", err) } else if len(data) != 364 { flux.FatalFailed(t, "incorrect assets/tests/lock.md content, expected length %d got %d", 364, len(data)) } if _, err := RootDirectory.GetFile("/fixtures/base/basic.tmpl"); err != nil { flux.FatalFailed(t, "Unable to get File /fixtures/base/basic.tmpl file: %s", err) } tom, _ := RootDirectory.GetDir("/fixtures") if _, err := tom.GetFile("/base/basic.tmpl"); err != nil { flux.FatalFailed(t, "Unable to get File /base/basic.tmpl file: %s", err) } }
func expect(t *testing.T, v, m interface{}) { if v != m { flux.FatalFailed(t, "Value %+v and %+v are not a match", v, m) return } flux.LogPassed(t, "Value %+v and %+v are a match", v, m) }
func TestChunkScannerWithSinglePack(t *testing.T) { var ws sync.WaitGroup ws.Add(1) fs := ChunkFileScanAdaptor() fs.React(func(rs flux.Reactor, err error, data interface{}) { ws.Done() if err != nil { flux.FatalFailed(t, "Error occured string: %v", err.Error()) } if _, ok := data.(string); !ok { t.Fatalf("Expected type string: %v", data) } flux.LogPassed(t, "Completed with scanning on SinglePack file") }, true) fs.Send("./../fixtures/dataset.dq") ws.Wait() fs.Close() }
func TestBadFileParser(t *testing.T) { ps := NewParser(DefaultInspectionFactory) fs, err := os.Open("./../fixtures/config.dq") if err != nil { flux.FatalFailed(t, "File.Error occured: %+s", err) } _, err = ps.Scan(fs) if err == nil { flux.FatalFailed(t, "Parser is supposed to error out about bad file") } flux.LogPassed(t, "Bad file failed properly: %+s", err) }
func dropTables(t *testing.T, db *sql.DB) { _, err := db.Exec("DROP TABLE IF EXISTS test.users") if err != nil { flux.FatalFailed(t, "Failed sql drop test.users table: %+s", err) } flux.LogPassed(t, "Successfully exectuable DROP table to sql db: %+s", "test.users") _, err = db.Exec("DROP TABLE IF EXISTS test.photos") if err != nil { flux.FatalFailed(t, "Failed sql drop test.photos table: %+s", err) } flux.LogPassed(t, "Successfully exectuable DROP table to sql db: %+s", "test.photos") }
func TestModels(t *testing.T) { ps := NewParser(DefaultInspectionFactory) fs, err := os.Open("./../fixtures/models.dq") if err != nil { flux.FatalFailed(t, "File.Error occured: %+s", err) } g, err := ps.Scan(fs) if err != nil { flux.FatalFailed(t, "Parser is supposed to not error out about model file: %+s", err) } flux.LogPassed(t, "Generated query graph successfully: %t", g != nil) }
func TestChunkScanning(t *testing.T) { fs, err := os.Open("./../fixtures/config.dq") if err != nil { flux.FatalFailed(t, "File.Error occured: %+s", err) } err = ScanChunks(NewScanner(fs), func(cu string) { // t.Logf("Chunks: %s", cu) }) if err != nil { flux.FatalFailed(t, "ChunkScanning.Error occured: %+s", err) } flux.LogPassed(t, "ChunkScanning finished successfully!") }
func TestDebugVirtualFile(t *testing.T) { vf := NewVFile("./", "assets/vim.md", "vim.md", 5, true, true, func(v *VFile) ([]byte, error) { return readFile(v) }) if vf.Size() > 5 { flux.FatalFailed(t, "Incorrect size value,expected %d got %d", 5, vf.Size()) } if data, err := vf.Data(); err != nil { flux.FatalFailed(t, "Error occured retrieving content: %s", err) } else { if string(data) != "#Vim\n" { flux.FatalFailed(t, "Error in file content expected %s got %s", "#Vim", data) } } flux.LogPassed(t, "Successfully read contents of virtual file") }
func TestCompressedVirtualFile(t *testing.T) { vf := NewVFile("./", "assets/bucklock.txt", "buklock.txt", 30, true, true, func(v *VFile) ([]byte, error) { return readData(v, []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x52\x0e\xcb\xcc\xe5\x02\x04\x00\x00\xff\xff\xec\xfe\xa5\xd9\x05\x00\x00\x00")) }) if vf.Size() < 30 { flux.FatalFailed(t, "Incorrect size value,expected %d got %d", 30, vf.Size()) } if data, err := vf.Data(); err != nil { flux.FatalFailed(t, "Error occured retrieving content: %s", err) } else { if string(data) != "#Vim\n" { flux.FatalFailed(t, "Error in file content expected %s got %s", "shop", data) } } flux.LogPassed(t, "Successfully read contents of virtual file") }
func TestPlainVirtualFile(t *testing.T) { vf := NewVFile("./", "assets/bucklock.txt", "buklock.txt", 5, true, true, func(v *VFile) ([]byte, error) { return []byte("shop"), nil }) if vf.Size() > 5 { flux.FatalFailed(t, "Incorrect size value,expected %d got %d", 5, vf.Size()) } if data, err := vf.Data(); err != nil { flux.FatalFailed(t, "Error occured retrieving content: %s", err) } else { if string(data) != "shop" { flux.FatalFailed(t, "Error in file content expected %s got %s", "shop", data) } } flux.LogPassed(t, "Successfully read contents of virtual file") }
func TestCollector(t *testing.T) { c := NewCollector() c.Set("name", "bond") if !c.HasMatch("name", "bond") { flux.FatalFailed(t, "unable to match added key %s and value %s", "name", "bond") } flux.LogPassed(t, "correctly matched added key %s and value %s", "name", "bond") }
func TestAssetListings(t *testing.T) { tree, err := Assets("./", func(dir string, info os.FileInfo) bool { if strings.Contains(dir, ".git") { return false } return true }, func(dir string, info os.FileInfo) string { return filepath.Join("static/", dir) }) if err != nil { flux.FatalFailed(t, "Unable to create asset map: %s", err.Error()) } if tree.Size() <= 0 { flux.FatalFailed(t, "expected one key atleast: %s") } flux.LogPassed(t, "Succesfully created asset map") }
// TestModelStructAttr if we can generates a map of attributes/fields of a inited struct func TestModelStructAttr(t *testing.T) { b := &zum{1} bo, err := NewModelStruct(b, "model") if err != nil { flux.FatalFailed(t, "Unable to create modelAttr for %s", err.Error()) } flux.LogPassed(t, "Successfully generated modelstruct with tag: %s %s", b, bo) }
//TestModelAttr creates a basic test case of a modelattr func TestModelAttr(t *testing.T) { na := NewModelAttr("name", "name", &zum{1}) dt := &zum{3} if err := na.Validate(dt); err != nil { flux.FatalFailed(t, "Validation failed: %s", err.Error()) } flux.LogPassed(t, "Validation Passed: %s", dt) }
func TestChunkScannerWithLargePack(t *testing.T) { var ws sync.WaitGroup ws.Add(2) fs := ChunkScanAdaptor() fs.React(func(rs flux.Reactor, err error, data interface{}) { ws.Done() if err != nil { flux.FatalFailed(t, "Error occured string: %v", err.Error()) } if _, ok := data.(string); !ok { t.Fatalf("Expected type string: %v", data) } flux.LogPassed(t, "Completed with scanning with ChunkScanner") }, true) fs.Send(` { user(){ id(is: 4000), name, state, address, skills(range: 30..100), age(lt:30, gte:40), age(is: 20), day(isnot: wednesday), photos(width: 400){ day, fax, }, }, admin(id:4,rack:10){ name, email, group, levels, permissions(){ code, active, }, }, } `) ws.Wait() fs.Close() }
func TestTodoModel(t *testing.T) { db := makeMockDb() if _, err := db.FindID(1); err != nil { flux.FatalFailed(t, "Todo id: %d should exists", 1) } flux.LogPassed(t, "Todo id: %d was located succesfully", 1) if err := db.Destroy(2); err != nil { flux.FatalFailed(t, "Todo id: %d was not destroyed", 2) } flux.LogPassed(t, "Todo id: %d was destroyed succesfully", 2) if todos, _ := db.FindAll(); len(todos) > 3 { flux.FatalFailed(t, "Todo length is not correct, epxected 2 got %d", len(todos)) } flux.LogPassed(t, "Todo length: %d is correct", 2) }
func TestBuildConfig(t *testing.T) { bo := NewBuildConfig() if err := bo.Load("./fixtures/builder.yaml"); err != nil { flux.FatalFailed(t, "Unable to load config: %s", err) } if bo.Addr != ":6000" { flux.FatalFailed(t, "Wrong addr value %s expected ':6000'", bo.Addr) } if bo.Static.Dir != "./static" { flux.FatalFailed(t, "Wrong static.dir value %s expected ':6000'", bo.Static.Dir) } if bo.Package != "bitbucket.org/flow/builder" { flux.FatalFailed(t, "Wrong package value %s expected 'bitbucket.org/flow/builder'", bo.Package) } if bo.ClientPackage != "bitbucket.org/flow/builder/client" { flux.FatalFailed(t, "Wrong clientpacket value %s expected 'bitbucket.org/flow/builder/client'", bo.ClientPackage) } if bo.Name != "builder" { flux.FatalFailed(t, "Wrong name value %s expected 'builder'", bo.Addr) } }
func TestListings(t *testing.T) { tree, err := DirListings("./", func(dir string, info os.FileInfo) bool { if strings.Contains(dir, ".git") { return false } return true }, func(dir string, info os.FileInfo) string { return filepath.Join("static/", dir) }) if err != nil { flux.FatalFailed(t, "Unable to create asset map: %s", err.Error()) } if tree.Listings.Size() <= 0 || tree.Listings.Size() > 11 { flux.FatalFailed(t, "expected size to be below 11 but got %d", tree.Listings.Size()) } flux.LogPassed(t, "Succesfully created directory listings") err = os.Mkdir("./fixtures/bucker", 0700) if err != nil { flux.FatalFailed(t, "Unable to create dir: %s", err.Error()) } defer os.Remove("./fixtures/bucker") err = tree.Reload() if err != nil { flux.FatalFailed(t, "Unable to reload listings: %s", err.Error()) } if tree.Listings.Size() <= 0 || tree.Listings.Size() < 10 { flux.FatalFailed(t, "expected size to be above 6 but got %d", tree.Listings.Size()) } flux.LogPassed(t, "Succesfully reloaded directory listings") }
// TestStructModels generates a modelattr and Model corresponding for validating values func TestStructModels(t *testing.T) { b := &zum{1} bo, err := NewStructModels(b, "model") if err != nil { flux.FatalFailed(t, "Unable to create modelAttr for %s", err.Error()) } flux.LogPassed(t, "Successfully generated modelstruct with tag: %s %s", b, bo) key, err := bo.Validate(map[string]interface{}{ "d_o": 20, }) if err != nil { flux.FatalFailed(t, "Validation key failed: %s : %s", key, err.Error()) } flux.LogPassed(t, "Validation passed!") }
func TestBasicAssets(t *testing.T) { tmpl, err := LoadTemplates("./fixtures/base", ".tmpl", nil, []template.FuncMap{DefaultTemplateFunctions}) if err != nil { flux.FatalFailed(t, "Unable to load templates: %+s", err) } buf := bytes.NewBuffer([]byte{}) do := &dataPack{ Name: "alex", Title: "world war - z", } err = tmpl.ExecuteTemplate(buf, "base", do) if err != nil { flux.FatalFailed(t, "Unable to exec templates: %+s", err) } flux.LogPassed(t, "Loaded Template succesfully") }