Golang RemoveAll示例

说明

golang removeall示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Golang

命名空间/包名称: os

示例#1
文件: auth.go 项目: EMSL-MSC/pacifica-uploader-2.0

func authInit() {
	os.MkdirAll(path.Join(common.BaseDir, "auth"), 0755)
	err := os.RemoveAll(path.Join(common.BaseDir, "auth", "secure"))
	if err != nil {
		log.Printf("Failed to clean out the secure directory. %v\n", err)
		os.Exit(-1)
	}
	err = os.RemoveAll(path.Join(common.BaseDir, "auth", "user"))
	if err != nil {
		log.Printf("Failed to clean out the user directory. %v\n", err)
		os.Exit(-1)
	}
	os.MkdirAll(path.Join(common.BaseDir, "auth", "user"), 0755)
	os.MkdirAll(path.Join(common.BaseDir, "auth", "secure"), 0700)
	if common.System && platform.PlatformGet() == platform.Windows {
		err = common.Cacls(path.Join(common.BaseDir, "auth", "secure"), "/p", "NT AUTHORITY\\SYSTEM:f", "BUILTIN\\Administrators:F")
		if err != nil {
			log.Printf("Failed to run cacls %v\n", err)
			os.Exit(-1)
		}
		err = common.Cacls(path.Join(common.BaseDir, "auth", "user"), "/p", "NT AUTHORITY\\SYSTEM:f", "BUILTIN\\Users:r", "BUILTIN\\Administrators:F")
		if err != nil {
			log.Printf("Failed to run cacls on auth user %v\n", err)
			os.Exit(-1)
		}
	}
}

示例#2
文件: archive_test.go 项目: truedays/docker

func BenchmarkTarUntarWithLinks(b *testing.B) {
	origin, err := ioutil.TempDir("", "docker-test-untar-origin")
	if err != nil {
		b.Fatal(err)
	}
	tempDir, err := ioutil.TempDir("", "docker-test-untar-destination")
	if err != nil {
		b.Fatal(err)
	}
	target := filepath.Join(tempDir, "dest")
	n, err := prepareUntarSourceDirectory(100, origin, true)
	if err != nil {
		b.Fatal(err)
	}
	defer os.RemoveAll(origin)
	defer os.RemoveAll(tempDir)

	b.ResetTimer()
	b.SetBytes(int64(n))
	for n := 0; n < b.N; n++ {
		err := TarUntar(origin, target)
		if err != nil {
			b.Fatal(err)
		}
		os.RemoveAll(target)
	}
}

示例#3
文件: graph.go 项目: eldarion-gondor/cli

// Delete atomically removes an image from the graph.
func (graph *Graph) Delete(name string) error {
	id, err := graph.idIndex.Get(name)
	if err != nil {
		return err
	}
	img, err := graph.Get(id)
	if err != nil {
		return err
	}
	graph.idIndex.Delete(id)
	tmp, err := graph.mktemp()
	if err != nil {
		tmp = graph.imageRoot(id)
	} else {
		if err := os.Rename(graph.imageRoot(id), tmp); err != nil {
			// On err make tmp point to old dir and cleanup unused tmp dir
			os.RemoveAll(tmp)
			tmp = graph.imageRoot(id)
		}
	}
	// Remove rootfs data from the driver
	graph.driver.Remove(id)

	graph.imageMutex.Lock(img.Parent)
	graph.parentRefs[img.Parent]--
	if graph.parentRefs[img.Parent] == 0 {
		delete(graph.parentRefs, img.Parent)
	}
	graph.imageMutex.Unlock(img.Parent)

	// Remove the trashed image directory
	return os.RemoveAll(tmp)
}

示例#4
文件: scribble.go 项目: toashd/golang-scribble

// Delete locks that database and then attempts to remove the collection/resource
// specified by [path]
func (d *Driver) Delete(collection, resource string) error {
	path := filepath.Join(collection, resource)
	//
	mutex := d.getOrCreateMutex(path)
	mutex.Lock()
	defer mutex.Unlock()

	//
	dir := filepath.Join(d.dir, path)

	switch fi, err := stat(dir); {

	// if fi is nil or error is not nil return
	case fi == nil, err != nil:
		return fmt.Errorf("Unable to find file or directory named %v\n", path)

	// remove directory and all contents
	case fi.Mode().IsDir():
		return os.RemoveAll(dir)

	// remove file
	case fi.Mode().IsRegular():
		return os.RemoveAll(dir + ".json")
	}

	return nil
}

示例#5
文件: glusterfs.go 项目: MarWestermann/gofabric8

func (c *glusterfsCleaner) cleanup(dir string) error {
	mountpoint, err := c.mounter.IsMountPoint(dir)
	if err != nil {
		glog.Errorf("Glusterfs: Error checking IsMountPoint: %v", err)
		return err
	}
	if !mountpoint {
		return os.RemoveAll(dir)
	}

	if err := c.mounter.Unmount(dir); err != nil {
		glog.Errorf("Glusterfs: Unmounting failed: %v", err)
		return err
	}
	mountpoint, mntErr := c.mounter.IsMountPoint(dir)
	if mntErr != nil {
		glog.Errorf("Glusterfs: IsMountpoint check failed: %v", mntErr)
		return mntErr
	}
	if !mountpoint {
		if err := os.RemoveAll(dir); err != nil {
			return err
		}
	}

	return nil
}

示例#6
文件: net_test.go 项目: kevinawalsh/cloudproxy

func TestCARequestACLSet(t *testing.T) {
	cal, err := net.Listen("tcp", "127.0.0.1:0")
	caAddr := cal.Addr()

	// Run TaoCA with a DatalogGuard.
	guard, keys, tmpDir, err := makeACLGuard()
	if err != nil {
		os.RemoveAll(tmpDir)
		t.Fatal(err)
	}
	defer os.RemoveAll(tmpDir)
	ch := make(chan bool)

	// Nominal test.
	go runTCCA(t, cal, keys, guard, ch)
	_, err = RequestACLSet("tcp", caAddr.String(), keys.VerifyingKey)
	if err != nil {
		t.Fatalf("Failed to get ACL set from CA: %s", err)
	}
	<-ch

	// Signature shouldn't verify
	badKeys, _ := NewTemporaryKeys(Signing)
	go runTCCA(t, cal, badKeys, guard, ch)
	_, err = RequestACLSet("tcp", caAddr.String(), keys.VerifyingKey)
	if err == nil {
		t.Error("Signature verified, should have failed")
	} else {
		t.Logf("Signature invalid!, %s", err)
	}
	<-ch
}

示例#7
文件: template_test.go 项目: titan-group/beego

func TestRelativeTemplate(t *testing.T) {
	dir := "_beeTmp"
	files := []string{
		"easyui/public/menu.tpl",
		"easyui/rbac/user.tpl",
	}
	if err := os.MkdirAll(dir, 0777); err != nil {
		t.Fatal(err)
	}
	for k, name := range files {
		os.MkdirAll(filepath.Dir(filepath.Join(dir, name)), 0777)
		if f, err := os.Create(filepath.Join(dir, name)); err != nil {
			t.Fatal(err)
		} else {
			if k == 0 {
				f.WriteString(menu)
			} else if k == 1 {
				f.WriteString(user)
			}
			f.Close()
		}
	}
	if err := BuildTemplate(dir); err != nil {
		t.Fatal(err)
	}
	if err := BeeTemplates["easyui/rbac/user.tpl"].ExecuteTemplate(os.Stdout, "easyui/rbac/user.tpl", nil); err != nil {
		t.Fatal(err)
	}
	for _, name := range files {
		os.RemoveAll(filepath.Join(dir, name))
	}
	os.RemoveAll(dir)
}

示例#8
文件: file_desc_test.go 项目: yufeng108/goleveldb

func TestFileDesc_Flock(t *testing.T) {
	pth := path.Join(os.TempDir(), fmt.Sprintf("goleveldbtestfd-%d", os.Getuid()))

	_, err := os.Stat(pth)
	if err == nil {
		err = os.RemoveAll(pth)
		if err != nil {
			t.Fatal("RemoveAll: got error: ", err)
		}
	}

	p1, err := OpenFile(pth)
	if err != nil {
		t.Fatal("OpenFile(1): got error: ", err)
	}

	defer os.RemoveAll(pth)

	p2, err := OpenFile(pth)
	if err != nil {
		t.Log("OpenFile(2): got error: ", err)
	} else {
		p2.Close()
		p1.Close()
		t.Fatal("OpenFile(2): expect error")
	}

	p1.Close()

	p3, err := OpenFile(pth)
	if err != nil {
		t.Fatal("OpenFile(3): got error: ", err)
	}
	p3.Close()
}

示例#9
文件: quick_test.go 项目: nohitall/minio

func (s *MySuite) TestSaveBackup(c *C) {
	defer os.RemoveAll("test.json")
	defer os.RemoveAll("test.json.old")
	type myStruct struct {
		Version  string
		User     string
		Password string
		Folders  []string
	}
	saveMe := myStruct{"1", "guest", "nopassword", []string{"Work", "Documents", "Music"}}
	config, err := quick.New(&saveMe)
	c.Assert(err, IsNil)
	c.Assert(config, Not(IsNil))
	err = config.Save("test.json")
	c.Assert(err, IsNil)

	loadMe := myStruct{Version: "1"}
	newConfig, err := quick.New(&loadMe)
	c.Assert(err, IsNil)
	c.Assert(newConfig, Not(IsNil))
	err = newConfig.Load("test.json")
	c.Assert(err, IsNil)

	c.Assert(config.Data(), DeepEquals, newConfig.Data())
	c.Assert(config.Data(), DeepEquals, &loadMe)

	mismatch := myStruct{"1.1", "guest", "nopassword", []string{"Work", "Documents", "Music"}}
	c.Assert(newConfig.Data(), Not(DeepEquals), &mismatch)
	config, err = quick.New(&mismatch)
	c.Assert(err, IsNil)
	c.Assert(config, Not(IsNil))
	err = config.Save("test.json")
	c.Assert(err, IsNil)
}

示例#10
文件: tx_test.go 项目: bclermont/btcwallet

func testStore() (*Store, func(), error) {
	tmpDir, err := ioutil.TempDir("", "wtxmgr_test")
	if err != nil {
		return nil, func() {}, err
	}
	db, err := walletdb.Create("bdb", filepath.Join(tmpDir, "db"))
	if err != nil {
		teardown := func() {
			os.RemoveAll(tmpDir)
		}
		return nil, teardown, err
	}
	teardown := func() {
		db.Close()
		os.RemoveAll(tmpDir)
	}
	ns, err := db.Namespace([]byte("txstore"))
	if err != nil {
		return nil, teardown, err
	}
	err = Create(ns)
	if err != nil {
		return nil, teardown, err
	}
	s, err := Open(ns, &chaincfg.TestNet3Params)
	return s, teardown, err
}

示例#11
文件: leader_test.go 项目: Unix4ever/consul

func TestLeader_MultiBootstrap(t *testing.T) {
	dir1, s1 := testServer(t)
	defer os.RemoveAll(dir1)
	defer s1.Shutdown()

	dir2, s2 := testServer(t)
	defer os.RemoveAll(dir2)
	defer s2.Shutdown()

	servers := []*Server{s1, s2}

	// Try to join
	addr := fmt.Sprintf("127.0.0.1:%d",
		s1.config.SerfLANConfig.MemberlistConfig.BindPort)
	if _, err := s2.JoinLAN([]string{addr}); err != nil {
		t.Fatalf("err: %v", err)
	}

	for _, s := range servers {
		testutil.WaitForResult(func() (bool, error) {
			peers := s.serfLAN.Members()
			return len(peers) == 2, nil
		}, func(err error) {
			t.Fatalf("should have 2 peers")
		})
	}

	// Ensure we don't have multiple raft peers
	for _, s := range servers {
		peers, _ := s.raftPeers.Peers()
		if len(peers) != 1 {
			t.Fatalf("should only have 1 raft peer!")
		}
	}
}

示例#12
文件: rm.go 项目: ZJU-SEL/hyper

func (daemon *Daemon) CleanPodWithLock(podId string) (int, string, error) {
	var (
		code  = 0
		cause = ""
		err   error
	)

	os.RemoveAll(path.Join(utils.HYPER_ROOT, "services", podId))
	os.RemoveAll(path.Join(utils.HYPER_ROOT, "hosts", podId))
	pod, ok := daemon.PodList.Get(podId)
	if !ok {
		return -1, "", fmt.Errorf("Can not find that Pod(%s)", podId)
	}

	if pod.status.Status == types.S_POD_RUNNING {
		code, cause, err = daemon.StopPodWithLock(podId, "yes")
		if err != nil {
			glog.Errorf("failed to stop pod %s", podId)
		}
	}

	daemon.DeletePodFromDB(podId)
	daemon.RemovePod(podId)
	if pod.status.Type != "kubernetes" {
		daemon.CleanUpContainer(pod.status)
	}
	daemon.DeleteVolumeId(podId)
	code = types.E_OK

	return code, cause, nil
}

示例#13
文件: config_test.go 项目: ypjin/swarmkit

func TestLoadOrCreateSecurityConfigNoCerts(t *testing.T) {
	tc := testutils.NewTestCA(t)
	defer tc.Stop()

	// Remove only the node certificates form the directory, and attest that we get
	// new certificates that are locally signed
	os.RemoveAll(tc.Paths.Node.Cert)
	nodeConfig, err := ca.LoadOrCreateSecurityConfig(tc.Context, tc.TempDir, tc.WorkerToken, ca.AgentRole, tc.Picker, nil)
	assert.NoError(t, err)
	assert.NotNil(t, nodeConfig)
	assert.NotNil(t, nodeConfig.ClientTLSCreds)
	assert.NotNil(t, nodeConfig.ServerTLSCreds)
	assert.NotNil(t, nodeConfig.RootCA().Pool)
	assert.NotNil(t, nodeConfig.RootCA().Cert)
	assert.NotNil(t, nodeConfig.RootCA().Signer)
	assert.True(t, nodeConfig.RootCA().CanSign())

	info := make(chan api.IssueNodeCertificateResponse, 1)
	// Remove only the node certificates form the directory, and attest that we get
	// new certificates that are issued by the remote CA
	os.RemoveAll(tc.Paths.RootCA.Key)
	os.RemoveAll(tc.Paths.Node.Cert)
	nodeConfig, err = ca.LoadOrCreateSecurityConfig(tc.Context, tc.TempDir, tc.WorkerToken, ca.AgentRole, tc.Picker, info)
	assert.NoError(t, err)
	assert.NotNil(t, nodeConfig)
	assert.NotNil(t, nodeConfig.ClientTLSCreds)
	assert.NotNil(t, nodeConfig.ServerTLSCreds)
	assert.NotNil(t, nodeConfig.RootCA().Pool)
	assert.NotNil(t, nodeConfig.RootCA().Cert)
	assert.Nil(t, nodeConfig.RootCA().Signer)
	assert.False(t, nodeConfig.RootCA().CanSign())
	assert.NotEmpty(t, <-info)
}

示例#14
文件: driver_test.go 项目: decred/dcrd

// TestInterface performs all interfaces tests for this database driver.
func TestInterface(t *testing.T) {
	t.Parallel()

	// Create a new database to run tests against.
	dbPath := filepath.Join(os.TempDir(), "ffldb-interfacetest")
	_ = os.RemoveAll(dbPath)
	db, err := database.Create(dbType, dbPath, blockDataNet)
	if err != nil {
		t.Errorf("Failed to create test database (%s) %v", dbType, err)
		return
	}
	defer os.RemoveAll(dbPath)
	defer db.Close()

	// Ensure the driver type is the expected value.
	gotDbType := db.Type()
	if gotDbType != dbType {
		t.Errorf("Type: unepxected driver type - got %v, want %v",
			gotDbType, dbType)
		return
	}

	// Run all of the interface tests against the database.
	runtime.GOMAXPROCS(runtime.NumCPU())

	// Change the maximum file size to a small value to force multiple flat
	// files with the test data set.
	ffldb.TstRunWithMaxBlockFileSize(db, 2048, func() {
		testInterface(t, db)
	})
}

示例#15
文件: e2e_service.go 项目: Clarifai/kubernetes

func (es *e2eService) stop() {
	if es.kubeletCmd != nil {
		err := es.kubeletCmd.Process.Kill()
		if err != nil {
			glog.Errorf("Failed to stop kubelet.\n%v", err)
		}
	}
	if es.kubeletStaticPodDir != "" {
		err := os.RemoveAll(es.kubeletStaticPodDir)
		if err != nil {
			glog.Errorf("Failed to delete kubelet static pod directory %s.\n%v", es.kubeletStaticPodDir, err)
		}
	}
	if es.apiServerCmd != nil {
		err := es.apiServerCmd.Process.Kill()
		if err != nil {
			glog.Errorf("Failed to stop kube-apiserver.\n%v", err)
		}
	}
	if es.etcdCmd != nil {
		err := es.etcdCmd.Process.Kill()
		if err != nil {
			glog.Errorf("Failed to stop etcd.\n%v", err)
		}
	}
	if es.etcdDataDir != "" {
		err := os.RemoveAll(es.etcdDataDir)
		if err != nil {
			glog.Errorf("Failed to delete etcd data directory %s.\n%v", es.etcdDataDir, err)
		}
	}
}

示例#16
文件: file_snapshot_test.go 项目: eswdd/bosun

func TestFileSS_CreateSnapshotMissingParentDir(t *testing.T) {
	parent, err := ioutil.TempDir("", "raft")
	if err != nil {
		t.Fatalf("err: %v ", err)
	}
	defer os.RemoveAll(parent)

	dir, err := ioutil.TempDir(parent, "raft")
	if err != nil {
		t.Fatalf("err: %v ", err)
	}

	snap, err := NewFileSnapshotStore(dir, 3, nil)
	if err != nil {
		t.Fatalf("err: %v", err)
	}

	os.RemoveAll(parent)
	peers := []byte("all my lovely friends")
	_, err = snap.Create(10, 3, peers)
	if err != nil {
		t.Fatalf("should not fail when using non existing parent")
	}

}

示例#17
文件: diff_test.go 项目: DaveDaCoda/docker

func makeTestLayer(paths []string) (rc io.ReadCloser, err error) {
	tmpDir, err := ioutil.TempDir("", "graphdriver-test-mklayer")
	if err != nil {
		return
	}
	defer func() {
		if err != nil {
			os.RemoveAll(tmpDir)
		}
	}()
	for _, p := range paths {
		if p[len(p)-1] == filepath.Separator {
			if err = os.MkdirAll(filepath.Join(tmpDir, p), 0700); err != nil {
				return
			}
		} else {
			if err = ioutil.WriteFile(filepath.Join(tmpDir, p), nil, 0600); err != nil {
				return
			}
		}
	}
	archive, err := Tar(tmpDir, Uncompressed)
	if err != nil {
		return
	}
	return ioutils.NewReadCloserWrapper(archive, func() error {
		err := archive.Close()
		os.RemoveAll(tmpDir)
		return err
	}), nil
}

示例#18
文件: store.go 项目: oiooj/influxdb

// DeleteDatabase will close all shards associated with a database and remove the directory and files from disk.
func (s *Store) DeleteDatabase(name string) error {
	s.mu.RLock()
	shards := s.filterShards(func(sh *Shard) bool {
		return sh.database == name
	})
	s.mu.RUnlock()

	if err := s.walkShards(shards, func(sh *Shard) error {
		if sh.database != name {
			return nil
		}

		return sh.Close()
	}); err != nil {
		return err
	}

	if err := os.RemoveAll(filepath.Join(s.path, name)); err != nil {
		return err
	}
	if err := os.RemoveAll(filepath.Join(s.EngineOptions.Config.WALDir, name)); err != nil {
		return err
	}

	s.mu.Lock()
	for _, sh := range shards {
		delete(s.shards, sh.id)
	}
	delete(s.databaseIndexes, name)
	s.mu.Unlock()

	return nil
}

示例#19
文件: client_test.go 项目: zendesk/consul

func TestClient_JoinLAN(t *testing.T) {
	dir1, s1 := testServer(t)
	defer os.RemoveAll(dir1)
	defer s1.Shutdown()

	dir2, c1 := testClient(t)
	defer os.RemoveAll(dir2)
	defer c1.Shutdown()

	// Try to join
	addr := fmt.Sprintf("127.0.0.1:%d",
		s1.config.SerfLANConfig.MemberlistConfig.BindPort)
	if _, err := c1.JoinLAN([]string{addr}); err != nil {
		t.Fatalf("err: %v", err)
	}

	// Check the members
	testutil.WaitForResult(func() (bool, error) {
		server_check := len(s1.LANMembers()) == 2
		client_check := len(c1.LANMembers()) == 2
		return server_check && client_check, nil
	}, func(err error) {
		t.Fatalf("bad len")
	})

	// Check we have a new consul
	testutil.WaitForResult(func() (bool, error) {
		return len(c1.consuls) == 1, nil
	}, func(err error) {
		t.Fatalf("expected consul server")
	})
}

示例#20
文件: local.go 项目: waterytowers/global-hack-day-3

// Remove removes the specified volume and all underlying data. If the
// given volume does not belong to this driver and an error is
// returned. The volume is reference counted, if all references are
// not released then the volume is not removed.
func (r *Root) Remove(v volume.Volume) error {
	r.m.Lock()
	defer r.m.Unlock()
	lv, ok := v.(*localVolume)
	if !ok {
		return errors.New("unknown volume type")
	}
	lv.release()
	if lv.usedCount == 0 {
		realPath, err := filepath.EvalSymlinks(lv.path)
		if err != nil {
			return err
		}
		if !r.scopedPath(realPath) {
			return fmt.Errorf("Unable to remove a directory of out the Docker root: %s", realPath)
		}

		if err := os.RemoveAll(realPath); err != nil {
			return err
		}

		delete(r.volumes, lv.name)
		return os.RemoveAll(filepath.Dir(lv.path))
	}
	return nil
}

示例#21
文件: db_test.go 项目: stoiclabs/blockchainr

func TestDb_CreateReopenDbOnFile(t *testing.T) {
	dbpath := filepath.Join(os.TempDir(), fmt.Sprintf("goleveldbtestCreateReopenDbOnFile-%d", os.Getuid()))
	if err := os.RemoveAll(dbpath); err != nil {
		t.Fatal("cannot remove old db: ", err)
	}
	defer os.RemoveAll(dbpath)

	for i := 0; i < 3; i++ {
		stor, err := storage.OpenFile(dbpath)
		if err != nil {
			t.Fatalf("(%d) cannot open storage: %s", i, err)
		}
		db, err := Open(stor, nil)
		if err != nil {
			t.Fatalf("(%d) cannot open db: %s", i, err)
		}
		if err := db.Put([]byte("foo"), []byte("bar"), nil); err != nil {
			t.Fatalf("(%d) cannot write to db: %s", i, err)
		}
		if err := db.Close(); err != nil {
			t.Fatalf("(%d) cannot close db: %s", i, err)
		}
		if err := stor.Close(); err != nil {
			t.Fatalf("(%d) cannot close storage: %s", i, err)
		}
	}
}

示例#22
文件: fix_test.go 项目: tsandall/opa

func (c testConfig) test(t *testing.T, fn func(*goimportTest)) {
	goroot := c.goroot
	gopath := c.gopath

	if c.gorootFiles != nil && goroot == "" {
		goroot = mustTempDir(t, "goroot-")
		defer os.RemoveAll(goroot)
	}
	if err := mapToDir(goroot, c.gorootFiles); err != nil {
		t.Fatal(err)
	}

	if c.gopathFiles != nil && gopath == "" {
		gopath = mustTempDir(t, "gopath-")
		defer os.RemoveAll(gopath)
	}
	if err := mapToDir(gopath, c.gopathFiles); err != nil {
		t.Fatal(err)
	}

	withEmptyGoPath(func() {
		if goroot != "" {
			build.Default.GOROOT = goroot
		}
		build.Default.GOPATH = gopath

		it := &goimportTest{
			T:      t,
			goroot: build.Default.GOROOT,
			gopath: gopath,
			ctx:    &build.Default,
		}
		fn(it)
	})
}

示例#23
文件: database_test.go 项目: kadirahq/kadiyadb

func TestTrack(t *testing.T) {
	if err := os.RemoveAll(dir); err != nil {
		t.Fatal(err)
	}
	if err := os.MkdirAll(dir, 0777); err != nil {
		t.Fatal(err)
	}

	p := &Params{
		Duration:    3600000000000,
		Retention:   36000000000000,
		Resolution:  60000000000,
		MaxROEpochs: 2,
		MaxRWEpochs: 2,
	}

	db, err := Open(dir, p)
	if err != nil {
		t.Fatal(err)
	}

	fields := []string{"a", "b", "d"}

	if err := db.Track(uint64(p.Resolution*0), fields, 5, 1); err != nil {
		t.Fatal(err)
	}
	if err := db.Track(uint64(p.Resolution*1), fields, 5, 2); err != nil {
		t.Fatal(err)
	}

	if err := os.RemoveAll(dir); err != nil {
		t.Fatal(err)
	}
}

示例#24
文件: graph_test.go 项目: nisaacson/docker

func TestMount(t *testing.T) {
	graph := tempGraph(t)
	defer os.RemoveAll(graph.Root)
	archive, err := fakeTar()
	if err != nil {
		t.Fatal(err)
	}
	image, err := graph.Create(archive, nil, "Testing", "", nil)
	if err != nil {
		t.Fatal(err)
	}
	tmp, err := ioutil.TempDir("", "docker-test-graph-mount-")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(tmp)
	rootfs := path.Join(tmp, "rootfs")
	if err := os.MkdirAll(rootfs, 0700); err != nil {
		t.Fatal(err)
	}
	rw := path.Join(tmp, "rw")
	if err := os.MkdirAll(rw, 0700); err != nil {
		t.Fatal(err)
	}
	if err := image.Mount(rootfs, rw); err != nil {
		t.Fatal(err)
	}
	// FIXME: test for mount contents
	defer func() {
		if err := Unmount(rootfs); err != nil {
			t.Error(err)
		}
	}()
}

示例#25
文件: archive_test.go 项目: truedays/docker

func checkNoChanges(fileNum int, hardlinks bool) error {
	srcDir, err := ioutil.TempDir("", "docker-test-srcDir")
	if err != nil {
		return err
	}
	defer os.RemoveAll(srcDir)

	destDir, err := ioutil.TempDir("", "docker-test-destDir")
	if err != nil {
		return err
	}
	defer os.RemoveAll(destDir)

	_, err = prepareUntarSourceDirectory(fileNum, srcDir, hardlinks)
	if err != nil {
		return err
	}

	err = TarUntar(srcDir, destDir)
	if err != nil {
		return err
	}

	changes, err := ChangesDirs(destDir, srcDir)
	if err != nil {
		return err
	}
	if len(changes) > 0 {
		return fmt.Errorf("with %d files and %v hardlinks: expected 0 changes, got %d", fileNum, hardlinks, len(changes))
	}
	return nil
}

示例#26
文件: catalog_endpoint_test.go 项目: jefferai/consul

func TestCatalogRegister_ForwardDC(t *testing.T) {
	dir1, s1 := testServer(t)
	defer os.RemoveAll(dir1)
	defer s1.Shutdown()
	client := rpcClient(t, s1)
	defer client.Close()

	dir2, s2 := testServerDC(t, "dc2")
	defer os.RemoveAll(dir2)
	defer s2.Shutdown()

	// Try to join
	addr := fmt.Sprintf("127.0.0.1:%d",
		s1.config.SerfWANConfig.MemberlistConfig.BindPort)
	if _, err := s2.JoinWAN([]string{addr}); err != nil {
		t.Fatalf("err: %v", err)
	}

	testutil.WaitForLeader(t, client.Call, "dc2")

	arg := structs.RegisterRequest{
		Datacenter: "dc2", // SHould forward through s1
		Node:       "foo",
		Address:    "127.0.0.1",
		Service: &structs.NodeService{
			Service: "db",
			Tags:    []string{"master"},
			Port:    8000,
		},
	}
	var out struct{}
	if err := client.Call("Catalog.Register", &arg, &out); err != nil {
		t.Fatalf("err: %v", err)
	}
}

示例#27
文件: client_test.go 项目: rayleyva/consul

func TestClient_JoinLAN(t *testing.T) {
	dir1, s1 := testServer(t)
	defer os.RemoveAll(dir1)
	defer s1.Shutdown()

	dir2, c1 := testClient(t)
	defer os.RemoveAll(dir2)
	defer c1.Shutdown()

	// Try to join
	addr := fmt.Sprintf("127.0.0.1:%d",
		s1.config.SerfLANConfig.MemberlistConfig.BindPort)
	if _, err := c1.JoinLAN([]string{addr}); err != nil {
		t.Fatalf("err: %v", err)
	}

	// Check the members
	if len(s1.LANMembers()) != 2 {
		t.Fatalf("bad len")
	}

	if len(c1.LANMembers()) != 2 {
		t.Fatalf("bad len")
	}

	time.Sleep(10 * time.Millisecond)

	// Check we have a new consul
	if len(c1.consuls) != 1 {
		t.Fatalf("expected consul server")
	}
}

示例#28
文件: store.go 项目: kyzh/influxdb

// DeleteShard removes a shard from disk.
func (s *Store) DeleteShard(shardID uint64) error {
	s.mu.Lock()
	defer s.mu.Unlock()

	// ensure shard exists
	sh, ok := s.shards[shardID]
	if !ok {
		return nil
	}

	if err := sh.Close(); err != nil {
		return err
	}

	if err := os.RemoveAll(sh.path); err != nil {
		return err
	}

	if err := os.RemoveAll(sh.walPath); err != nil {
		return err
	}

	delete(s.shards, shardID)

	return nil
}

示例#29
文件: aufs.go 项目: eldarion-gondor/cli

// useDirperm checks dirperm1 mount option can be used with the current
// version of aufs.
func useDirperm() bool {
	enableDirpermLock.Do(func() {
		base, err := ioutil.TempDir("", "docker-aufs-base")
		if err != nil {
			logrus.Errorf("error checking dirperm1: %v", err)
			return
		}
		defer os.RemoveAll(base)

		union, err := ioutil.TempDir("", "docker-aufs-union")
		if err != nil {
			logrus.Errorf("error checking dirperm1: %v", err)
			return
		}
		defer os.RemoveAll(union)

		opts := fmt.Sprintf("br:%s,dirperm1,xino=/dev/shm/aufs.xino", base)
		if err := mount("none", union, "aufs", 0, opts); err != nil {
			return
		}
		enableDirperm = true
		if err := Unmount(union); err != nil {
			logrus.Errorf("error checking dirperm1: failed to unmount %v", err)
		}
	})
	return enableDirperm
}

示例#30
文件: session_file_system_test.go 项目: golang-devops/go-psexec

func TestUploadTarFile(t *testing.T) {
	Convey("Test Uploading a tar directory", t, func() {
		testData, err := testing_utils.NewTestDataContainer("testdata/copy-files", 6)
		So(err, ShouldBeNil)

		tempRemoteBasePath, err := ioutil.TempDir(os.TempDir(), "gopsexec-client-test-")
		So(err, ShouldBeNil)
		defer os.RemoveAll(tempRemoteBasePath)

		sessionFileSystem, err := testingGetNewSessionFileSystem()
		So(err, ShouldBeNil)

		testData.ForeachRelativeFile(func(relFile string) {
			localFullFilePath := filepath.Join(testData.FullDir, relFile)
			fullTempRemotePath := filepath.Join(tempRemoteBasePath, relFile)

			So(fullTempRemotePath, more_goconvey_assertions.AssertFileExistance, false)

			fileTarProvider := tar_io.Factories.TarProvider.File(localFullFilePath)
			err = sessionFileSystem.UploadTar(fileTarProvider, fullTempRemotePath, false)
			So(err, ShouldBeNil)

			So(fullTempRemotePath, more_goconvey_assertions.AssertFileExistance, true)
			So(testing_utils.CheckFilePropertiesEqual(localFullFilePath, fullTempRemotePath), ShouldBeNil)
		})

		err = os.RemoveAll(tempRemoteBasePath)
		So(err, ShouldBeNil)
		So(tempRemoteBasePath, more_goconvey_assertions.AssertDirectoryExistance, false)
		testData.ForeachRelativeFile(func(relFile string) {
			fullTempRemotePath := filepath.Join(tempRemoteBasePath, relFile)
			So(fullTempRemotePath, more_goconvey_assertions.AssertFileExistance, false)
		})
	})
}

展开阅读全文