コード例 #1
0
ファイル: repl_test.go プロジェクト: fjballest/clive
func TestTreePush(t *testing.T) {
	db, fn := mkrtest(t, rtdir)
	defer fn()
	db.Close()
	db, fn2 := mktest(t, tdir)
	defer fn2()
	db.Close()

	tr, err := New("adb", tdir, "unix!local!9988!/p")
	if err != nil {
		t.Fatalf("tree %s", err)
	}
	tr.Debug = testing.Verbose()
	tr.Rdb.Debug = testing.Verbose()
	defer tr.Close()
	fstest.MkChgs(t, tdir)
	fstest.MkChgs2(t, rtdir+"/p")
	chkFiles(t, tr.Ldb, fstest.AllFiles, fstest.AllFilesList)
	chkFiles(t, tr.Rdb, fstest.AllFiles, fstest.AllFilesList)
	dprintf("\npush\n")
	cc, dc := getChgs()
	err = tr.BlindPush(cc)
	if err != nil {
		t.Fatalf("push %s", err)
	}
	cs := <-dc
	logChgs(cs)
	cmpChgs(t, pushcs, cs)
	chkFiles(t, tr.Ldb, nil, pushldb)
	chkFiles(t, tr.Rdb, nil, pushrdb)
	os.RemoveAll(rtdir + ".push")
	os.Rename(rtdir+"/p", rtdir+".push")
}
コード例 #2
0
ファイル: zxc_test.go プロジェクト: chengguozhen/clive
func TestExtChanges(t *testing.T) {
	os.Args[0] = "rzx.test"
	fstest.Verb = testing.Verbose()
	ccfg, err := net.TLSCfg("/Users/nemo/.ssh/client")
	if err != nil {
		t.Logf("no certs found, no tls conn")
	}
	scfg, err := net.TLSCfg("/Users/nemo/.ssh/server")
	if err != nil || ccfg == nil {
		ccfg = nil
		scfg = nil
		t.Logf("no certs found, no tls conn")
	}
	_, _ = scfg, ccfg
	fstest.MkTree(t, tdir)
	defer os.RemoveAll(tdir)
	lfs, err := zux.NewZX(tdir)
	if err != nil {
		t.Fatal(err)
	}
	defer lfs.Sync()

	cfs, err := New(lfs)
	if err != nil {
		t.Fatal(err)
	}
	defer cfs.Close()
	cfs.Debug = testing.Verbose()
	lfs.Debug = testing.Verbose()
	cfs.Flags.Set("rfsdebug", cfs.Debug)
	cfs.Flags.Set("cachedebug", cfs.Debug)
	cfs.Flags.Set("verb", cfs.Debug)
	rc := fscmp.Diff(lfs, cfs)
	out := ""
	for c := range rc {
		s := fmt.Sprintf("pre chg %s %s\n", c.Type, c.D.Fmt())
		out += s
	}
	if len(out) > 0 {
		t.Fatalf("had changes")
	}
	cfs.Dprintf("%s", out)
	fstest.MkZXChgs(t, lfs)
	fstest.MkZXChgs2(t, lfs)
	cacheTout = time.Millisecond
	time.Sleep(cacheTout)
	rc = fscmp.Diff(lfs, cfs)
	out = ""
	for c := range rc {
		s := fmt.Sprintf("post chg %s %s\n", c.Type, c.D.Fmt())
		out += s
	}
	cfs.Dprintf("%s", out)
	if len(out) > 0 {
		t.Fatalf("had missed external changes")
	}
	if cfs.Debug {
		cfs.c.dump()
	}
}
コード例 #3
0
ファイル: repl_test.go プロジェクト: fjballest/clive
func TestTreeSync(t *testing.T) {
	db, fn := mkrtest(t, rtdir)
	defer fn()
	db.Close()
	db, fn2 := mktest(t, tdir)
	defer fn2()
	db.Close()

	tr, err := New("adb", tdir, "unix!local!9988!/p")
	if err != nil {
		t.Fatalf("tree %s", err)
	}
	tr.Debug = testing.Verbose()
	tr.Rdb.Debug = testing.Verbose()
	defer tr.Close()
	fstest.MkChgs(t, tdir)
	fstest.MkChgs2(t, rtdir+"/p")
	dprintf("\nsync\n")
	cc, dc := getChgs()
	err = tr.Sync(cc)
	if err != nil {
		t.Fatalf("sync %s", err)
	}
	cs := <-dc
	logChgs(cs)
	chkFiles(t, tr.Ldb, nil, "")
	chkFiles(t, tr.Rdb, nil, "")
	os.RemoveAll(tdir + ".pull")
	os.Rename(tdir, tdir+".pull")
	os.RemoveAll(rtdir + ".push")
	os.Rename(rtdir+"/p", rtdir+".push")
}
コード例 #4
0
ファイル: sre_test.go プロジェクト: Christopheraburns/clive
func TestExecBack(t *testing.T) {
	// Debug = testing.Verbose()
	for i, e := range xexprs {
		p, err := CompileStr(e, Bck)
		if err != nil {
			t.Errorf("compile error: %v", err)
			continue
		}
		fmt.Printf("expr: '%s':\n", e)
		if testing.Verbose() && false {
			fmt.Printf("%s", p)
		}
		ranges := [][]Range{}
		for pos := len(xtext); pos >= 0; {
			rg := p.ExecStr(xtext, pos, len(xtext))
			if len(rg)==0 || rg[0].P0<0 {
				break
			}
			pos = rg[0].P0
			if rg[0].P0 == rg[0].P1 {
				pos--
			}
			o := fmt.Sprintf("%v", rg)
			txt := xtext[rg[0].P0:rg[0].P1]
			if testing.Verbose() {
				fmt.Printf(" =>%s '%s'\n", o, txt)
			}
			ranges = append(ranges, rg)
		}
		os := fmt.Sprintf("%v", ranges)
		if os != xoutback[i] {
			t.Errorf("output for %s does not match: `%s`", e, os)
		}
	}
}
コード例 #5
0
func TestFixHCL(t *testing.T) {
	var vHCL interface{}

	if err := hcl.Unmarshal(stackfixture.StackHCL, &vHCL); err != nil {
		t.Fatalf("hcl.Unmarshal()=%s", err)
	}

	if testing.Verbose() {
		t.Logf("original (vHCL):\n%s", mustJSON(vHCL))
	}

	if reflect.DeepEqual(vHCL, stackfixture.Stack) {
		t.Fatal("expected HCL-encoded stack to not unmarshal cleanly")
	}

	stack.FixHCL(vHCL)

	if !reflect.DeepEqual(vHCL, stackfixture.Stack) {
		t.Fatalf("got %+v, want %+v", vHCL, stackfixture.Stack)
	}

	var vJSON interface{}

	if err := json.Unmarshal(stackfixture.StackJSON, &vJSON); err != nil {
		t.Fatalf("json.Unmarshal()=%s", err)
	}

	if testing.Verbose() {
		t.Logf("fixed (vJSON):\n%s", mustJSON(vJSON))
	}

	if !reflect.DeepEqual(vJSON, vHCL) {
		t.Fatalf("got %+v, want %+v", vJSON, vHCL)
	}
}
コード例 #6
0
// NewConfig returns the default config with temporary paths.
func NewConfig() *run.Config {
	c := run.NewConfig()
	c.ReportingDisabled = true
	c.Cluster.ShardWriterTimeout = toml.Duration(30 * time.Second)
	c.Cluster.WriteTimeout = toml.Duration(30 * time.Second)
	c.Meta.Dir = MustTempFile()
	c.Meta.BindAddress = "127.0.0.1:0"
	c.Meta.HTTPBindAddress = "127.0.0.1:0"
	c.Meta.HeartbeatTimeout = toml.Duration(50 * time.Millisecond)
	c.Meta.ElectionTimeout = toml.Duration(50 * time.Millisecond)
	c.Meta.LeaderLeaseTimeout = toml.Duration(50 * time.Millisecond)
	c.Meta.CommitTimeout = toml.Duration(5 * time.Millisecond)

	if !testing.Verbose() {
		c.Meta.LoggingEnabled = false
	}

	c.Data.Dir = MustTempFile()
	c.Data.WALDir = MustTempFile()
	c.Data.WALLoggingEnabled = false

	c.HintedHandoff.Dir = MustTempFile()

	c.HTTPD.Enabled = true
	c.HTTPD.BindAddress = "127.0.0.1:0"
	c.HTTPD.LogEnabled = testing.Verbose()

	c.Monitor.StoreEnabled = false

	return c
}
コード例 #7
0
ファイル: twilio_test.go プロジェクト: kyleburton/twilio.go
func init() {
	// a 'live' test against the Twilio API
	if os.Getenv("TWILIO_TEST_CONFIG") != "" {
		if testing.Verbose() {
			fmt.Fprintf(os.Stderr, "TWILIO_TEST_CONFIG=%s\n", os.Getenv("TWILIO_TEST_CONFIG"))
		}
		data, e := ioutil.ReadFile(os.Getenv("TWILIO_TEST_CONFIG"))
		if e != nil {
			fmt.Fprintf(os.Stderr, "File error: %v\n", e)
		}
		if testing.Verbose() {
			fmt.Fprintf(os.Stderr, "twilio_test.go: init, data=%s\n", string(data))
		}
		DefaultClient.Unmarshal(data)
		DefaultClient.Verbose = testing.Verbose()
		if testing.Verbose() {
			fmt.Fprintf(os.Stderr, "twilio_test.go: init, DefaultClient=%s\n", DefaultClient)
		}
	} else {
		if testing.Verbose() {
			fmt.Fprintf(os.Stderr, "init: Creating default\n")
		}
		TestServer = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			fmt.Fprintf(w, "%s", `{"sid": "account.test-sid"}`)
		}))
		// how to close this at the end of all the tests?
		// defer TestServer.Close()
		TestBaseUrl = TestServer.URL
		DefaultClient = MakeTestClient("banana", "kimchee")
	}
}
コード例 #8
0
ファイル: ns_test.go プロジェクト: Christopheraburns/clive
func TestResolve(t *testing.T) {
	ns := mkns(t, false)
	defer fstest.RmTree(t, tdir)
	ns.Debug = testing.Verbose()
	ns.DebugFind = testing.Verbose()

	for _, r := range resolves {
		_, dirs, paths, err := ns.Resolve(r.Path)
		printf("sts %v\n", err)
		if err!=nil && !r.Fails {
			t.Fatalf("failed with %v", err)
		}
		if err==nil && r.Fails {
			t.Fatal("didn't fail")
		}
		if len(dirs) != len(paths) {
			t.Fatal("wrong lengths")
		}
		printf("dirs:\n")
		for _, d := range dirs {
			delete(d, "Uid")
			delete(d, "Gid")
			delete(d, "Wuid")
			delete(d, "Sum")
			printf("\t`%s`,\n", d)
		}
		printf("paths:\n")
		for _, p := range paths {
			printf("\t`%s`,\n", p)
		}
		for i := 0; i<len(r.Dirs) && i<len(dirs); i++ {
			if r.Dirs[i] != dirs[i].String() {
				t.Fatalf("bad result [%d]\n\tgot %s\n\twant %s\n",
					i, dirs[i], r.Dirs[i])
			}
		}
		if r.Dirs != nil {
			if len(dirs) > len(r.Dirs) {
				t.Fatalf("unexpected %s", dirs[len(r.Dirs)])
			}
			if len(dirs) < len(r.Dirs) {
				t.Fatalf("did expect %s", r.Dirs[len(dirs)])
			}
		}
		for i := 0; i<len(r.Paths) && i<len(paths); i++ {
			if r.Paths[i] != paths[i] {
				t.Fatalf("bad result [%d]\n\tgot %s\n\twant %s\n",
					i, paths[i], r.Paths[i])
			}
		}
		if r.Paths != nil {
			if len(paths) > len(r.Paths) {
				t.Fatalf("unexpected %s", paths[len(r.Paths)])
			}
			if len(paths) < len(r.Paths) {
				t.Fatalf("did expect %s", r.Paths[len(paths)])
			}
		}
	}
}
コード例 #9
0
ファイル: world_dat_test.go プロジェクト: BenLubar/df2014
func testWorldDat(t *testing.T, fn string) {
	t.Log(fn)

	f, err := os.Open(fn)
	if err != nil {
		t.Fatal(err)
	}
	defer f.Close()

	r := &Reader{f}

	var w WorldDat

	err = r.Decode(&w)
	if err != nil {
		t.Error(err)
	}
	if testing.Verbose() {
		t.Log(string(prettyPrint(&w, reflect.ValueOf(w), nil, []byte{'\n'}, "")))
	}

	if err == nil || testing.Verbose() {
		xxd := exec.Command("xxd")
		xxd.Stdin = io.LimitReader(r, 1<<10)
		b, err := xxd.CombinedOutput()
		if err != nil {
			t.Fatal(err)
		}
		if len(b) != 0 {
			t.Errorf("Unparsed data:\n%s", b)
		}
	}
}
コード例 #10
0
ファイル: writer_test.go プロジェクト: dt/gohfile
func tempHfile(t *testing.T, compress bool, blockSize int, keys [][]byte, values [][]byte) (string, *Scanner) {
	fp, err := ioutil.TempFile("", "demohfile")
	if err != nil {
		t.Fatal("error creating tempfile:", err)
	}
	if testing.Verbose() {
		log.Println("###############")
		log.Println("Writing temp hfile:", fp.Name())
		log.Println("###############")
	}
	w, err := NewWriter(fp, compress, blockSize, testing.Verbose())
	if err != nil {
		t.Fatal("error creating writer:", err)
	}
	for i, _ := range keys {
		if err := w.Write(keys[i], values[i]); err != nil {
			t.Fatal("error writing k-v pair:", err)
		}
	}
	w.Close()

	if testing.Verbose() {
		log.Println("###############")
		log.Println("Done writing temp hfile:", fp.Name())
		log.Println("###############")
	}

	r, err := NewReader("demo", fp.Name(), false, testing.Verbose())
	if err != nil {
		t.Fatal("error creating reader:", err)
	}
	s := NewScanner(r)

	return fp.Name(), s
}
コード例 #11
0
ファイル: ns_test.go プロジェクト: Christopheraburns/clive
func TestRFind(t *testing.T) {
	ns := mkrns(t, false)
	defer fstest.RmTree(t, tdir)
	ns.Debug = testing.Verbose()
	ns.DebugFind = testing.Verbose()
	for _, f := range finds {
		dc := ns.Find(f.Path, f.Pred, f.Spref, f.Spref, f.Depth)
		outs := []string{}
		for d := range dc {
			printf("got %s err %s\n", d.TestFmt(), d["err"])
			if d["err"] != "" {
				continue
			}
			if d["type"] == "c" {		// for fuse&cfs
				d["type"] = "-"
			}
			outs = append(outs, d.TestFmt())
		}
		printf("done find %s %s sts %v\n", f.Path, f.Pred, cerror(dc))
		for i := 0; i<len(f.Res) && i<len(outs); i++ {
			if outs[i] != f.Res[i] {
				t.Fatalf("bad result [%d]\n\tgot %s\n\twant %s\n", i, outs[i], f.Res[i])
			}
		}
		if f.Res != nil {
			if len(outs) > len(f.Res) {
				t.Fatalf("unexpected %s", outs[len(f.Res)])
			}
			if len(outs) < len(f.Res) {
				t.Fatalf("unexpected %s", f.Res[len(outs)])
			}
		}
	}
}
コード例 #12
0
ファイル: cli_test.go プロジェクト: thinkingo/gocryptfs
// Test -init flag
func TestInit(t *testing.T) {
	dir := tmpDir + "TestInit/"
	err := os.Mkdir(dir, 0777)
	if err != nil {
		t.Fatal(err)
	}
	cmd := exec.Command(gocryptfsBinary, "-init", "-extpass", "echo test", "-scryptn=10", dir)
	if testing.Verbose() {
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
	}
	err = cmd.Run()
	if err != nil {
		t.Fatal(err)
	}
	_, err = os.Stat(dir + cryptfs.ConfDefaultName)
	if err != nil {
		t.Fatal(err)
	}

	// Test -passwd
	cmd2 := exec.Command(gocryptfsBinary, "-passwd", "-extpass", "echo test", dir)
	if testing.Verbose() {
		cmd2.Stdout = os.Stdout
		cmd2.Stderr = os.Stderr
	}
	err = cmd2.Run()
	if err != nil {
		t.Error(err)
	}
}
コード例 #13
0
ファイル: interpret_test.go プロジェクト: sdboyer/pipeviz
// Reads all message fixtures from fixtures/ein and validates them
// against the master message schema (schema.json).
func TestMessageValidity(t *testing.T) {
	files, err := ioutil.ReadDir("../fixtures/ein/")
	if err != nil {
		t.Error("Failed to scan message fixtures dir:", err.Error())
		t.FailNow()
	}

	for _, f := range files {
		if testing.Verbose() {
			t.Log("Beginning validation on", f.Name())
		}

		src, _ := ioutil.ReadFile("../fixtures/ein/" + f.Name())
		msg := gjs.NewStringLoader(string(src))
		result, err := masterSchema.Validate(msg)

		if err != nil {
			panic(err.Error())
		}

		if result.Valid() {
			if testing.Verbose() {
				t.Log(f.Name(), "passed validation")
			}
		} else {
			for _, desc := range result.Errors() {
				t.Errorf("%s\n", strings.Replace(desc.String(), "root", f.Name(), 1))
			}
		}
	}
}
コード例 #14
0
ファイル: shared_test.go プロジェクト: danny8002/go
// goCmd invokes the go tool with the installsuffix set up by TestMain. It calls
// t.Errorf if the command fails.
func goCmd(t *testing.T, args ...string) {
	newargs := []string{args[0], "-installsuffix=" + suffix}
	if testing.Verbose() {
		newargs = append(newargs, "-v")
	}
	newargs = append(newargs, args[1:]...)
	c := exec.Command("go", newargs...)
	var output []byte
	var err error
	if testing.Verbose() {
		fmt.Printf("+ go %s\n", strings.Join(newargs, " "))
		c.Stdout = os.Stdout
		c.Stderr = os.Stderr
		err = c.Run()
	} else {
		output, err = c.CombinedOutput()
	}
	if err != nil {
		if t != nil {
			t.Errorf("executing %s failed %v:\n%s", strings.Join(c.Args, " "), err, output)
		} else {
			log.Fatalf("executing %s failed %v:\n%s", strings.Join(c.Args, " "), err, output)
		}
	}
}
コード例 #15
0
ファイル: id_test.go プロジェクト: ahmetalpbalkan/osutil
func TestID(t *testing.T) {
	id, err := NextSystemUID()
	if err != nil {
		t.Error(err)
	}
	if testing.Verbose() {
		fmt.Print(" Next system UID: ", id)
	}

	if id, err = NextUID(); err != nil {
		t.Error(err)
	}
	if testing.Verbose() {
		fmt.Println("\tNext UID:", id)
	}

	if id, err = NextSystemGID(); err != nil {
		t.Error(err)
	}
	if testing.Verbose() {
		fmt.Print(" Next system GID: ", id)
	}

	if id, err = NextGID(); err != nil {
		t.Error(err)
	}
	if testing.Verbose() {
		fmt.Println("\tNext GID:", id)
	}
}
コード例 #16
0
ファイル: mdfs_test.go プロジェクト: Christopheraburns/clive
func testfn(t *testing.T, fns ...func(t fstest.Fataler, fss ...zx.Tree)) {
	bufs.Size = 1 * 1024
	os.RemoveAll(tlfsdir)
	defer os.RemoveAll(tlfsdir)
	if err := os.Mkdir(tlfsdir, 0755); err != nil {
		t.Fatalf("lfs: %s", err)
	}
	os.Args[0] = "mdfs_test"
	dfs, err := lfs.New("	cache", tlfsdir, lfs.RW)
	if err != nil {
		t.Fatalf("lfs: %s", err)
	}
	dfs.SaveAttrs(true)
	mfs, err := New("example mfs", dfs)
	if err != nil {
		t.Fatalf("lfs: %s", err)
	}
	xfs, _ := mfs.AuthFor(&auth.Info{Uid: dbg.Usr, SpeaksFor: dbg.Usr, Ok: true})
	fs := xfs.(zx.RWTree)
	fstest.MkZXTree(t, fs)
	mfs.Dbg = testing.Verbose()
	dfs.Dbg = testing.Verbose()
	var fn func(t fstest.Fataler, fss ...zx.Tree)
	if len(fns) > 0 {
		fn = fns[0]
	}
	if fn != nil {
		if mfs.Dbg {
			defer func() {
				mfs.Dump(os.Stdout)
				dfs.Dump(os.Stdout)
			}()
		}
		for _, fn := range fns {
			fn(t, fs)
		}
	} else {
		d1, _ := zx.Stat(mfs, "/")
		printf("mfs st:\t%s\n", d1)
		d1, _ = zx.Stat(dfs, "/")
		printf("lfs st:\t%s\n", d1)
		// recreate, to test a reload
		mfs, err = New("example mfs", dfs)
		if err != nil {
			t.Fatalf("lfs: %s", err)
		}
		mfs.Dbg = testing.Verbose()
		xfs, _ = mfs.AuthFor(&auth.Info{Uid: dbg.Usr, SpeaksFor: dbg.Usr, Ok: true})
		fs = xfs.(zx.RWTree)
		if mfs.Dbg {
			defer func() {
				mfs.Dump(os.Stdout)
				dfs.Dump(os.Stdout)
			}()
		}
	}
	mfs.Dbg = false
	dfs.Dbg = false
	fstest.SameDump(t, mfs, dfs)
}
コード例 #17
0
ファイル: mdfs_test.go プロジェクト: Christopheraburns/clive
func TestInitDirs(t *testing.T) {
	os.Args[0] = "mdfs_test"
	os.RemoveAll(tlfsdir)
	defer os.RemoveAll(tlfsdir)
	if err := os.Mkdir(tlfsdir, 0755); err != nil {
		t.Fatalf("lfs: %s", err)
	}
	dfs, err := lfs.New("	cache", tlfsdir, lfs.RW)
	if err != nil {
		t.Fatalf("lfs: %s", err)
	}
	dfs.SaveAttrs(true)
	dfs.Dbg = moreverb && testing.Verbose()
	fs, err := New("example mdfs", dfs)
	if err != nil {
		t.Fatalf("mdfs: %s", err)
	}
	fs.Dbg = testing.Verbose()
	if fs.Dbg {
		defer func() {
			fs.Dbg = false
			dfs.Dbg = false
			fs.Dump(os.Stdout)
			dfs.Dump(os.Stdout)
		}()
	}
	for _, dn := range fstest.Dirs {
		if err := zx.MkdirAll(fs, dn, zx.Dir{"mode": "0755"}); err != nil {
			t.Fatalf("mkdir: %s", err)
		}
	}
}
コード例 #18
0
ファイル: cli_test.go プロジェクト: thinkingo/gocryptfs
// Test -init & -config flag
func TestInitConfig(t *testing.T) {
	dir := tmpDir + "TestInitConfig/"
	config := tmpDir + "TestInitConfig.conf"
	err := os.Mkdir(dir, 0777)
	if err != nil {
		t.Fatal(err)
	}
	cmd := exec.Command(gocryptfsBinary, "-init", "-extpass", "echo test",
		"-config", config, "-scryptn=10", dir)
	if testing.Verbose() {
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
	}
	err = cmd.Run()
	if err != nil {
		t.Fatal(err)
	}
	_, err = os.Stat(config)
	if err != nil {
		t.Fatal(err)
	}

	// Test -passwd & -config
	cmd2 := exec.Command(gocryptfsBinary, "-passwd", "-extpass", "echo test",
		"-config", config, dir)
	if testing.Verbose() {
		cmd2.Stdout = os.Stdout
		cmd2.Stderr = os.Stderr
	}
	err = cmd2.Run()
	if err != nil {
		t.Error(err)
	}
}
コード例 #19
0
ファイル: import_test.go プロジェクト: dylanpoe/golang.org
func TestImportStdLib(t *testing.T) {
	start := time.Now()

	libs, err := stdLibs()
	if err != nil {
		t.Fatalf("could not compute list of std libraries: %s", err)
	}
	if len(libs) < 100 {
		t.Fatalf("only %d std libraries found - something's not right", len(libs))
	}

	// make sure printed go/types types and gc-imported types
	// can be compared reasonably well
	types.GcCompatibilityMode = true

	var totSize, totGcSize int
	for _, lib := range libs {
		// limit run time for short tests
		if testing.Short() && time.Since(start) >= 750*time.Millisecond {
			return
		}
		if lib == "cmd/internal/objfile" || lib == "net/http" {
			// gcimporter doesn't support vendored imports.
			// TODO(gri): fix.
			continue
		}

		pkg, err := pkgForPath(lib)
		switch err := err.(type) {
		case nil:
			// ok
		case *build.NoGoError:
			// no Go files - ignore
			continue
		default:
			t.Errorf("typecheck failed: %s", err)
			continue
		}

		size, gcsize := testExportImport(t, pkg, lib)
		if gcsize == 0 {
			// if gc import didn't happen, assume same size
			// (and avoid division by zero below)
			gcsize = size
		}

		if testing.Verbose() {
			fmt.Printf("%s\t%d\t%d\t%d%%\n", lib, size, gcsize, int(float64(size)*100/float64(gcsize)))
		}
		totSize += size
		totGcSize += gcsize
	}

	if testing.Verbose() {
		fmt.Printf("\n%d\t%d\t%d%%\n", totSize, totGcSize, int(float64(totSize)*100/float64(totGcSize)))
	}

	types.GcCompatibilityMode = false
}
コード例 #20
0
ファイル: sync_test.go プロジェクト: Christopheraburns/clive
func TestSync0Chgs(t *testing.T) {
	fstest.ResetTime()
	fstest.MkTree(t, tdir)
	defer fstest.RmTree(t, tdir)
	fstest.ResetTime()
	fstest.MkTree(t, tdir2)
	defer fstest.RmTree(t, tdir2)
	fstest.MkChgs(t, tdir2)
	fs, err := lfs.New(tdir, tdir, lfs.RW)
	if err != nil {
		t.Fatalf("new lfs: %s", err)
	}
	fs2, err := lfs.New(tdir2, tdir2, lfs.RW)
	if err != nil {
		t.Fatalf("new lfs: %s", err)
	}
	Debug = moreverb
	fs.Dbg = moreverb
	fs2.Dbg = moreverb
	fs.SaveAttrs(true)
	fs2.SaveAttrs(true)

	db, err := NewDB("tdb", "", fs)
	if err != nil {
		t.Fatalf("new: %s", err)
	}
	if testing.Verbose() {
		db.DumpTo(os.Stdout)
	}
	db2, err := NewDB("tdb2", "", fs2)
	if err != nil {
		t.Fatalf("new: %s", err)
	}
	if testing.Verbose() {
		db2.DumpTo(os.Stdout)
	}
	pulls := []chg{
		chg{Type: Data, Path: "/a/a1"},
		chg{Type: Meta, Path: "/a/a2"},
		chg{Type: Add, Path: "/a/n"},
	}
	pushes := []chg{
		chg{Type: Add, Path: "/a/b/c"},
	}
	pullc, pushc := Changes(db, db2)
	ec := make(chan error, 2)
	go chkcc("pull", pullc, pulls, ec)
	go chkcc("push", pushc, pushes, ec)
	if e := <-ec; e != nil {
		t.Fatal(e)
	}
	if e := <-ec; e != nil {
		t.Fatal(e)
	}
	if testing.Verbose() {
		db.DumpTo(os.Stdout)
		db2.DumpTo(os.Stdout)
	}
}
コード例 #21
0
ファイル: utp_test.go プロジェクト: postfix/utp-1
func connectSelfLots(n int, t testing.TB) {
	s, err := NewSocket("127.0.0.1:0")
	if err != nil {
		t.Fatal(err)
	}
	go func() {
		for range iter.N(n) {
			c, err := s.Accept()
			if err != nil {
				log.Fatal(err)
			}
			defer c.Close()
		}
	}()
	dialErr := make(chan error)
	connCh := make(chan net.Conn)
	for range iter.N(n) {
		go func() {
			c, err := s.Dial(s.Addr().String())
			if err != nil {
				dialErr <- err
				return
			}
			connCh <- c
		}()
	}
	conns := make([]net.Conn, 0, n)
	for range iter.N(n) {
		select {
		case c := <-connCh:
			conns = append(conns, c)
		case err := <-dialErr:
			t.Fatal(err)
		}
		if testing.Verbose() {
			log.Printf("%x", len(conns))
		}
	}
	for _, c := range conns {
		if c != nil {
			c.Close()
		}
	}
	s.mu.Lock()
	for len(s.conns) != 0 {
		if testing.Verbose() {
			log.Printf("socket conns: %d", len(s.conns))
			if len(s.conns) < 10 {
				for _, c := range s.conns {
					log.Printf("%#v", c)
				}
			}
		}
		s.event.Wait()
	}
	s.mu.Unlock()
	s.Close()
}
コード例 #22
0
ファイル: auth_test.go プロジェクト: chengguozhen/clive
func TestMuxAuth(t *testing.T) {
	addr := "unix!local!6679"
	debug = testing.Verbose()
	printf("serving...\n")
	mc, ec, err := net.MuxServe(addr)
	if err != nil {
		t.Fatal(err)
	}
	donec := make(chan bool)
	failed := false
	go func() {
		for mx := range mc {
			mx.Debug = testing.Verbose()
			printf("new muxed client %q\n", mx.Tag)
			mx := mx
			c := <-mx.In
			printf("new muxed conn %s\n", c.Tag)
			ai, err := AtServer(c, "", "foo")
			if err != nil {
				printf("auth failed at server: %s\n", err)
				failed = true
			} else {
				printf("server ai %v\n", ai)
			}
			close(c.In)
			close(c.Out)
		}
		close(donec)
	}()
	go func() {
		<-ec
		printf("serve mux done: %v\n", cerror(ec))
	}()
	printf("dialing...\n")
	mx, err := net.MuxDial(addr)
	if err != nil {
		t.Fatal(err)
	}
	printf("now talking...\n")
	call := mx.Rpc()
	ai, err := AtClient(call, "", "foo")
	if err != nil {
		t.Fatalf("auth failed with %s", err)
	}
	if failed {
		t.Fatal("server auth failed")
	}
	printf("client ai %v\n", ai)
	close(call.Out)
	<-call.In
	printf("closing...\n")
	close(ec)
	<-donec
}
コード例 #23
0
ファイル: parallel_test.go プロジェクト: veteranlu/cockroach
func (t *parallelTest) setup(spec *parTestSpec) {
	if spec.ClusterSize == 0 {
		spec.ClusterSize = 1
	}

	if testing.Verbose() || log.V(1) {
		log.Infof(t.ctx, "Cluster Size: %d", spec.ClusterSize)
	}

	args := base.TestClusterArgs{
		ServerArgs: base.TestServerArgs{
			Knobs: base.TestingKnobs{
				SQLExecutor: &sql.ExecutorTestingKnobs{
					WaitForGossipUpdate:   true,
					CheckStmtStringChange: true,
				},
			},
		},
	}
	t.cluster = serverutils.StartTestCluster(t, spec.ClusterSize, args)
	t.clients = make([][]*gosql.DB, spec.ClusterSize)
	for i := range t.clients {
		t.clients[i] = append(t.clients[i], t.cluster.ServerConn(i))
	}
	r0 := sqlutils.MakeSQLRunner(t, t.clients[0][0])

	if spec.RangeSplitSize != 0 {
		if testing.Verbose() || log.V(1) {
			log.Infof(t.ctx, "Setting range split size: %d", spec.RangeSplitSize)
		}
		zoneCfg := config.DefaultZoneConfig()
		zoneCfg.RangeMaxBytes = int64(spec.RangeSplitSize)
		zoneCfg.RangeMinBytes = zoneCfg.RangeMaxBytes / 2
		buf, err := protoutil.Marshal(&zoneCfg)
		if err != nil {
			t.Fatal(err)
		}
		objID := keys.RootNamespaceID
		r0.Exec(`UPDATE system.zones SET config = $2 WHERE id = $1`, objID, buf)
	}

	if testing.Verbose() || log.V(1) {
		log.Infof(t.ctx, "Creating database")
	}

	r0.Exec("CREATE DATABASE test")
	for i := range t.clients {
		sqlutils.MakeSQLRunner(t, t.clients[i][0]).Exec("SET DATABASE = test")
	}

	if testing.Verbose() || log.V(1) {
		log.Infof(t.ctx, "Test setup done")
	}
}
コード例 #24
0
ファイル: repl_test.go プロジェクト: fjballest/clive
func TestTreeSaveLoad(t *testing.T) {

	db, fn := mkrtest(t, rtdir)
	defer fn()
	db.Close()
	db, fn2 := mktest(t, tdir)
	defer fn2()
	db.Close()
	fstest.MkChgs(t, tdir)
	fstest.MkChgs2(t, rtdir+"/p")
	os.Remove(tdir + "repl.ldb")
	os.Remove(tdir + "repl.rdb")
	defer os.Remove(tdir + "repl.ldb")
	defer os.Remove(tdir + "repl.rdb")
	tr, err := New("adb", tdir, "unix!local!9988!/p")
	if err != nil {
		t.Fatalf("tree %s", err)
	}
	tr.Debug = testing.Verbose()
	tr.Rdb.Debug = testing.Verbose()
	defer tr.Close()
	dprintf("\ninitial:\n")
	chkFiles(t, tr.Ldb, nil, "")
	chkFiles(t, tr.Rdb, nil, "")

	dprintf("\nsave & load:\n")
	if err := tr.Save(tdir + "repl"); err != nil {
		t.Fatalf("save %s", err)
	}
	if tr, err = Load(tdir + "repl"); err != nil {
		t.Fatalf("load %s", err)
	}
	chkFiles(t, tr.Ldb, nil, "")
	chkFiles(t, tr.Rdb, nil, "")

	// now continue as in the previous test, to check
	// it all is ok.
	dprintf("\npullall\n")
	cc, dc := getChgs()
	err = tr.PullAll(cc)
	if err != nil {
		t.Fatalf("pullall %s", err)
	}
	dprintf("\npullall done\n")
	cs := <-dc
	logChgs(cs)
	chkFiles(t, tr.Ldb, nil, pullrdb)
	chkFiles(t, tr.Rdb, nil, pullrdb)
	os.RemoveAll(tdir + ".pull")
	os.Rename(tdir, tdir+".pull")
	os.RemoveAll(rtdir + ".push")
	os.Rename(rtdir+"/p", rtdir+".push")

}
コード例 #25
0
ファイル: husl_test.go プロジェクト: husl-colors/husl-go
func TestSnapshot(t *testing.T) {
	snapshotFile, err := os.Open("snapshot-rev4.json")
	if err != nil {
		t.Fatal(err)
	}
	defer snapshotFile.Close()

	jsonParser := json.NewDecoder(snapshotFile)
	snapshot := make(mapping)
	if err = jsonParser.Decode(&snapshot); err != nil {
		t.Fatal(err)
	}

	for hex, colorValues := range snapshot {
		// tests for public methods
		if testing.Verbose() {
			t.Logf("Testing public methods for test case %s", hex)
		}

		compareHex(t, HuslToHex(unpack(colorValues.Husl)), hex, "HuslToHex", hex)
		compareTuple(t, pack(HuslToRGB(unpack(colorValues.Husl))), colorValues.Rgb, "HuslToRGB", hex)
		compareTuple(t, pack(HuslFromHex(hex)), colorValues.Husl, "HuslFromHex", hex)
		compareTuple(t, pack(HuslFromRGB(unpack(colorValues.Rgb))), colorValues.Husl, "HuslFromRGB", hex)
		compareHex(t, HuslpToHex(unpack(colorValues.Huslp)), hex, "HuslpToHex", hex)
		compareTuple(t, pack(HuslpToRGB(unpack(colorValues.Huslp))), colorValues.Rgb, "HuslpToRGB", hex)
		compareTuple(t, pack(HuslpFromHex(hex)), colorValues.Huslp, "HuslpFromHex", hex)
		compareTuple(t, pack(HuslpFromRGB(unpack(colorValues.Rgb))), colorValues.Huslp, "HuslpFromRGB", hex)

		if !testing.Short() {
			// internal tests
			if testing.Verbose() {
				t.Logf("Testing internal methods for test case %s", hex)
			}

			compareTuple(t, pack(convLchRgb(unpack(colorValues.Lch))), colorValues.Rgb, "convLchRgb", hex)
			compareTuple(t, pack(convRgbLch(unpack(colorValues.Rgb))), colorValues.Lch, "convRgbLch", hex)
			compareTuple(t, pack(convXyzLuv(unpack(colorValues.Xyz))), colorValues.Luv, "convXyzLuv", hex)
			compareTuple(t, pack(convLuvXyz(unpack(colorValues.Luv))), colorValues.Xyz, "convLuvXyz", hex)
			compareTuple(t, pack(convLuvLch(unpack(colorValues.Luv))), colorValues.Lch, "convLuvLch", hex)
			compareTuple(t, pack(convLchLuv(unpack(colorValues.Lch))), colorValues.Luv, "convLchLuv", hex)
			compareTuple(t, pack(convHuslLch(unpack(colorValues.Husl))), colorValues.Lch, "convHuslLch", hex)
			compareTuple(t, pack(convLchHusl(unpack(colorValues.Lch))), colorValues.Husl, "convLchHusl", hex)
			compareTuple(t, pack(convHuslpLch(unpack(colorValues.Huslp))), colorValues.Lch, "convHuslpLch", hex)
			compareTuple(t, pack(convLchHuslp(unpack(colorValues.Lch))), colorValues.Huslp, "convLchHuslp", hex)
			compareHex(t, convRgbHex(unpack(colorValues.Rgb)), hex, "convRgbHex", hex)
			compareTuple(t, pack(convHexRgb(hex)), colorValues.Rgb, "convHexRgb", hex)
			compareTuple(t, pack(convXyzRgb(unpack(colorValues.Xyz))), colorValues.Rgb, "convXyzRgb", hex)
			compareTuple(t, pack(convRgbXyz(unpack(colorValues.Rgb))), colorValues.Xyz, "convRgbXyz", hex)
		}
	}
}
コード例 #26
0
ファイル: world.go プロジェクト: camlistore/camlistore
// Build builds the Camlistore binaries.
func (w *World) Build() error {
	var err error
	w.tempDir, err = ioutil.TempDir("", "camlistore-test-")
	if err != nil {
		return err
	}
	// Build.
	{
		targs := []string{
			"camget",
			"camput",
			"camtool",
			"camlistored",
		}
		var latestModtime time.Time
		for _, target := range targs {
			binPath := filepath.Join(w.camRoot, "bin", target)
			fi, err := os.Stat(binPath)
			if err != nil {
				if !os.IsNotExist(err) {
					return fmt.Errorf("could not stat %v: %v", binPath, err)
				}
			} else {
				modTime := fi.ModTime()
				if modTime.After(latestModtime) {
					latestModtime = modTime
				}
			}
		}
		cmd := exec.Command("go", "run", "make.go",
			fmt.Sprintf("--if_mods_since=%d", latestModtime.Unix()),
		)
		if testing.Verbose() {
			// TODO(mpl): do the same when -verbose with devcam test. Even better: see if testing.Verbose
			// can be made true if devcam test -verbose ?
			cmd.Args = append(cmd.Args, "-v=true")
		}
		cmd.Dir = w.camRoot
		log.Print("Running make.go to build camlistore binaries for testing...")
		out, err := cmd.CombinedOutput()
		if err != nil {
			return fmt.Errorf("Error building world: %v, %s", err, string(out))
		}
		if testing.Verbose() {
			log.Printf("%s\n", out)
		}
		log.Print("Ran make.go.")
	}
	return nil
}
コード例 #27
0
func (t *parallelTest) run(dir string) {
	// Process the spec file.
	mainFile := filepath.Join(dir, "test.yaml")
	yamlData, err := ioutil.ReadFile(mainFile)
	if err != nil {
		t.Fatalf("%s: %s", mainFile, err)
	}
	var spec parTestSpec
	err = yaml.Unmarshal(yamlData, &spec)
	if err != nil {
		t.Fatalf("%s: %s", mainFile, err)
	}

	if spec.SkipReason != "" {
		log.Warningf(t.ctx, "Skipping test %s: %s", dir, spec.SkipReason)
		return
	}

	log.Infof(t.ctx, "Running test %s", dir)
	if testing.Verbose() || log.V(1) {
		log.Infof(t.ctx, "spec: %+v", spec)
	}

	t.setup(&spec)
	defer t.close()

	for runListIdx, runList := range spec.Run {
		if testing.Verbose() || log.V(1) {
			var descr []string
			for _, re := range runList {
				descr = append(descr, fmt.Sprintf("%d:%s", re.Node, re.File))
			}
			log.Infof(t.ctx, "%s: run list %d: %s", mainFile, runListIdx,
				strings.Join(descr, ", "))
		}
		// Store the number of clients used so far (per node).
		numClients := make([]int, spec.ClusterSize)
		ch := make(chan bool)
		for _, re := range runList {
			client := t.getClient(re.Node, numClients[re.Node])
			numClients[re.Node]++
			go t.processTestFile(filepath.Join(dir, re.File), re.Node, client, ch)
		}
		// Wait for all clients to complete.
		for range runList {
			<-ch
		}
	}
}
コード例 #28
0
ファイル: graphite_test.go プロジェクト: theevocater/fsgo
func TestOstrichWrites(t *testing.T) {
	res, l, r, wg := NewTestServer(t, "foobar")
	defer l.Close()

	fillMetrics(r)

	wg.Add(1)
	r.Format = OstrichFormats
	if testing.Verbose() {
		t.Log("Sening ostrich format to graphite..")
	}
	r.sendToGraphite()
	wg.Wait()

	if expected, found := 0.0, res["foobar.baz.99-percentile"]; !floatEquals(found, expected) {
		t.Fatal("bad value:", expected, found)
	}

	if expected, found := 0.0, res["foobar.baz.50-percentile"]; !floatEquals(found, expected) {
		t.Fatal("bad value:", expected, found)
	}

	if expected, found := 5000.0, res["foobar.baz.percentiles.p99"]; !floatEquals(found, expected) {
		t.Fatal("bad value:", expected, found)
	}

	if expected, found := 3000.0, res["foobar.baz.percentiles.p50"]; !floatEquals(found, expected) {
		t.Fatal("bad value:", expected, found)
	}

	for k, _ := range res {
		delete(res, k)
	}

	wg.Add(1)
	if testing.Verbose() {
		t.Log("Sening recently cleared metrics to graphite...")
	}
	r.sendToGraphite()
	wg.Wait()

	if expected, found := 0.0, res["foobar.baz.percentiles.p99"]; !floatEquals(found, expected) {
		t.Fatal("bad value:", expected, found)
	}

	if expected, found := 0.0, res["foobar.baz.percentiles.p50"]; !floatEquals(found, expected) {
		t.Fatal("bad value:", expected, found)
	}
}
コード例 #29
0
ファイル: opt_test.go プロジェクト: Christopheraburns/clive
func TestFlags(t *testing.T) {
	opts := New("[file...]")
	var bl, bd, br bool
	var ival int
	opts.NewFlag("l", "long", &bl)
	opts.NewFlag("d", "long", &bd)
	opts.NewFlag("r", "long", &br)
	opts.NewFlag("i", "ival", &ival)
	for _, c := range okchks {
		bl, bd, br = false, false, false
		args, err := opts.Parse(c.argv)
		flg := fmt.Sprintf("%v %v %v %d", bl, bd, br, ival)
		left := strings.Join(args, " ")
		if testing.Verbose() {
			fmt.Printf("flags %s args %s sts %v\n", flg, left, err)
		}
		if flg!=c.flags || left!=c.args {
			t.Fatal("bad result")
		}
	}
	for _, c := range errchks {
		bl, bd, br = false, false, false
		args, err := opts.Parse(c.argv)
		flg := fmt.Sprintf("%v %v %v %d", bl, bd, br, ival)
		left := strings.Join(args, " ")
		if testing.Verbose() {
			fmt.Printf("flags %s args %s sts %v\n", flg, left, err)
		}
		if err == nil {
			t.Fatal("didn't fail")
		}
	}
	if testing.Verbose() {
		opts.Usage()
	}
	var pn, mn int
	opts.NewFlag("+num", "add numb", &pn)
	opts.NewFlag("-num", "del numb", &mn)
	args, err := opts.Parse([]string{"ls", "+3", "-ldi", "15", "-5", "/tmp"})
	flg := fmt.Sprintf("%v %v %v %d %d %d", bl, bd, br, ival, pn, mn)
	left := strings.Join(args, " ")
	if testing.Verbose() {
		fmt.Printf("flags %s args %s sts %v\n", flg, left, err)
	}
	if flg!=`true true false 15 3 -5` || left!="/tmp" {
		t.Fatal("bad arg")
	}
}
コード例 #30
0
ファイル: main_test.go プロジェクト: thinkingo/gocryptfs
// This is the entry point for the tests
func TestMain(m *testing.M) {
	var defaultonly bool
	flag.BoolVar(&defaultonly, "defaultonly", false, "Only test default configuration (openssl=true, plaintextnames=false)")
	flag.Parse()

	if testing.Verbose() {
		fmt.Printf("***** Testing with OpenSSL\n")
	}
	resetTmpDir() // <- this also create gocryptfs.diriv
	mount(defaultCipherDir, defaultPlainDir, "--zerokey")
	r := m.Run()
	unmount(defaultPlainDir)

	if r != 0 {
		os.Exit(r)
	}

	if defaultonly {
		os.Exit(r)
	}

	if testing.Verbose() {
		fmt.Printf("***** Testing with native Go crypto\n")
	}
	resetTmpDir()
	mount(defaultCipherDir, defaultPlainDir, "--zerokey", "--openssl=false")
	r = m.Run()
	unmount(defaultPlainDir)

	if r != 0 {
		os.Exit(r)
	}

	if testing.Verbose() {
		fmt.Printf("***** Testing \"--plaintextnames\"\n")
	}
	resetTmpDir()
	mount(defaultCipherDir, defaultPlainDir, "--zerokey", "--plaintextnames")
	plaintextNames = true
	r = m.Run()
	unmount(defaultPlainDir)

	if r != 0 {
		os.Exit(r)
	}

	os.Exit(r)
}