예제 #1
0
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")
}
예제 #2
0
// 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())
}
예제 #3
0
파일: js_test.go 프로젝트: influx6/reactors
func TestJSDirBundler(t *testing.T) {
	js, jsmap, err := session.BuildDir("./js", "github.com/influx6/reactors/builders/base", "base")

	if err != nil {
		flux.FatalFailed(t, "Error build gopherjs dir: %s", err)
	}

	if jsmap.Len() > 50 {
		flux.LogPassed(t, "Successfully built js.map package: %d", jsmap.Len())
	}

	if js.Len() > 50 {
		flux.LogPassed(t, "Successfully built js package: %d", js.Len())
	}
}
예제 #4
0
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()
}
예제 #5
0
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")
}
예제 #6
0
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()
}
예제 #7
0
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()
}
예제 #8
0
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")
}
예제 #9
0
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)
}
예제 #10
0
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()
}
예제 #11
0
파일: utils.go 프로젝트: influx6/relay
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)
}
예제 #12
0
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")
}
예제 #13
0
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")
}
예제 #14
0
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()
}
예제 #15
0
파일: model_test.go 프로젝트: influx6/todo
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)
}
예제 #16
0
//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)
}
예제 #17
0
// 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)
}
예제 #18
0
func prepareTable(t *testing.T, db *sql.DB) {
	_, err := db.Exec("CREATE TABLE IF NOT EXISTS test.users(id integer not null AUTO_INCREMENT primary key,name varchar(50),age integer,street varchar(50),stamp date)")

	if err != nil {
		flux.FatalFailed(t, "Creating sql test.users table: %+s", err)
	}

	flux.LogPassed(t, "Successfully exectuable create table to sql db: %+s", "test.users")

	_, err = db.Exec("INSERT INTO test.users(name,age,street) VALUES('alex',21,'lagos')")

	if err != nil {
		flux.FatalFailed(t, "Running sql insert into test.users table: %+s", err)
	}
	_, err = db.Exec("INSERT INTO test.users(name,age,street) VALUES('josh',32,'new york')")

	if err != nil {
		flux.FatalFailed(t, "Running sql insert into test.users table: %+s", err)
	}

	_, err = db.Exec("CREATE TABLE IF NOT EXISTS test.photos(url varchar(50),user_id integer,id int not null primary key AUTO_INCREMENT)")

	if err != nil {
		flux.FatalFailed(t, "Creating sql test.photos table: %+s", err)
	}

	_, err = db.Exec("INSERT INTO test.photos(url,user_id) VALUES('./images/sock.jpg',2)")

	if err != nil {
		flux.FatalFailed(t, "Running sql insert into test.photos table: %+s", err)
	}

	_, err = db.Exec("INSERT INTO test.photos(url,user_id) VALUES('./images/winnie.jpg',1)")

	if err != nil {
		flux.FatalFailed(t, "Running sql insert into test.photos table: %+s", err)
	}

	flux.LogPassed(t, "Successfully exectuable create table to sql db: %+s", "test.photos")
}
예제 #19
0
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")
}
예제 #20
0
// 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!")
}
예제 #21
0
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")
}
예제 #22
0
// TestLists checks if we can also assign and validates lists of values
func TestLists(t *testing.T) {
	mo := NewModels(map[string]interface{}{
		"name": []string{},
	})

	key, err := mo.Validate(map[string]interface{}{
		"name": []string{"alex ewetumo"},
	})

	if err != nil {
		flux.FatalFailed(t, "Validation key failed: %s : %s", key, err.Error())
	}

	flux.LogPassed(t, "Validation passed!")
}
예제 #23
0
// TestInterLists tests wether we can assign a []string to an array type
func TestInterLists(t *testing.T) {
	mo := NewModels(map[string]interface{}{
		"name": []interface{}{},
	})

	key, err := mo.Validate(map[string]interface{}{
		"name": []string{"alex ewetumo"},
	})

	if err != nil {
		flux.LogPassed(t, "Validation passed! We cant assign %s to %s!", key, err.Error())
		return
	}

	flux.FatalFailed(t, "Validation key did not fail!")
}
예제 #24
0
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!")
}
예제 #25
0
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)
}
예제 #26
0
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)
}
예제 #27
0
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")
}
예제 #28
0
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")
}
예제 #29
0
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")
}
예제 #30
0
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")
}