本文整理匯總了Golang中github.com/elleFlorio/gru/Godeps/_workspace/src/github.com/stretchr/testify/assert.Error函數的典型用法代碼示例。如果您正苦於以下問題:Golang Error函數的具體用法?Golang Error怎麽用?Golang Error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Error函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestGetCompleteRange
func TestGetCompleteRange(t *testing.T) {
var err error
var result []string
invalid := "pippo"
invalidLimit := "pippo-10"
onveValue := "5"
valid := "0-10"
_, err = GetCompleteRange(invalid)
assert.Error(t, err)
_, err = GetCompleteRange(invalidLimit)
assert.Error(t, err)
result, err = GetCompleteRange(onveValue)
assert.NoError(t, err)
assert.Len(t, result, 1)
assert.Contains(t, result, "5")
result, err = GetCompleteRange(valid)
assert.NoError(t, err)
assert.Len(t, result, 11)
assert.Contains(t, result, "0")
assert.Contains(t, result, "10")
assert.NotContains(t, result, "11")
}
示例2: TestChooseRandomFriends
func TestChooseRandomFriends(t *testing.T) {
cfg.SetNode(node.CreateMockNode())
mockPeers := createMockPeers(100)
nFriends := 10
test, err := chooseRandomFriends(mockPeers, nFriends)
assert.NoError(t, err, "(nFrineds > 0) Choose friends should produce no error")
nFriends = 150
test, err = chooseRandomFriends(mockPeers, nFriends)
friendsKeys := make([]string, 0, len(mockPeers)-1)
for key, _ := range test {
friendsKeys = append(friendsKeys, key)
}
assert.NoError(t, err, "(nFrineds > nPeers) Choose friends should produce no error")
nFriends = 0
test, err = chooseRandomFriends(mockPeers, nFriends)
assert.Error(t, err, "(nFriends < 0) Choose friends should produce an error")
mockPeers = createMockPeers(0)
nFriends = 10
_, err = chooseRandomFriends(mockPeers, nFriends)
assert.Error(t, err, "(peers = 0) Choose friend should produce an error")
mockPeers = createMockPeers(1)
nFriends = 10
_, err = chooseRandomFriends(mockPeers, nFriends)
assert.Error(t, err, "(peers = me) Choose friend should produce an error")
mockPeers = createMockPeers(2)
nFriends = 10
test, err = chooseRandomFriends(mockPeers, nFriends)
assert.NoError(t, err, "(nFrineds == 2) Choose friends should produce no error")
}
示例3: TestChangeServiceInstanceStatus
func TestChangeServiceInstanceStatus(t *testing.T) {
defer cfg.CleanServices()
cfg.SetServices(CreateMockServices())
name := "service1"
service, _ := GetServiceByName(name)
instance := "instance1_3"
var prev enum.Status
var upd enum.Status
var err error
prev = enum.PENDING
upd = enum.RUNNING
err = ChangeServiceInstanceStatus(name, instance, prev, upd)
assert.NotContains(t, service.Instances.Pending, instance)
assert.Contains(t, service.Instances.Running, instance)
assert.NoError(t, err)
prev = enum.RUNNING
upd = enum.PAUSED
err = ChangeServiceInstanceStatus(name, instance, prev, upd)
assert.NotContains(t, service.Instances.Running, instance)
assert.Contains(t, service.Instances.Paused, instance)
assert.NoError(t, err)
prev = enum.PAUSED
upd = enum.STOPPED
err = ChangeServiceInstanceStatus(name, instance, prev, upd)
assert.NotContains(t, service.Instances.Paused, instance)
assert.Contains(t, service.Instances.Stopped, instance)
assert.NoError(t, err)
prev = enum.STOPPED
upd = enum.PENDING
err = ChangeServiceInstanceStatus(name, instance, prev, upd)
assert.NotContains(t, service.Instances.Stopped, instance)
assert.Contains(t, service.Instances.Pending, instance)
assert.NoError(t, err)
prev = enum.PENDING
upd = enum.RUNNING
err = ChangeServiceInstanceStatus("pippo", instance, prev, upd)
assert.Error(t, err)
prev = enum.PENDING
upd = enum.RUNNING
err = ChangeServiceInstanceStatus(name, "pippo", prev, upd)
assert.Error(t, err)
}
示例4: TestRequestPortsForService
func TestRequestPortsForService(t *testing.T) {
defer clearServicePorts()
var err error
createServicePorts()
service := "pippo"
port1 := "50100"
port2 := "50200"
result, err := RequestPortsForService(service)
assert.NoError(t, err)
assert.Len(t, result, 2)
assert.Len(t, resources.Network.ServicePorts[service].LastRequested, 2)
available1 := resources.Network.ServicePorts[service].Status[port1].Available
occupied1 := resources.Network.ServicePorts[service].Status[port1].Occupied
assert.Len(t, available1, 4)
assert.Len(t, occupied1, 0)
available2 := resources.Network.ServicePorts[service].Status[port2].Available
occupied2 := resources.Network.ServicePorts[service].Status[port2].Occupied
assert.Len(t, available2, 2)
assert.Len(t, occupied2, 0)
ports := resources.Network.ServicePorts[service]
status := ports.Status[port1]
status.Available = []string{}
ports.Status[port1] = status
resources.Network.ServicePorts[service] = ports
_, err = RequestPortsForService(service)
assert.Error(t, err)
assert.Empty(t, resources.Network.ServicePorts[service].LastRequested)
}
示例5: TestNew
func TestNew(t *testing.T) {
notSupported := "notSupported"
dscvr, err := New(notSupported, "http://localhost:5000")
assert.Error(t, err)
assert.Equal(t, "noservice", dscvr.Name())
}
示例6: TestAddServiceInstance
func TestAddServiceInstance(t *testing.T) {
defer cfg.CleanServices()
cfg.SetServices(CreateMockServices())
name := "service1"
service, _ := GetServiceByName(name)
instance_p := "instance1_100"
instance_ps := "instance1_101"
instance_s := "instance1_102"
var err error
var status enum.Status
status = enum.PENDING
err = AddServiceInstance(name, instance_p, status)
assert.NoError(t, err)
assert.Contains(t, service.Instances.All, instance_p)
assert.Contains(t, service.Instances.Pending, instance_p)
status = enum.PAUSED
err = AddServiceInstance(name, instance_ps, status)
assert.NoError(t, err)
assert.Contains(t, service.Instances.All, instance_ps)
assert.Contains(t, service.Instances.Paused, instance_ps)
status = enum.STOPPED
err = AddServiceInstance(name, instance_s, status)
assert.NoError(t, err)
assert.Contains(t, service.Instances.All, instance_s)
assert.Contains(t, service.Instances.Stopped, instance_s)
status = enum.PENDING
err = AddServiceInstance("pippo", "pippo", status)
assert.Error(t, err)
}
示例7: TestFillStruct
func TestFillStruct(t *testing.T) {
testMap := map[string]interface{}{
"Pippo": 5,
"Topolino": 4.6,
"Paperino": "ciao",
}
noErr := &noError{}
err1 := &wrongField{}
err2 := &wrongType{}
err3 := &cantSet{}
assert.NoError(t, FillStruct(noErr, testMap))
assert.Error(t, FillStruct(err1, testMap))
assert.Error(t, FillStruct(err2, testMap))
assert.Error(t, FillStruct(err3, testMap))
}
示例8: TestNew
func TestNew(t *testing.T) {
noService := "noservice"
noServiceConf := CreateMetricsMockConfig(noService)
influxService := "influxdb"
influxConf := CreateMetricsMockConfig(influxService)
test, testErr := New(influxService, influxConf)
assert.NoError(t, testErr)
assert.Equal(t, test.Name(), influxService)
influxConf["Username"] = 1
test, testErr = New(influxService, influxConf)
assert.Error(t, testErr)
assert.Equal(t, test.Name(), noService)
test, testErr = New(noService, noServiceConf)
assert.Error(t, testErr)
assert.Equal(t, test.Name(), noService)
}
示例9: TestGetCoresNumber
func TestGetCoresNumber(t *testing.T) {
var err error
cores := "0,1,2,3"
cores_tooMany := "0,1,2,3,4,5,6"
cores_wrongNumber := "0,1,85"
cores_atoi := "1,pippo"
var n []int
n, err = getCoresNumber(cores)
assert.NoError(t, err)
assert.Equal(t, []int{0, 1, 2, 3}, n)
n, err = getCoresNumber(cores_tooMany)
assert.Error(t, err)
n, err = getCoresNumber(cores_wrongNumber)
assert.Error(t, err)
n, err = getCoresNumber(cores_atoi)
assert.Error(t, err)
}
示例10: TestGetServiceByName
func TestGetServiceByName(t *testing.T) {
defer cfg.CleanServices()
cfg.SetServices(CreateMockServices())
s1, err := GetServiceByName("service2")
assert.Equal(t, "service2", s1.Name, "service name should be service1")
_, err = GetServiceByName("pippo")
assert.Error(t, err, "There should be no service with name 'pippo'")
}
示例11: TestGetServiceByImage
func TestGetServiceByImage(t *testing.T) {
defer cfg.CleanServices()
cfg.SetServices(CreateMockServices())
img1, err := GetServiceByImage("test/mysql")
assert.Equal(t, "test/mysql", img1.Image, "service image should be test/tomcat")
_, err = GetServiceByImage("test/pippo")
assert.Error(t, err, "There should be no image 'test/pippo'")
}
示例12: TestRAMInBytes
func TestRAMInBytes(t *testing.T) {
human := [13]string{
"32",
"32b",
"32B",
"32k",
"32K",
"32kb",
"32Kb",
"32Mb",
"32Gb",
"32Tb",
"32Pb",
"32PB",
"32P",
}
values := [13]int64{
32,
32,
32,
32 * KiB,
32 * KiB,
32 * KiB,
32 * KiB,
32 * MiB,
32 * GiB,
32 * TiB,
32 * PiB,
32 * PiB,
32 * PiB,
}
errors := [9]string{
"",
"hello",
"-32",
"32.3",
" 32 ",
"32.3Kb",
"32 mb",
"32m b",
"32bm",
}
for i := 0; i < len(human); i++ {
ram, _ := RAMInBytes(human[i])
assert.Equal(t, values[i], ram)
}
for i := 0; i < len(errors); i++ {
_, err := RAMInBytes(errors[i])
assert.Error(t, err)
}
}
示例13: TestRemoveServiceIntance
func TestRemoveServiceIntance(t *testing.T) {
defer cfg.CleanServices()
cfg.SetServices(CreateMockServices())
name := "service1"
service, _ := GetServiceByName(name)
instance := "instance1_0"
var err error
err = RemoveServiceInstance(name, instance)
assert.NotContains(t, service.Instances.Stopped, instance)
assert.NotContains(t, service.Instances.All, instance)
assert.NoError(t, err)
err = RemoveServiceInstance("pippo", instance)
assert.Error(t, err)
err = RemoveServiceInstance(name, "pippo")
assert.Error(t, err)
}
示例14: TestGetPolicy
func TestGetPolicy(t *testing.T) {
defer storage.DeleteAllData(enum.POLICIES)
var err error
_, err = GetPolicy()
assert.Error(t, err)
expected := CreateRandomMockPolicies(1)[0]
SavePolicy(expected)
policy, err := GetPolicy()
assert.NoError(t, err)
assert.Equal(t, expected, policy)
}
示例15: TestGetAnalytics
func TestGetAnalytics(t *testing.T) {
defer storage.DeleteAllData(enum.ANALYTICS)
var err error
_, err = GetAnalytics()
assert.Error(t, err)
expected := CreateMockAnalytics()
SaveMockAnalytics()
analytics, err := GetAnalytics()
assert.NoError(t, err)
assert.Equal(t, expected, analytics)
}