當前位置: 首頁>>代碼示例>>Golang>>正文


Golang testfiles.Locate函數代碼示例

本文整理匯總了Golang中github.com/youtube/vitess/go/testfiles.Locate函數的典型用法代碼示例。如果您正苦於以下問題:Golang Locate函數的具體用法?Golang Locate怎麽用?Golang Locate使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Locate函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestStream

func TestStream(t *testing.T) {
	env := setup("cat $3", 0)
	defer cleanup(env)

	var transactions []transaction

	out, err := ioutil.ReadFile(testfiles.Locate("mysqlctl_test/expected.json"))
	if err != nil {
		t.Fatal(err)
	}
	err = json.Unmarshal(out, &transactions)
	if err != nil {
		t.Fatal(err)
	}
	svm := &sync2.ServiceManager{}

	curTransaction := 0
	sendTx := func(tx *proto.BinlogTransaction) error {
		for i, stmt := range tx.Statements {
			if transactions[curTransaction].Statements[i].Sql != string(stmt.Sql) {
				t.Errorf("want %s, got %s", transactions[curTransaction].Statements[i].Sql, stmt.Sql)
			}
			if transactions[curTransaction].Statements[i].Category != stmt.Category {
				t.Errorf("want %d, got %d", transactions[curTransaction].Statements[i].Category, stmt.Category)
			}
		}
		if transactions[curTransaction].GTIDField != tx.GTIDField {
			t.Errorf("want %#v, got %#v", transactions[curTransaction].GTIDField, tx.GTIDField)
		}
		curTransaction++
		if curTransaction == len(transactions) {
			// Launch as goroutine to prevent deadlock.
			go svm.Stop()
		}
		// Uncomment the following lines to produce a different set of
		// expected outputs. You'll need to massage the file a bit afterwards.
		/*
			fmt.Printf("{\n\"Statements\": [\n")
			for i := 0; i < len(tx.Statements); i++ {
				fmt.Printf(`{"Category": %d, "Sql": %#v}`, tx.Statements[i].Category, string(tx.Statements[i].Sql))
				if i == len(tx.Statements)-1 {
					fmt.Printf("\n")
				} else {
					fmt.Printf(",\n")
				}
			}
			fmt.Printf("],\n")
			fmt.Printf("\"GTID\": \"%s\"\n},\n", tx.GTID)
		*/
		return nil
	}
	bls := newTestBinlogFileStreamer("db", testfiles.Locate("mysqlctl_test/vt-0000041983-bin"), myproto.ReplicationPosition{}, sendTx)
	svm.Go(func(ctx *sync2.ServiceContext) error {
		return bls.streamFilePos(ctx, "vt-0000041983-bin.000001", 0)
	})
	err = svm.Join()
	if err != nil {
		t.Error(err)
	}
}
開發者ID:chinna1986,項目名稱:vitess,代碼行數:60,代碼來源:binlog_file_streamer_test.go

示例2: TestStream

func TestStream(t *testing.T) {
	env := setup("cat $3", 0)
	defer cleanup(env)

	var transactions []transaction

	out, err := ioutil.ReadFile(testfiles.Locate("mysqlctl_test/expected.json"))
	if err != nil {
		t.Fatal(err)
	}
	err = json.Unmarshal(out, &transactions)
	if err != nil {
		t.Fatal(err)
	}

	curTransaction := 0
	bls := NewBinlogStreamer("db", testfiles.Locate("mysqlctl_test/vt-0000041983-bin"))
	err = bls.Stream("vt-0000041983-bin.000001", 0, func(tx *proto.BinlogTransaction) error {
		for i, stmt := range tx.Statements {
			if transactions[curTransaction].Statements[i].Sql != string(stmt.Sql) {
				t.Errorf("want %s, got %s", transactions[curTransaction].Statements[i].Sql, stmt.Sql)
			}
			if transactions[curTransaction].Statements[i].Category != stmt.Category {
				t.Errorf("want %d, got %d", transactions[curTransaction].Statements[i].Category, stmt.Category)
			}
		}
		if transactions[curTransaction].GroupId != tx.GroupId {
			t.Errorf("want %#v, got %#v", transactions[curTransaction].GroupId, tx.GroupId)
		}
		curTransaction++
		if curTransaction == len(transactions) {
			// Launch as goroutine to prevent deadlock.
			go bls.Stop()
		}
		// Uncomment the following lines to produce a different set of
		// expected outputs. You'll need to massage the file a bit afterwards.
		/*
			fmt.Printf("{\n\"Statements\": [\n")
			for i := 0; i < len(tx.Statements); i++ {
				fmt.Printf(`{"Category": %d, "Sql": %#v}`, tx.Statements[i].Category, string(tx.Statements[i].Sql))
				if i == len(tx.Statements)-1 {
					fmt.Printf("\n")
				} else {
					fmt.Printf(",\n")
				}
			}
			fmt.Printf("],\n")
			fmt.Printf("\"GroupId\": \"%s\"\n},\n", tx.GroupId)
		*/
		return nil
	})
	if err != nil {
		t.Error(err)
	}
}
開發者ID:kingpro,項目名稱:vitess,代碼行數:55,代碼來源:binlog_streamer_test.go

示例3: TestFromFile

func TestFromFile(t *testing.T) {
	conn := NewConnFromFile(testfiles.Locate("fakezk_test_config.json"))

	keyspaces, _, err := conn.Children("/zk/testing/vt/ns")
	if err != nil {
		t.Errorf("conn.Children: %v", err)
	}
	if len(keyspaces) != 1 || keyspaces[0] != "test_keyspace" {
		t.Errorf("conn.Children returned bad value: %v", keyspaces)
	}

	data, _, err := conn.Get("/zk/testing/vt/ns/test_keyspace")
	if err != nil {
		t.Errorf("conn.Get(/zk/testing/vt/ns/test_keyspace): %v", err)
	}
	if !strings.Contains(string(data), "ShardReferences") {
		t.Errorf("conn.Get(/zk/testing/vt/ns/test_keyspace) returned bad value: %v", data)
	}

	data, _, err = conn.Get("/zk/testing/vt/ns/test_keyspace/0/master")
	if err != nil {
		t.Errorf("conn.Get(/zk/testing/vt/ns/test_keyspace/0/master): %v", err)
	}
	if !strings.Contains(string(data), "NamedPortMap") {
		t.Errorf("conn.Get(/zk/testing/vt/ns/test_keyspace/0/master) returned bad value: %v", data)
	}
}
開發者ID:erzel,項目名稱:vitess,代碼行數:27,代碼來源:fakezk_test.go

示例4: iterateFile

func iterateFile(name string) (testCaseIterator chan testCase) {
	name = testfiles.Locate("sqlparser_test/" + name)
	fd, err := os.OpenFile(name, os.O_RDONLY, 0)
	if err != nil {
		panic(fmt.Sprintf("Could not open file %s", name))
	}
	testCaseIterator = make(chan testCase)
	go func() {
		defer close(testCaseIterator)

		r := bufio.NewReader(fd)
		lineno := 0
		for {
			line, err := r.ReadString('\n')
			lines := strings.Split(strings.TrimRight(line, "\n"), "#")
			lineno++
			if err != nil {
				if err != io.EOF {
					panic(fmt.Sprintf("Error reading file %s: %s", name, err.Error()))
				}
				break
			}
			input := lines[0]
			output := ""
			if len(lines) > 1 {
				output = lines[1]
			}
			if input == "" {
				continue
			}
			testCaseIterator <- testCase{lineno, input, output}
		}
	}()
	return testCaseIterator
}
開發者ID:rjammala,項目名稱:vitess,代碼行數:35,代碼來源:parse_test.go

示例5: newSpecialReader

func newSpecialReader(t *testing.T, filename string) *specialReader {
	filename = testfiles.Locate(filename)
	b, err := ioutil.ReadFile(filename)
	if err != nil {
		t.Fatalf("Cannot read file %v: %v", filename, err)
	}
	return &specialReader{t, b, 0}
}
開發者ID:kingpro,項目名稱:vitess,代碼行數:8,代碼來源:eof_read_test.go

示例6: TestInitWithInvalidConfigFile

func TestInitWithInvalidConfigFile(t *testing.T) {
	setUpTableACL(&simpleacl.Factory{})
	defer func() {
		err := recover()
		if err == nil {
			t.Fatalf("init should fail for an invalid config file")
		}
	}()
	Init(testfiles.Locate("tableacl/invalid_tableacl_config.json"))
}
開發者ID:pranjal5215,項目名稱:vitess,代碼行數:10,代碼來源:tableacl_test.go

示例7: iterateJSONFile

func iterateJSONFile(name string) (testCaseIterator chan testCase) {
	name = testfiles.Locate("sqlparser_test/" + name)
	fd, err := os.OpenFile(name, os.O_RDONLY, 0)
	if err != nil {
		panic(fmt.Sprintf("Could not open file %s", name))
	}
	testCaseIterator = make(chan testCase)
	go func() {
		defer close(testCaseIterator)

		r := bufio.NewReader(fd)
		lineno := 0
		for {
			binput, _, err := r.ReadLine()
			input := string(binput)
			lineno++
			if err != nil {
				if err != io.EOF {
					panic(fmt.Sprintf("Error reading file %s: %s", name, err.Error()))
				}
				break
			}
			if input == "" || input[0] == '#' {
				//fmt.Printf("%s\n", input)
				continue
			}
			var output []byte
			for {
				l, err := r.ReadBytes('\n')
				lineno++
				if err != nil {
					panic(fmt.Sprintf("Error reading file %s: %s", name, err.Error()))
				}
				output = append(output, l...)
				if l[0] == '}' {
					output = output[:len(output)-1]
					b := bytes.NewBuffer(make([]byte, 0, 64))
					if err := json.Compact(b, output); err == nil {
						output = b.Bytes()
					}
					break
				}
				if l[0] == '"' {
					output = output[1 : len(output)-2]
					break
				}
			}
			testCaseIterator <- testCase{lineno, input, string(output)}
		}
	}()
	return testCaseIterator
}
開發者ID:rjammala,項目名稱:vitess,代碼行數:52,代碼來源:parse_test.go

示例8: TestRotation

// TestRoration should not hang
func TestRotation(t *testing.T) {
	env := setup("cat $3", 0)
	defer cleanup(env)

	bls := NewBinlogStreamer("db", testfiles.Locate("mysqlctl_test/vt-0000041983-bin"))
	err := bls.Stream("vt-0000041983-bin.000004", 2682, func(tx *proto.BinlogTransaction) error {
		bls.Stop()
		return nil
	})
	if err != nil {
		t.Error(err)
	}
}
開發者ID:nimishzynga,項目名稱:vitess,代碼行數:14,代碼來源:binlog_streamer_test.go

示例9: TestSimple

func TestSimple(t *testing.T) {
	input := testfiles.Locate("bson_test/simple_type.go")
	b, err := ioutil.ReadFile(input)
	if err != nil {
		log.Fatal(err)
	}
	out, err := generateCode(string(b), "MyType")
	if err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		return
	}
	fmt.Printf("%s\n", out)
}
開發者ID:nosix-me,項目名稱:vitess,代碼行數:13,代碼來源:bsongen_test.go

示例10: TestRotation

// TestRoration should not hang
func TestRotation(t *testing.T) {
	env := setup("cat $3", 0)
	defer cleanup(env)

	bls := newTestBinlogFileStreamer("db", testfiles.Locate("mysqlctl_test/vt-0000041983-bin"))
	err := bls.streamFilePos("vt-0000041983-bin.000004", 2682, func(tx *proto.BinlogTransaction) error {
		// Launch as goroutine to prevent deadlock.
		go bls.Stop()
		return nil
	})
	if err != nil {
		t.Error(err)
	}
}
開發者ID:ninqing,項目名稱:vitess,代碼行數:15,代碼來源:binlog_file_streamer_test.go

示例11: TestRotation

// TestRoration should not hang
func TestRotation(t *testing.T) {
	env := setup("cat $3", 0)
	defer cleanup(env)

	svm := &sync2.ServiceManager{}
	bls := newTestBinlogFileStreamer("db", testfiles.Locate("mysqlctl_test/vt-0000041983-bin"), myproto.ReplicationPosition{}, func(tx *proto.BinlogTransaction) error {
		// Launch as goroutine to prevent deadlock.
		go svm.Stop()
		return nil
	})
	svm.Go(func(ctx *sync2.ServiceContext) error {
		return bls.streamFilePos(ctx, "vt-0000041983-bin.000004", 2682)
	})
	err := svm.Join()
	if err != nil {
		t.Error(err)
	}
}
開發者ID:chinna1986,項目名稱:vitess,代碼行數:19,代碼來源:binlog_file_streamer_test.go

示例12: main

func main() {
	input := testfiles.Locate("bson_test/simple_type.go")
	b, err := ioutil.ReadFile(input)
	if err != nil {
		log.Fatal(err)
	}
	src := string(b)

	fset := token.NewFileSet()
	f, err := parser.ParseFile(fset, "", src, 0)
	if err != nil {
		log.Fatal(err)
	}
	//ast.Print(fset, f)
	typeInfo, err := FindType(f, "MyType")
	if err != nil {
		fmt.Println(err)
		return
	}
	generator.ExecuteTemplate(os.Stdout, "Body", typeInfo)
}
開發者ID:rn2dy,項目名稱:vitess,代碼行數:21,代碼來源:bsongen.go

示例13: BenchmarkFileStreamerParseEvents

func BenchmarkFileStreamerParseEvents(b *testing.B) {
	filename := testfiles.Locate("binlog_test/vt-0000062347-bin.000001")
	var svm sync2.ServiceManager
	count := 0
	bls := newTestBinlogFileStreamer("vt_test_database", "", myproto.ReplicationPosition{}, func(tx *proto.BinlogTransaction) error {
		count++
		return nil
	})

	for i := 0; i < b.N; i++ {
		if err := bls.file.Init(filename, 0); err != nil {
			b.Fatalf("%v", err)
		}
		svm.Go(bls.run)
		if err := svm.Join(); err != nil {
			b.Errorf("%v", err)
		}
		bls.file.Close()
	}

	b.Logf("%d transactions processed", count)
}
開發者ID:chinna1986,項目名稱:vitess,代碼行數:22,代碼來源:benchmark_test.go

示例14: BenchmarkConnStreamerParseEvents

func BenchmarkConnStreamerParseEvents(b *testing.B) {
	filename := testfiles.Locate("binlog_test/vt-0000062347-bin.000001")
	var svm sync2.ServiceManager
	count := 0
	bls := &binlogConnStreamer{dbname: "vt_test_database", sendTransaction: func(tx *proto.BinlogTransaction) error {
		count++
		return nil
	}}

	for i := 0; i < b.N; i++ {
		events := readEvents(b, filename)
		svm.Go(func(svc *sync2.ServiceContext) error {
			_, err := bls.parseEvents(svc, events)
			return err
		})
		if err := svm.Join(); err != ServerEOF {
			b.Errorf("%v", err)
		}
	}

	b.Logf("%d transactions processed", count)
}
開發者ID:chinna1986,項目名稱:vitess,代碼行數:22,代碼來源:benchmark_test.go

示例15: readLines

func readLines(t *testing.T, name string) []string {
	file, err := os.Open(testfiles.Locate(name))
	if err != nil {
		t.Fatalf("Cannot open %v: %v", name, err)
	}
	r := NewCSVReader(file, ',')

	lines := make([]string, 0)

	for {
		line, err := r.ReadRecord()
		if err == io.EOF {
			break
		}
		if err != nil {
			t.Fatalf("Unexpected error: %v", err)
		}
		lines = append(lines, string(line))
	}

	return lines
}
開發者ID:chinna1986,項目名稱:vitess,代碼行數:22,代碼來源:csv_reader_test.go


注:本文中的github.com/youtube/vitess/go/testfiles.Locate函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。