當前位置: 首頁>>代碼示例>>Golang>>正文


Golang assert.NoError函數代碼示例

本文整理匯總了Golang中github.com/elleFlorio/gru/Godeps/_workspace/src/github.com/stretchr/testify/assert.NoError函數的典型用法代碼示例。如果您正苦於以下問題:Golang NoError函數的具體用法?Golang NoError怎麽用?Golang NoError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NoError函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestDoubleLoggingDoesntPrefixPreviousFields

func TestDoubleLoggingDoesntPrefixPreviousFields(t *testing.T) {

	var buffer bytes.Buffer
	var fields Fields

	logger := New()
	logger.Out = &buffer
	logger.Formatter = new(JSONFormatter)

	llog := logger.WithField("context", "eating raw fish")

	llog.Info("looks delicious")

	err := json.Unmarshal(buffer.Bytes(), &fields)
	assert.NoError(t, err, "should have decoded first message")
	assert.Equal(t, len(fields), 4, "should only have msg/time/level/context fields")
	assert.Equal(t, fields["msg"], "looks delicious")
	assert.Equal(t, fields["context"], "eating raw fish")

	buffer.Reset()

	llog.Warn("omg it is!")

	err = json.Unmarshal(buffer.Bytes(), &fields)
	assert.NoError(t, err, "should have decoded second message")
	assert.Equal(t, len(fields), 4, "should only have msg/time/level/context fields")
	assert.Equal(t, fields["msg"], "omg it is!")
	assert.Equal(t, fields["context"], "eating raw fish")
	assert.Nil(t, fields["fields.msg"], "should not have prefixed previous `msg` entry")

}
開發者ID:elleFlorio,項目名稱:gru,代碼行數:31,代碼來源:logrus_test.go

示例2: TestDeleteData

func TestDeleteData(t *testing.T) {
	intern := 0
	key := "test"
	data := []byte("pippo")
	var value []byte
	var err error

	//INTERNAL
	dataStore = intern
	Initialize()
	StoreData(key, data, enum.STATS)
	StoreData(key, data, enum.ANALYTICS)
	StoreData(key, data, enum.POLICIES)
	StoreData(key, data, enum.SHARED)

	err = DeleteData(key, enum.STATS)
	assert.NoError(t, err)
	value, _ = GetData(key, enum.STATS)
	assert.Nil(t, value)
	err = DeleteData(key, enum.ANALYTICS)
	assert.NoError(t, err)
	value, _ = GetData(key, enum.ANALYTICS)
	assert.Nil(t, value)
	err = DeleteData(key, enum.POLICIES)
	assert.NoError(t, err)
	value, _ = GetData(key, enum.POLICIES)
	assert.Nil(t, value)
	err = DeleteData(key, enum.SHARED)
	assert.NoError(t, err)
	value, _ = GetData(key, enum.SHARED)
	assert.Nil(t, value)
}
開發者ID:elleFlorio,項目名稱:gru,代碼行數:32,代碼來源:datastore_test.go

示例3: 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)
}
開發者ID:elleFlorio,項目名稱:gru,代碼行數:33,代碼來源:service_test.go

示例4: 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")

}
開發者ID:elleFlorio,項目名稱:gru,代碼行數:28,代碼來源:range_test.go

示例5: 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")
}
開發者ID:elleFlorio,項目名稱:gru,代碼行數:34,代碼來源:communication_test.go

示例6: TestAssignSpecificPortsToService

func TestAssignSpecificPortsToService(t *testing.T) {
	defer clearServicePorts()
	var err error
	createServicePorts()
	service := "pippo"
	id := "123456789"
	port1 := "50100"
	port2 := "50200"
	bindings := map[string][]string{
		port1: []string{"50100"},
		port2: []string{"50200"},
	}

	err = AssignSpecifiPortsToService(service, id, bindings)
	assert.NoError(t, err)
	available1 := resources.Network.ServicePorts[service].Status[port1].Available
	occupied1 := resources.Network.ServicePorts[service].Status[port1].Occupied
	assert.Len(t, available1, 3)
	assert.Len(t, occupied1, 1)
	available2 := resources.Network.ServicePorts[service].Status[port2].Available
	occupied2 := resources.Network.ServicePorts[service].Status[port2].Occupied
	assert.Len(t, available2, 1)
	assert.Len(t, occupied2, 1)
	assert.NotEmpty(t, instanceBindings)

	err = AssignSpecifiPortsToService(service, id, bindings)
	assert.Error(t, err)
	available1 = resources.Network.ServicePorts[service].Status[port1].Available
	occupied1 = resources.Network.ServicePorts[service].Status[port1].Occupied
	assert.Len(t, available1, 3)
	assert.Len(t, occupied1, 1)
	available2 = resources.Network.ServicePorts[service].Status[port2].Available
	occupied2 = resources.Network.ServicePorts[service].Status[port2].Occupied
	assert.Len(t, available2, 1)
	assert.Len(t, occupied2, 1)

	bindings[port1] = []string{"50000"}
	bindings[port2] = []string{"50201"}
	err = AssignSpecifiPortsToService(service, id, bindings)
	assert.NoError(t, err)
	available1 = resources.Network.ServicePorts[service].Status[port1].Available
	occupied1 = resources.Network.ServicePorts[service].Status[port1].Occupied
	assert.Len(t, available1, 3)
	assert.Len(t, occupied1, 2)
	available2 = resources.Network.ServicePorts[service].Status[port2].Available
	occupied2 = resources.Network.ServicePorts[service].Status[port2].Occupied
	assert.Len(t, available2, 0)
	assert.Len(t, occupied2, 2)

}
開發者ID:elleFlorio,項目名稱:gru,代碼行數:50,代碼來源:resources_test.go

示例7: TestGetAllData

func TestGetAllData(t *testing.T) {
	intern := 0

	//INTERNAL
	dataStore = intern
	Initialize()
	_, err := GetAllData(enum.STATS)
	assert.NoError(t, err)
	_, err = GetAllData(enum.ANALYTICS)
	assert.NoError(t, err)
	_, err = GetAllData(enum.POLICIES)
	assert.NoError(t, err)
	_, err = GetAllData(enum.SHARED)
	assert.NoError(t, err)
}
開發者ID:elleFlorio,項目名稱:gru,代碼行數:15,代碼來源:datastore_test.go

示例8: 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)
}
開發者ID:elleFlorio,項目名稱:gru,代碼行數:48,代碼來源:service_test.go

示例9: 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)
}
開發者ID:elleFlorio,項目名稱:gru,代碼行數:30,代碼來源:resources_test.go

示例10: LogAndAssertText

func LogAndAssertText(t *testing.T, log func(*Logger), assertions func(fields map[string]string)) {
	var buffer bytes.Buffer

	logger := New()
	logger.Out = &buffer
	logger.Formatter = &TextFormatter{
		DisableColors: true,
	}

	log(logger)

	fields := make(map[string]string)
	for _, kv := range strings.Split(buffer.String(), " ") {
		if !strings.Contains(kv, "=") {
			continue
		}
		kvArr := strings.Split(kv, "=")
		key := strings.TrimSpace(kvArr[0])
		val := kvArr[1]
		if kvArr[1][0] == '"' {
			var err error
			val, err = strconv.Unquote(val)
			assert.NoError(t, err)
		}
		fields[key] = val
	}
	assertions(fields)
}
開發者ID:elleFlorio,項目名稱:gru,代碼行數:28,代碼來源:logrus_test.go

示例11: TestCreateInfluxMetrics

func TestCreateInfluxMetrics(t *testing.T) {
	New("influxdb", createInfluxMockConfig())
	mockMetrics := CreateMockMetrics()
	points, err := createInfluxMetrics(mockMetrics)
	assert.NoError(t, err)
	assert.NotEmpty(t, points)
}
開發者ID:elleFlorio,項目名稱:gru,代碼行數:7,代碼來源:metric_test.go

示例12: TestStoreClusterData

func TestStoreClusterData(t *testing.T) {
	New("internal")
	var err error
	data := []byte{1, 2, 3, 4, 5}

	err = StoreClusterData(data, enum.POLICIES)
	assert.NoError(t, err)
}
開發者ID:elleFlorio,項目名稱:gru,代碼行數:8,代碼來源:datastore_test.go

示例13: TestGetServiceById

func TestGetServiceById(t *testing.T) {
	defer cfg.CleanServices()

	var err error
	cfg.SetServices(CreateMockServices())

	srv1, err := GetServiceById("instance1_0")
	assert.NoError(t, err)
	assert.Equal(t, "service1", srv1.Name)

	srv2, err := GetServiceById("instance2_1")
	assert.NoError(t, err)
	assert.Equal(t, "service2", srv2.Name)

	_, err = GetServiceById("pippo")
	assert.Error(t, err)
}
開發者ID:elleFlorio,項目名稱:gru,代碼行數:17,代碼來源:service_test.go

示例14: TestStoreData

func TestStoreData(t *testing.T) {
	intern := 0
	key := "test"
	data := []byte("pippo")
	var err error

	//INTERNAL
	dataStore = intern
	Initialize()
	err = StoreData(key, data, enum.STATS)
	assert.NoError(t, err)
	err = StoreData(key, data, enum.ANALYTICS)
	assert.NoError(t, err)
	err = StoreData(key, data, enum.POLICIES)
	assert.NoError(t, err)
	err = StoreData(key, data, enum.SHARED)
	assert.NoError(t, err)
}
開發者ID:elleFlorio,項目名稱:gru,代碼行數:18,代碼來源:datastore_test.go

示例15: TestGetClusterData

func TestGetClusterData(t *testing.T) {
	data := []byte{1, 2, 3, 4, 5}
	New("intenal")

	StoreData(enum.CLUSTER.ToString(), data, enum.POLICIES)
	test, err := GetClusterData(enum.POLICIES)
	assert.NoError(t, err)
	assert.Equal(t, data, test)
}
開發者ID:elleFlorio,項目名稱:gru,代碼行數:9,代碼來源:datastore_test.go


注:本文中的github.com/elleFlorio/gru/Godeps/_workspace/src/github.com/stretchr/testify/assert.NoError函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。