当前位置: 首页>>代码示例>>Golang>>正文


Golang PRNG.NextFileName方法代码示例

本文整理汇总了Golang中github.com/jddixon/rnglib_go.PRNG.NextFileName方法的典型用法代码示例。如果您正苦于以下问题:Golang PRNG.NextFileName方法的具体用法?Golang PRNG.NextFileName怎么用?Golang PRNG.NextFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/jddixon/rnglib_go.PRNG的用法示例。


在下文中一共展示了PRNG.NextFileName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: doTestMDParser

func (s *XLSuite) doTestMDParser(c *C, rng *xr.PRNG, whichSHA int) {

	var tHash []byte
	switch whichSHA {
	case xu.USING_SHA1:
		tHash = make([]byte, xu.SHA1_BIN_LEN)
	case xu.USING_SHA2:
		tHash = make([]byte, xu.SHA2_BIN_LEN)
	case xu.USING_SHA3:
		tHash = make([]byte, xu.SHA3_BIN_LEN)
		// DEFAULT = ERROR
	}
	rng.NextBytes(tHash)               // not really a hash, of course
	sHash := hex.EncodeToString(tHash) // string form of tHash

	withoutSlash := rng.NextFileName(8)
	dirName := withoutSlash + "/"

	length := rng.Intn(4)
	var rSpaces string
	for i := 0; i < length; i++ {
		rSpaces += " " // on the right
	}

	// TEST FIRST LINE PARSER -----------------------------
	line := sHash + " " + dirName + rSpaces

	treeHash2, dirName2, err := ParseMerkleDocFirstLine(line)
	c.Assert(err, IsNil)
	c.Assert(bytes.Equal(treeHash2, tHash), Equals, true)
	// we retain the terminating slash in MerkleDoc first lines
	c.Assert(dirName2, Equals, dirName)
}
开发者ID:jddixon,项目名称:xlUtil_go,代码行数:33,代码来源:merkle_doc_test.go

示例2: makeHost

// Return an initialized and tested host, with a NodeID, ckPriv,
// and skPriv.  OpenAcc() is not called and so any acceptors are not open.
func (s *XLSuite) makeHost(c *C, rng *xr.PRNG) *Node {
	// XXX names may not be unique
	name := rng.NextFileName(6)
	for {
		first := string(name[0])
		if !strings.Contains(first, "0123456789") &&
			!strings.Contains(name, "-") {
			break
		}
		name = rng.NextFileName(6)
	}
	id, err := makeNodeID(rng)
	c.Assert(err, Equals, nil)
	c.Assert(id, Not(IsNil))

	lfs := "tmp/" + hex.EncodeToString(id.Value())
	n, err := NewNew(name, id, lfs)
	c.Assert(err, IsNil)
	c.Assert(n, Not(IsNil))
	c.Assert(name, Equals, n.GetName())
	actualID := n.GetNodeID()
	c.Assert(true, Equals, id.Equal(actualID))
	s.doKeyTests(c, n, rng)
	c.Assert(0, Equals, (*n).SizePeers())
	c.Assert(0, Equals, (*n).SizeOverlays())
	c.Assert(0, Equals, n.SizeConnections())
	c.Assert(lfs, Equals, n.GetLFS())
	return n
}
开发者ID:jddixon,项目名称:xlNode_go,代码行数:31,代码来源:node_test.go

示例3: doTestSimpleConstructor

func doTestSimpleConstructor(c *C, rng *xr.PRNG, usingSHA1 bool) {

	var sha hash.Hash
	if usingSHA1 {
		sha = sha1.New()
	} else {
		sha = sha256.New()
	}

	name := rng.NextFileName(8)
	n := rng.SomeBytes(8)
	sha.Write(n)
	hash0 := sha.Sum(nil)

	leaf0, err := NewNLHLeaf(name, hash0)
	c.Assert(err, IsNil)
	c.Assert(name, Equals, leaf0.Name())
	c.Assert(hash0, Equals, leaf0.BinHash())

	name2 := name
	for name2 == name {
		name2 = rng.NextFileName(8)
	}
	n = rng.SomeBytes(8)
	sha.Write(n)
	hash1 := sha.Sum(nil)
	leaf1, err := NewNLHLeaf(name2, hash1)
	c.Assert(err, IsNil)
	c.Assert(name2, Equals, leaf1.Name())
	c.Assert(hash1, Equals, leaf1.BinHash())

	c.Assert(leaf0, Equals, leaf0)
	c.Assert(leaf1, Equals, leaf1)
	c.Assert(leaf0.Equal(leaf1), Equals, false)
}
开发者ID:jddixon,项目名称:xlUtil_go,代码行数:35,代码来源:nlhLeaf_test.go

示例4: makeHostAndKeys

func (s *XLSuite) makeHostAndKeys(c *C, rng *xr.PRNG) (
	n *xn.Node, ckPriv, skPriv *rsa.PrivateKey) {

	// XXX names may not be unique
	name := rng.NextFileName(6)
	for {
		first := string(name[0])
		if !strings.Contains(first, "0123456789") &&
			!strings.Contains(name, "-") {
			break
		}
		name = rng.NextFileName(6)
	}
	id := s.makeANodeID(c, rng)
	lfs := "tmp/" + hex.EncodeToString(id.Value())
	ckPriv = s.makeAnRSAKey(c)
	skPriv = s.makeAnRSAKey(c)

	n, err2 := xn.New(name, id, lfs, ckPriv, skPriv, nil, nil, nil)

	c.Assert(err2, IsNil)
	c.Assert(n, Not(IsNil))
	c.Assert(name, Equals, n.GetName())
	actualID := n.GetNodeID()
	c.Assert(true, Equals, id.Equal(actualID))
	// s.doKeyTests(c, n, rng)
	c.Assert(0, Equals, (*n).SizePeers())
	c.Assert(0, Equals, (*n).SizeOverlays())
	c.Assert(0, Equals, n.SizeConnections())
	c.Assert(lfs, Equals, n.GetLFS())
	return n, ckPriv, skPriv
}
开发者ID:jddixon,项目名称:upax_go,代码行数:32,代码来源:gocheck_test.go

示例5: makeARegCluster

// Make a RegCluster for test purposes.  Cluster member names are guaranteed
// to be unique but the name of the cluster itself may not be.
//
// THIS IS THE REGISTRY'S VIEW OF A CLUSTER
func (s *XLSuite) makeARegCluster(c *C, rng *xr.PRNG, epCount, size uint32) (
	rc *RegCluster) {

	var err error
	c.Assert(MIN_CLUSTER_SIZE <= size && size <= MAX_CLUSTER_SIZE, Equals, true)

	attrs := uint64(rng.Int63())
	name := rng.NextFileName(8) // no guarantee of uniqueness
	id := s.makeANodeID(c, rng)

	rc, err = NewRegCluster(name, id, attrs, size, epCount)
	c.Assert(err, IsNil)

	for count := uint32(0); count < size; count++ {
		cm := s.makeAClientInfo(c, rng, epCount)
		for {
			if _, ok := rc.MembersByName[cm.GetName()]; ok {
				// name is in use, so try again
				cm = s.makeAClientInfo(c, rng, epCount)
			} else {
				err = rc.AddMember(cm)
				c.Assert(err, IsNil)
				break
			}
		}
	}
	return
}
开发者ID:jddixon,项目名称:xlReg_go,代码行数:32,代码来源:gocheck_test.go

示例6: doTestSimpleTreeConstructor

func doTestSimpleTreeConstructor(c *C, rng *xr.PRNG, usingSHA1 bool) {
	name := rng.NextFileName(8)
	tree := NewNLHTree(name, usingSHA1)
	c.Assert(tree.name, Equals, name)
	c.Assert(tree.usingSHA1, Equals, usingSHA1)
	c.Assert(len(tree.nodes), Equals, 0)
}
开发者ID:jddixon,项目名称:xlUtil_go,代码行数:7,代码来源:nlhTree_test.go

示例7: noDotsOrDashes

func (s *XLSuite) noDotsOrDashes(rng *xr.PRNG) string {
	var length int = 3 + rng.Intn(16)
	var name = rng.NextFileName(length)
	for len(name) < 3 || strings.ContainsAny(name, ".-") ||
		strings.ContainsAny(name[0:1], "0123456789") {
		name = rng.NextFileName(length)
	}
	return name
}
开发者ID:jddixon,项目名称:xlUtil_go,代码行数:9,代码来源:entityName_test.go

示例8: doTestConstructor

func doTestConstructor(c *C, rng *xr.PRNG, usingSHA1 bool) {
	name := rng.NextFileName(8)
	b := NewNLHBase(name, usingSHA1)
	c.Assert(b.Name(), Equals, name)
	c.Assert(b.UsingSHA1(), Equals, usingSHA1)
	root := b.Root()
	ct := b.CurTree()
	c.Assert(root.Name(), Equals, ct.Name())
}
开发者ID:jddixon,项目名称:xlUtil_go,代码行数:9,代码来源:nlhBase_test.go

示例9: doTestLoadEntries

func (s *XLSuite) doTestLoadEntries(c *C, rng *xr.PRNG, whichSHA int) {
	K := 16 + rng.Intn(16)

	// create a unique name for a scratch file
	pathToFile := filepath.Join("tmp", rng.NextFileName(16))
	found, err := xf.PathExists(pathToFile)
	c.Assert(err, IsNil)
	for found {
		pathToFile = filepath.Join("tmp", rng.NextFileName(16))
		found, err = xf.PathExists(pathToFile)
		c.Assert(err, IsNil)
	}
	f, err := os.OpenFile(pathToFile, os.O_CREATE|os.O_WRONLY, 0600)
	c.Assert(err, IsNil)

	// create K entries, saving them in a slice while writing them
	// to disk
	var entries []*LogEntry
	for i := 0; i < K; i++ {
		t, key, nodeID, src, path := s.makeEntryData(c, rng, whichSHA)
		entry, err := NewLogEntry(t, key, nodeID, src, path)
		c.Assert(err, IsNil)
		strEntry := entry.String()
		entries = append(entries, entry)
		var count int
		count, err = f.WriteString(strEntry + "\n")
		c.Assert(err, IsNil)
		c.Assert(count, Equals, len(strEntry)+1)
	}
	f.Close()
	c.Assert(len(entries), Equals, K)

	// use UpaxServer.LoadEntries to load the stuff in the file.
	m, err := xi.NewNewIDMap()
	c.Assert(err, IsNil)
	count, err := loadEntries(pathToFile, m, whichSHA)
	c.Assert(err, IsNil)
	c.Assert(count, Equals, K) // K entries loaded.

	for i := 0; i < K; i++ {
		var entry, eInMap *LogEntry
		var whatever interface{}
		entry = entries[i]
		key := entry.key
		whatever, err = m.Find(key)
		c.Assert(err, IsNil)
		c.Assert(whatever, NotNil)
		eInMap = whatever.(*LogEntry)

		// DEBUG
		// XXX NEED LogEntry.Equal()
		// END

		c.Assert(bytes.Equal(key, eInMap.key), Equals, true)
	}
}
开发者ID:jddixon,项目名称:upax_go,代码行数:56,代码来源:entry_test.go

示例10: getTwoUniqueDirectoryNames

func (s *XLSuite) getTwoUniqueDirectoryNames(c *C, rng *xr.PRNG) (
	string, string) {

	dirName1 := rng.NextFileName(MAX_NAME_LEN)
	dirName2 := rng.NextFileName(MAX_NAME_LEN)
	for dirName2 == dirName1 {
		dirName2 = rng.NextFileName(MAX_NAME_LEN)
	}
	return dirName1, dirName2
}
开发者ID:jddixon,项目名称:xlUtil_go,代码行数:10,代码来源:merkle_tree_test.go

示例11: getAName

func (s *XLSuite) getAName(rng *xr.PRNG) (name string) {
	name = string(rng.NextFileName(8))
	for {
		first := string(name[0])
		if !strings.ContainsAny(name, "-_.") && !strings.ContainsAny(first, "0123456789") {
			break
		}
		name = string(rng.NextFileName(8))
	}
	return
}
开发者ID:jddixon,项目名称:xlOverlay_go,代码行数:11,代码来源:parser_test.go

示例12: getTwoUniqueDirectoryNames

func getTwoUniqueDirectoryNames(c *C, rng *xr.PRNG) (dirName1, dirName2 string) {

	dirName1 = rng.NextFileName(8)
	dirName2 = dirName1
	for dirName2 == dirName1 {
		dirName2 = rng.NextFileName(8)
	}
	c.Assert(len(dirName1) > 0, Equals, true)
	c.Assert(len(dirName2) > 0, Equals, true)
	c.Assert(dirName1 != dirName2, Equals, true)
	return
}
开发者ID:jddixon,项目名称:xlUtil_go,代码行数:12,代码来源:nlhTree_test.go

示例13: makeTwoTestDirectories

func makeTwoTestDirectories(c *C, rng *xr.PRNG, depth, width int) (
	dirName1, dirPath1, dirName2, dirPath2 string) {

	dirName1 = rng.NextFileName(8)
	dirPath1 = makeOneNamedTestDirectory(c, rng, dirName1, depth, width)

	dirName2 = dirName1
	for dirName2 == dirName1 {
		dirName2 = rng.NextFileName(8)
	}
	dirPath2 = makeOneNamedTestDirectory(c, rng, dirName2, depth, width)

	return
}
开发者ID:jddixon,项目名称:xlUtil_go,代码行数:14,代码来源:nlhTree_test.go

示例14: makeContext

func (s *XLSuite) makeContext(c *C, rng *xr.PRNG, size int) (
	k, v []string, context *gc.Context) {

	var err error
	context = gc.NewNewContext()
	k = s.makeSymbolSet(c, rng, size)
	v = make([]string, size)
	for i := 0; i < size; i++ {
		value := rng.NextFileName(8)
		v[i] = value
		err = context.Bind(k[i], value)
		c.Assert(err, IsNil)
	}
	return k, v, context
}
开发者ID:jddixon,项目名称:xgo_go,代码行数:15,代码来源:processor_test.go

示例15: makeAMemberInfo

func (s *XLSuite) makeAMemberInfo(c *C, rng *xr.PRNG) *xcl.MemberInfo {
	attrs := uint64(rng.Int63())
	peer, err := xn.NewPeer(
		rng.NextFileName(8),
		s.makeANodeID(c, rng),
		&s.makeAnRSAKey(c).PublicKey,
		&s.makeAnRSAKey(c).PublicKey,
		nil, // overlays
		nil) // XXX CONNECTORS
	c.Assert(err, IsNil)
	return &xcl.MemberInfo{
		Attrs: attrs,
		Peer:  peer,
	}
} // GEEP
开发者ID:jddixon,项目名称:xlReg_go,代码行数:15,代码来源:gocheck_test.go


注:本文中的github.com/jddixon/rnglib_go.PRNG.NextFileName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。