本文整理匯總了Golang中github.com/heketi/tests.Tempfile函數的典型用法代碼示例。如果您正苦於以下問題:Golang Tempfile函數的具體用法?Golang Tempfile怎麽用?Golang Tempfile使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Tempfile函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestVolumeListEmpty
func TestVolumeListEmpty(t *testing.T) {
tmpfile := tests.Tempfile()
defer os.Remove(tmpfile)
// Create the app
app := NewTestApp(tmpfile)
defer app.Close()
router := mux.NewRouter()
app.SetRoutes(router)
// Setup the server
ts := httptest.NewServer(router)
defer ts.Close()
// Get volumes, there should be none
r, err := http.Get(ts.URL + "/volumes")
tests.Assert(t, r.StatusCode == http.StatusOK)
tests.Assert(t, err == nil)
tests.Assert(t, r.Header.Get("Content-Type") == "application/json; charset=UTF-8")
// Read response
var msg VolumeListResponse
err = utils.GetJsonFromResponse(r, &msg)
tests.Assert(t, err == nil)
tests.Assert(t, len(msg.Volumes) == 0)
}
示例2: TestVolumeCreateSmallSize
func TestVolumeCreateSmallSize(t *testing.T) {
tmpfile := tests.Tempfile()
defer os.Remove(tmpfile)
// Create the app
app := NewTestApp(tmpfile)
defer app.Close()
router := mux.NewRouter()
app.SetRoutes(router)
// Setup the server
ts := httptest.NewServer(router)
defer ts.Close()
// VolumeCreate JSON Request
request := []byte(`{
"size" : 0
}`)
// Send request
r, err := http.Post(ts.URL+"/volumes", "application/json", bytes.NewBuffer(request))
tests.Assert(t, err == nil)
tests.Assert(t, r.StatusCode == http.StatusBadRequest)
body, err := ioutil.ReadAll(io.LimitReader(r.Body, r.ContentLength))
tests.Assert(t, err == nil)
r.Body.Close()
tests.Assert(t, strings.Contains(string(body), "Invalid volume size"))
}
示例3: TestVolumeEntryExpandMaxBrickLimit
func TestVolumeEntryExpandMaxBrickLimit(t *testing.T) {
tmpfile := tests.Tempfile()
defer os.Remove(tmpfile)
// Create the app
app := NewTestApp(tmpfile)
defer app.Close()
// Create a large cluster
err := setupSampleDbWithTopology(app,
10, // clusters
4, // nodes_per_cluster
24, // devices_per_node,
600*GB, // disksize)
)
tests.Assert(t, err == nil)
// Create large volume
v := createSampleVolumeEntry(100)
err = v.Create(app.db, app.executor, app.allocator)
tests.Assert(t, err == nil)
// Add a bunch of bricks until the limit
fakebricks := make(sort.StringSlice, BrickMaxNum-len(v.Bricks))
v.Bricks = append(v.Bricks, fakebricks...)
// Try to expand the volume, but it will return that the max number
// of bricks has been reached
err = v.Expand(app.db, app.executor, app.allocator, 100)
tests.Assert(t, err == ErrMaxBricks, err)
}
示例4: TestAppAdvsettings
func TestAppAdvsettings(t *testing.T) {
dbfile := tests.Tempfile()
defer os.Remove(dbfile)
os.Setenv("HEKETI_EXECUTOR", "mock")
defer os.Unsetenv("HEKETI_EXECUTOR")
data := []byte(`{
"glusterfs" : {
"executor" : "crazyexec",
"allocator" : "simple",
"db" : "` + dbfile + `",
"brick_max_size_gb" : 1024,
"brick_min_size_gb" : 1,
"max_bricks_per_volume" : 33
}
}`)
bmax, bmin, bnum := BrickMaxSize, BrickMinSize, BrickMaxNum
defer func() {
BrickMaxSize, BrickMinSize, BrickMaxNum = bmax, bmin, bnum
}()
app := NewApp(bytes.NewReader(data))
tests.Assert(t, app != nil)
tests.Assert(t, app.conf.Executor == "mock")
tests.Assert(t, BrickMaxNum == 33)
tests.Assert(t, BrickMaxSize == 1*TB)
tests.Assert(t, BrickMinSize == 1*GB)
}
示例5: TestVolumeEntryNameConflictMultiCluster
func TestVolumeEntryNameConflictMultiCluster(t *testing.T) {
tmpfile := tests.Tempfile()
defer os.Remove(tmpfile)
// Create the app
app := NewTestApp(tmpfile)
defer app.Close()
// Create 10 clusters
err := setupSampleDbWithTopology(app,
10, // clusters
3, // nodes_per_cluster
6, // devices_per_node,
6*TB, // disksize)
)
tests.Assert(t, err == nil)
// Create 10 volumes
for i := 0; i < 10; i++ {
v := createSampleVolumeEntry(1024)
v.Info.Name = "myvol"
err = v.Create(app.db, app.executor, app.allocator)
tests.Assert(t, err == nil)
}
// Create another volume same name
v := createSampleVolumeEntry(10000)
v.Info.Name = "myvol"
err = v.Create(app.db, app.executor, app.allocator)
tests.Assert(t, err != nil, err)
}
示例6: TestVolumeEntryDoNotAllowDeviceOnSameNode
func TestVolumeEntryDoNotAllowDeviceOnSameNode(t *testing.T) {
tmpfile := tests.Tempfile()
defer os.Remove(tmpfile)
// Create the app
app := NewTestApp(tmpfile)
defer app.Close()
// Create cluster with plenty of space, but
// it will not have enough nodes
err := setupSampleDbWithTopology(app,
1, // clusters
1, // nodes_per_cluster
200, // devices_per_node,
6*TB, // disksize)
)
tests.Assert(t, err == nil)
// Create volume
v := createSampleVolumeEntry(100)
err = v.Create(app.db, app.executor, app.allocator)
tests.Assert(t, err != nil, err)
tests.Assert(t, err == ErrNoSpace)
v = createSampleVolumeEntry(10000)
err = v.Create(app.db, app.executor, app.allocator)
tests.Assert(t, err != nil, err)
tests.Assert(t, err == ErrNoSpace)
}
示例7: TestNewBrickEntryFromId
func TestNewBrickEntryFromId(t *testing.T) {
tmpfile := tests.Tempfile()
defer os.Remove(tmpfile)
// Create the app
app := NewTestApp(tmpfile)
defer app.Close()
// Create a brick
b := NewBrickEntry(10, 20, 5, "abc", "def")
// Save element in database
err := app.db.Update(func(tx *bolt.Tx) error {
return b.Save(tx)
})
tests.Assert(t, err == nil)
var brick *BrickEntry
err = app.db.View(func(tx *bolt.Tx) error {
var err error
brick, err = NewBrickEntryFromId(tx, b.Info.Id)
return err
})
tests.Assert(t, err == nil)
tests.Assert(t, reflect.DeepEqual(brick, b))
}
示例8: TestNewBrickEntryNewInfoResponse
func TestNewBrickEntryNewInfoResponse(t *testing.T) {
tmpfile := tests.Tempfile()
defer os.Remove(tmpfile)
// Create the app
app := NewTestApp(tmpfile)
defer app.Close()
// Create a brick
b := NewBrickEntry(10, 20, 5, "abc", "def")
// Save element in database
err := app.db.Update(func(tx *bolt.Tx) error {
return b.Save(tx)
})
tests.Assert(t, err == nil)
var info *api.BrickInfo
err = app.db.View(func(tx *bolt.Tx) error {
brick, err := NewBrickEntryFromId(tx, b.Id())
if err != nil {
return err
}
info, err = brick.NewInfoResponse(tx)
return err
})
tests.Assert(t, err == nil)
tests.Assert(t, reflect.DeepEqual(*info, b.Info))
}
示例9: TestVolumeEntryFromId
func TestVolumeEntryFromId(t *testing.T) {
tmpfile := tests.Tempfile()
defer os.Remove(tmpfile)
// Create the app
app := NewTestApp(tmpfile)
defer app.Close()
// Create a volume entry
v := createSampleVolumeEntry(1024)
// Save in database
err := app.db.Update(func(tx *bolt.Tx) error {
return v.Save(tx)
})
tests.Assert(t, err == nil)
// Load from database
var entry *VolumeEntry
err = app.db.View(func(tx *bolt.Tx) error {
var err error
entry, err = NewVolumeEntryFromId(tx, v.Info.Id)
return err
})
tests.Assert(t, err == nil)
tests.Assert(t, reflect.DeepEqual(entry, v))
}
示例10: TestVolumeExpandIdNotFound
func TestVolumeExpandIdNotFound(t *testing.T) {
tmpfile := tests.Tempfile()
defer os.Remove(tmpfile)
// Create the app
app := NewTestApp(tmpfile)
defer app.Close()
router := mux.NewRouter()
app.SetRoutes(router)
// Setup the server
ts := httptest.NewServer(router)
defer ts.Close()
// JSON Request
request := []byte(`{
"expand_size" : 100
}`)
// Now that we have some data in the database, we can
// make a request for the clutser list
r, err := http.Post(ts.URL+"/volumes/12345/expand",
"application/json",
bytes.NewBuffer(request))
tests.Assert(t, err == nil)
tests.Assert(t, r.StatusCode == http.StatusNotFound, r.StatusCode)
body, err := ioutil.ReadAll(io.LimitReader(r.Body, r.ContentLength))
tests.Assert(t, err == nil)
r.Body.Close()
tests.Assert(t, strings.Contains(string(body), "Id not found"))
}
示例11: TestClientCluster
func TestClientCluster(t *testing.T) {
db := tests.Tempfile()
defer os.Remove(db)
// Create the app
app := glusterfs.NewTestApp(db)
defer app.Close()
// Setup the server
ts := setupHeketiServer(app)
defer ts.Close()
// Create cluster with unknown user
c := NewClient(ts.URL, "asdf", "")
tests.Assert(t, c != nil)
cluster, err := c.ClusterCreate()
tests.Assert(t, err != nil)
tests.Assert(t, cluster == nil)
// Create cluster with bad password
c = NewClient(ts.URL, "admin", "badpassword")
tests.Assert(t, c != nil)
cluster, err = c.ClusterCreate()
tests.Assert(t, err != nil)
tests.Assert(t, cluster == nil)
// Create cluster correctly
c = NewClient(ts.URL, "admin", TEST_ADMIN_KEY)
tests.Assert(t, c != nil)
cluster, err = c.ClusterCreate()
tests.Assert(t, err == nil)
tests.Assert(t, cluster.Id != "")
tests.Assert(t, len(cluster.Nodes) == 0)
tests.Assert(t, len(cluster.Volumes) == 0)
// Request bad id
info, err := c.ClusterInfo("bad")
tests.Assert(t, err != nil)
tests.Assert(t, info == nil)
// Get information about the client
info, err = c.ClusterInfo(cluster.Id)
tests.Assert(t, err == nil)
tests.Assert(t, reflect.DeepEqual(info, cluster))
// Get a list of clusters
list, err := c.ClusterList()
tests.Assert(t, err == nil)
tests.Assert(t, len(list.Clusters) == 1)
tests.Assert(t, list.Clusters[0] == info.Id)
// Delete non-existent cluster
err = c.ClusterDelete("badid")
tests.Assert(t, err != nil)
// Delete current cluster
err = c.ClusterDelete(info.Id)
tests.Assert(t, err == nil)
}
示例12: TestAppLogLevel
func TestAppLogLevel(t *testing.T) {
dbfile := tests.Tempfile()
defer os.Remove(dbfile)
levels := []string{
"none",
"critical",
"error",
"warning",
"info",
"debug",
}
logger.SetLevel(utils.LEVEL_DEBUG)
for _, level := range levels {
data := []byte(`{
"glusterfs" : {
"executor" : "mock",
"allocator" : "simple",
"db" : "` + dbfile + `",
"loglevel" : "` + level + `"
}
}`)
app := NewApp(bytes.NewReader(data))
tests.Assert(t, app != nil, level, string(data))
switch level {
case "none":
tests.Assert(t, logger.Level() == utils.LEVEL_NOLOG)
case "critical":
tests.Assert(t, logger.Level() == utils.LEVEL_CRITICAL)
case "error":
tests.Assert(t, logger.Level() == utils.LEVEL_ERROR)
case "warning":
tests.Assert(t, logger.Level() == utils.LEVEL_WARNING)
case "info":
tests.Assert(t, logger.Level() == utils.LEVEL_INFO)
case "debug":
tests.Assert(t, logger.Level() == utils.LEVEL_DEBUG)
}
app.Close()
}
// Test that an unknown value does not change the loglevel
logger.SetLevel(utils.LEVEL_NOLOG)
data := []byte(`{
"glusterfs" : {
"executor" : "mock",
"allocator" : "simple",
"db" : "` + dbfile + `",
"loglevel" : "blah"
}
}`)
app := NewApp(bytes.NewReader(data))
tests.Assert(t, app != nil)
tests.Assert(t, logger.Level() == utils.LEVEL_NOLOG)
}
示例13: TestVolumeDelete
func TestVolumeDelete(t *testing.T) {
tmpfile := tests.Tempfile()
defer os.Remove(tmpfile)
// Create the app
app := NewTestApp(tmpfile)
defer app.Close()
router := mux.NewRouter()
app.SetRoutes(router)
// Setup the server
ts := httptest.NewServer(router)
defer ts.Close()
// Setup database
err := setupSampleDbWithTopology(app,
1, // clusters
10, // nodes_per_cluster
10, // devices_per_node,
5*TB, // disksize)
)
tests.Assert(t, err == nil)
// Create a volume
v := createSampleVolumeEntry(100)
tests.Assert(t, v != nil)
err = v.Create(app.db, app.executor, app.allocator)
tests.Assert(t, err == nil)
// Delete the volume
req, err := http.NewRequest("DELETE", ts.URL+"/volumes/"+v.Info.Id, nil)
tests.Assert(t, err == nil)
r, err := http.DefaultClient.Do(req)
tests.Assert(t, err == nil)
tests.Assert(t, r.StatusCode == http.StatusAccepted)
location, err := r.Location()
tests.Assert(t, err == nil)
// Query queue until finished
for {
r, err = http.Get(location.String())
tests.Assert(t, err == nil)
if r.Header.Get("X-Pending") == "true" {
tests.Assert(t, r.StatusCode == http.StatusOK)
time.Sleep(time.Millisecond * 10)
continue
} else {
tests.Assert(t, r.StatusCode == http.StatusNoContent)
tests.Assert(t, err == nil)
break
}
}
// Check it is not there
r, err = http.Get(ts.URL + "/volumes/" + v.Info.Id)
tests.Assert(t, r.StatusCode == http.StatusNotFound)
tests.Assert(t, err == nil)
}
示例14: TestVolumeList
func TestVolumeList(t *testing.T) {
tmpfile := tests.Tempfile()
defer os.Remove(tmpfile)
// Create the app
app := NewTestApp(tmpfile)
defer app.Close()
router := mux.NewRouter()
app.SetRoutes(router)
// Setup the server
ts := httptest.NewServer(router)
defer ts.Close()
// Create some volumes
numvolumes := 1000
err := app.db.Update(func(tx *bolt.Tx) error {
for i := 0; i < numvolumes; i++ {
v := createSampleVolumeEntry(100)
err := v.Save(tx)
if err != nil {
return err
}
}
return nil
})
tests.Assert(t, err == nil)
// Get volumes, there should be none
r, err := http.Get(ts.URL + "/volumes")
tests.Assert(t, r.StatusCode == http.StatusOK)
tests.Assert(t, err == nil)
tests.Assert(t, r.Header.Get("Content-Type") == "application/json; charset=UTF-8")
// Read response
var msg VolumeListResponse
err = utils.GetJsonFromResponse(r, &msg)
tests.Assert(t, err == nil)
tests.Assert(t, len(msg.Volumes) == numvolumes)
// Check that all the volumes are in the database
err = app.db.View(func(tx *bolt.Tx) error {
for _, id := range msg.Volumes {
_, err := NewVolumeEntryFromId(tx, id)
if err != nil {
return err
}
}
return nil
})
tests.Assert(t, err == nil)
}
示例15: TestVolumeCreateBadDispersionValues
func TestVolumeCreateBadDispersionValues(t *testing.T) {
tmpfile := tests.Tempfile()
defer os.Remove(tmpfile)
// Create the app
app := NewTestApp(tmpfile)
defer app.Close()
router := mux.NewRouter()
app.SetRoutes(router)
// Setup the server
ts := httptest.NewServer(router)
defer ts.Close()
// VolumeCreate JSON Request
request := []byte(`{
"size" : 100,
"durability": {
"type": "disperse",
"disperse": {
"data" : 8,
"redundancy" : 1
}
}
}`)
// Send request
r, err := http.Post(ts.URL+"/volumes", "application/json", bytes.NewBuffer(request))
tests.Assert(t, err == nil)
tests.Assert(t, r.StatusCode == http.StatusBadRequest)
body, err := ioutil.ReadAll(io.LimitReader(r.Body, r.ContentLength))
tests.Assert(t, err == nil)
r.Body.Close()
tests.Assert(t, strings.Contains(string(body), "Invalid dispersion combination"))
// VolumeCreate JSON Request
request = []byte(`{
"size" : 100,
"durability": {
"type": "disperse",
"disperse": {
"data" : 4,
"redundancy" : 3
}
}
}`)
// Send request
r, err = http.Post(ts.URL+"/volumes", "application/json", bytes.NewBuffer(request))
tests.Assert(t, err == nil)
tests.Assert(t, r.StatusCode == http.StatusBadRequest)
body, err = ioutil.ReadAll(io.LimitReader(r.Body, r.ContentLength))
tests.Assert(t, err == nil)
r.Body.Close()
tests.Assert(t, strings.Contains(string(body), "Invalid dispersion combination"))
}