func NewObjectMapper(c *config.Config) (*ObjectMapper, error) { var err error swift := openstack.NewSwift(c) if err = swift.Auth(); err != nil { return nil, err } if c.CreateContainer { if err = swift.CreateContainer(); err != nil { return nil, err } } else { _, err := swift.GetContainer() if err != nil { return nil, fmt.Errorf("Container \"%s\" not found", c.ContainerName) } } m := &ObjectMapper{ objects: map[string]*object{}, swift: swift, objectCacheTime: c.ObjectCacheTime, lastCached: time.Now(), } m.syncObjects() return m, nil }
func mount() error { var err error if fs != nil || server != nil { // already mounting return nil } // create mountpoint os.Mkdir(TEST_MOUNTPOINT, 0777) // config config := &config.Config{ MountPoint: TEST_MOUNTPOINT, ContainerName: TEST_CONTAINER_NAME, CreateContainer: true, Debug: true, NoDaemon: true, } // swift swift := openstack.NewSwift(config) if err = swift.Auth(); err != nil { return err } swift.DeleteContainer() // mapper mapper, err := mapper.NewObjectMapper(config) if err != nil { return err } // initialize filesystem fs = NewObjectFileSystem(config, mapper) path := pathfs.NewPathNodeFs(fs, nil) con := nodefs.NewFileSystemConnector(path.Root(), &nodefs.Options{}) opts := &fuse.MountOptions{ Name: "test-filesystem", FsName: "test-filesystem", } // create server and do mount with dedicated goroutine server, err = fuse.NewServer(con.RawFS(), TEST_MOUNTPOINT, opts) if err != nil { return err } go func() { server.Serve() }() server.WaitMount() return nil }
func initSwift() error { c := config.NewConfig() c.ContainerName = TEST_CONTAINER // initialize swift var err error swift = openstack.NewSwift(c) if err = swift.Auth(); err != nil { return err } if err = swift.DeleteContainer(); err != nil { // 404 } if err = swift.CreateContainer(); err != nil { return err } return nil }
func TestSetup(t *testing.T) { var err error c := config.NewConfig() c.MountPoint = TEST_MOUNTPOINT c.ContainerName = TEST_CONTAINER_NAME c.CreateContainer = true c.Debug = true c.NoDaemon = true // initialize swift and uplaod testdata swift := openstack.NewSwift(c) if err = swift.Auth(); err != nil { t.Fatalf("%v", err) } swift.DeleteContainer() swift.CreateContainer() // mapper mp, err := mapper.NewObjectMapper(c) if err != nil { t.Fatalf("%v", err) } obj, err := mp.Create(TEST_OBJECT_NAME) if err != nil { t.Fatalf("%v", err) } file, err := obj.Open(os.O_CREATE|os.O_WRONLY, 0666) if err != nil { t.Fatalf("%v", err) } _, err = file.WriteString(TEST_DATA) if err != nil { t.Fatalf("%v", err) } file.Close() // initialize ObjectFile objfile = NewObjectFile(TEST_OBJECT_NAME, obj) }