本文整理匯總了Golang中github.com/heketi/tests.Assert函數的典型用法代碼示例。如果您正苦於以下問題:Golang Assert函數的具體用法?Golang Assert怎麽用?Golang Assert使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Assert函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
示例2: TestReplicaDurabilityDefaults
func TestReplicaDurabilityDefaults(t *testing.T) {
r := &ReplicaDurability{}
tests.Assert(t, r.Replica == 0)
r.SetDurability()
tests.Assert(t, r.Replica == DEFAULT_REPLICA)
}
示例3: 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"))
}
示例4: 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"))
}
示例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: 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))
}
示例7: 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))
}
示例8: TestNoneDurabilityDefaults
func TestNoneDurabilityDefaults(t *testing.T) {
r := &NoneDurability{}
tests.Assert(t, r.Replica == 0)
r.SetDurability()
tests.Assert(t, r.Replica == 1)
}
示例9: 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)
}
示例10: 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))
}
示例11: 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)
}
示例12: setupCluster
func setupCluster(t *testing.T) {
tests.Assert(t, heketi != nil)
nodespercluster := NODES / CLUSTERS
nodes := getnodes()
sg := utils.NewStatusGroup()
for cluster := 0; cluster < CLUSTERS; cluster++ {
sg.Add(1)
go func(nodes_in_cluster []string) {
defer sg.Done()
// Create a cluster
cluster, err := heketi.ClusterCreate()
if err != nil {
logger.Err(err)
sg.Err(err)
return
}
// Add nodes sequentially due to probes
for index, hostname := range nodes_in_cluster {
nodeReq := &glusterfs.NodeAddRequest{}
nodeReq.ClusterId = cluster.Id
nodeReq.Hostnames.Manage = []string{hostname}
nodeReq.Hostnames.Storage = []string{hostname}
nodeReq.Zone = index%ZONES + 1
node, err := heketi.NodeAdd(nodeReq)
if err != nil {
logger.Err(err)
sg.Err(err)
return
}
// Add devices all concurrently
for _, disk := range getdisks() {
sg.Add(1)
go func(d string) {
defer sg.Done()
driveReq := &glusterfs.DeviceAddRequest{}
driveReq.Name = d
driveReq.Weight = 100
driveReq.NodeId = node.Id
err := heketi.DeviceAdd(driveReq)
if err != nil {
logger.Err(err)
sg.Err(err)
}
}(disk)
}
}
}(nodes[cluster*nodespercluster : (cluster+1)*nodespercluster])
}
// Wait here for results
err := sg.Result()
tests.Assert(t, err == nil)
}
示例13: 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)
}
示例14: TestNewSimpleAllocator
func TestNewSimpleAllocator(t *testing.T) {
a := NewSimpleAllocator()
tests.Assert(t, a != nil)
tests.Assert(t, a.rings != nil)
}
示例15: TestNewNodeEntryMarshal
func TestNewNodeEntryMarshal(t *testing.T) {
req := &api.NodeAddRequest{
ClusterId: "123",
Hostnames: api.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))
}