本文整理匯總了Golang中github.com/heketi/heketi/tests.Assert函數的典型用法代碼示例。如果您正苦於以下問題:Golang Assert函數的具體用法?Golang Assert怎麽用?Golang Assert使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Assert函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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, BRICK_MAX_NUM-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)
}
示例2: TestNoneDurabilityDefaults
func TestNoneDurabilityDefaults(t *testing.T) {
r := &NoneDurability{}
tests.Assert(t, r.Replica == 0)
r.SetDurability()
tests.Assert(t, r.Replica == 1)
}
示例3: 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"))
}
示例4: TestGlusterFSDBFileLoad
func TestGlusterFSDBFileLoad(t *testing.T) {
tmpfile := tests.Tempfile()
defer os.Remove(tmpfile)
db := NewGlusterFSDB(tmpfile)
db.nodes["one"] = &NodeEntry{
Info: requests.NodeInfoResp{
Name: "nodetest",
},
}
db.volumes["a"] = &VolumeEntry{
Info: requests.VolumeInfoResp{
Name: "volumetest",
},
}
err := db.Commit()
tests.Assert(t, err == nil)
newdb := NewGlusterFSDB(tmpfile)
tests.Assert(t, newdb != nil)
tests.Assert(t, newdb.nodes["one"].Info.Name == db.nodes["one"].Info.Name)
tests.Assert(t, newdb.volumes["a"].Info.Name == db.volumes["a"].Info.Name)
}
示例5: 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)
}
示例6: TestNewStatusGroup
func TestNewStatusGroup(t *testing.T) {
s := NewStatusGroup()
tests.Assert(t, s != nil)
tests.Assert(t, s.results != nil)
tests.Assert(t, len(s.results) == 0)
tests.Assert(t, s.err == nil)
}
示例7: TestNewDeviceEntryMarshal
func TestNewDeviceEntryMarshal(t *testing.T) {
req := &Device{
Name: "dev",
Weight: 123,
}
nodeid := "abc"
d := NewDeviceEntryFromRequest(req, nodeid)
d.Info.Storage.Free = 10
d.Info.Storage.Total = 100
d.Info.Storage.Used = 1000
d.BrickAdd("abc")
d.BrickAdd("def")
buffer, err := d.Marshal()
tests.Assert(t, err == nil)
tests.Assert(t, buffer != nil)
tests.Assert(t, len(buffer) > 0)
um := &DeviceEntry{}
err = um.Unmarshal(buffer)
tests.Assert(t, err == nil)
tests.Assert(t, reflect.DeepEqual(um, d))
}
示例8: TestNewSimpleAllocator
func TestNewSimpleAllocator(t *testing.T) {
a := NewSimpleAllocator()
tests.Assert(t, a != nil)
tests.Assert(t, a.rings != nil)
}
示例9: TestReplicaDurabilityDefaults
func TestReplicaDurabilityDefaults(t *testing.T) {
r := &ReplicaDurability{}
tests.Assert(t, r.Replica == 0)
r.SetDurability()
tests.Assert(t, r.Replica == DEFAULT_REPLICA)
}
示例10: 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))
}
示例11: 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))
}
示例12: 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"))
}
示例13: TestDisperseDurability
func TestDisperseDurability(t *testing.T) {
r := &DisperseDurability{
Data: 8,
Redundancy: 3,
}
gen := r.BrickSizeGenerator(200 * GB)
// Gen 1
sets, brick_size, err := gen()
tests.Assert(t, err == nil)
tests.Assert(t, sets == 2)
tests.Assert(t, brick_size == uint64(100*GB/8))
tests.Assert(t, 8+3 == r.BricksInSet())
// Gen 2
sets, brick_size, err = gen()
tests.Assert(t, err == nil)
tests.Assert(t, sets == 4)
tests.Assert(t, brick_size == uint64(50*GB/8))
tests.Assert(t, 8+3 == r.BricksInSet())
// Gen 3
sets, brick_size, err = gen()
tests.Assert(t, err == ErrMininumBrickSize)
tests.Assert(t, 8+3 == r.BricksInSet())
}
示例14: TestNodeAddHandler
func TestNodeAddHandler(t *testing.T) {
var msg requests.NodeInfoResp
// Instead of coding our own JSON here,
// create the JSON message as a string to test the handler
request := []byte(`{
"name" : "test_name",
"zone" : 12345
}`)
n := NewNodeServer(mock.NewMockPlugin())
ts := httptest.NewServer(http.HandlerFunc(n.NodeAddHandler))
defer ts.Close()
// Request
r, err := http.Post(ts.URL, "application/json", bytes.NewBuffer(request))
tests.Assert(t, r.StatusCode == http.StatusCreated)
tests.Assert(t, err == nil)
// Check body
err = utils.GetJsonFromResponse(r, &msg)
tests.Assert(t, err == nil)
tests.Assert(t, msg.Name == "test_name")
tests.Assert(t, msg.Zone == 12345)
}
示例15: TestNewNodeEntryMarshal
func TestNewNodeEntryMarshal(t *testing.T) {
req := &NodeAddRequest{
ClusterId: "123",
Hostnames: HostAddresses{
Manage: []string{"manage"},
Storage: []string{"storage"},
},
Zone: 99,
}
n := NewNodeEntryFromRequest(req)
n.DeviceAdd("abc")
n.DeviceAdd("def")
buffer, err := n.Marshal()
tests.Assert(t, err == nil)
tests.Assert(t, buffer != nil)
tests.Assert(t, len(buffer) > 0)
um := &NodeEntry{}
err = um.Unmarshal(buffer)
tests.Assert(t, err == nil)
tests.Assert(t, reflect.DeepEqual(n, um))
}