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


Golang workarounds.GolangDoesnotAllowPointerToStringLiteral函數代碼示例

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


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

示例1: TestCarbonInvalidCarbonDeconstructorListenerLoader

func TestCarbonInvalidCarbonDeconstructorListenerLoader(t *testing.T) {
	listenFrom := &config.ListenFrom{
		ListenAddr:          workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:12247"),
		MetricDeconstructor: workarounds.GolangDoesnotAllowPointerToStringLiteral("UNKNOWN"),
	}
	ctx := context.Background()
	forwardTo := dptest.NewBasicSink()
	_, err := ListenerLoader(ctx, forwardTo, listenFrom)
	assert.NotEqual(t, nil, err, "Should get an error making")
}
開發者ID:baris,項目名稱:metricproxy,代碼行數:10,代碼來源:carbonlistener_test.go

示例2: TestListenerLoader

func TestListenerLoader(t *testing.T) {
	listenFrom := &config.ListenFrom{
		ListenAddr:           workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:0"),
		ServerAcceptDeadline: workarounds.GolangDoesnotAllowPointerToTimeLiteral(time.Millisecond),
	}
	ctx := context.Background()
	forwardTo := dptest.NewBasicSink()
	listener, err := ListenerLoader(ctx, forwardTo, listenFrom)
	defer listener.Close()
	assert.Equal(t, nil, err, "Should be ok to make")
	defer listener.Close()
	listeningDialAddress := fmt.Sprintf("127.0.0.1:%d", nettest.TCPPort(listener.psocket))
	assert.Equal(t, numStats, len(listener.Stats()), "Should have no stats")
	assert.NoError(t, err, "Should be ok to make")

	conn, err := net.Dial("tcp", listeningDialAddress)
	assert.NoError(t, err, "Should be ok to make")
	assert.Equal(t, int64(0), listener.stats.invalidDatapoints)
	var buf bytes.Buffer
	fmt.Fprintf(&buf, "%s %d %d\n\nINVALIDLINE", "ametric", 2, 2)
	_, err = buf.WriteTo(conn)
	conn.Close()
	assert.Equal(t, nil, err, "Should be ok to write")
	dp := forwardTo.Next()
	assert.Equal(t, "ametric", dp.Metric, "Should be metric")
	i := dp.Value.(datapoint.IntValue).Int()
	assert.Equal(t, int64(2), i, "Should get 2")

	for atomic.LoadInt64(&listener.stats.retriedListenErrors) == 0 {
		time.Sleep(time.Millisecond)
	}
	assert.Equal(t, int64(1), atomic.LoadInt64(&listener.stats.invalidDatapoints))
}
開發者ID:baris,項目名稱:metricproxy,代碼行數:33,代碼來源:carbonlistener_test.go

示例3: TestCarbonHandleConnection

func TestCarbonHandleConnection(t *testing.T) {
	log.Info("START TestCarbonHandleConnection")
	defer log.Info("END   TestCarbonHandleConnection")
	listenFrom := &config.ListenFrom{
		ListenAddr: workarounds.GolangDoesnotAllowPointerToStringLiteral("localhost:0"),
	}

	ctx := context.Background()
	forwardTo := dptest.NewBasicSink()
	listener, err := ListenerLoader(ctx, forwardTo, listenFrom)
	defer listener.Close()

	listeningDialAddress := fmt.Sprintf("localhost:%d", nettest.TCPPort(listener.psocket))

	conn, err := net.Dial("tcp", listeningDialAddress)
	assert.NoError(t, err)
	conn.Close()
	assert.Error(t, listener.handleConnection(conn))

	conn, err = net.Dial("tcp", listeningDialAddress)
	assert.NoError(t, err)
	waitChan := make(chan struct{})
	go func() {
		time.Sleep(time.Millisecond * 10)
		assert.NoError(t, conn.Close())
		close(waitChan)
	}()
	<-waitChan

	for atomic.LoadInt64(&listener.stats.totalEOFCloses) == 0 {
		time.Sleep(time.Millisecond)
	}
}
開發者ID:baris,項目名稱:metricproxy,代碼行數:33,代碼來源:carbonlistener_test.go

示例4: TestInvalidPort

func TestInvalidPort(t *testing.T) {

	ft := config.ForwardTo{
		Host: workarounds.GolangDoesnotAllowPointerToStringLiteral("zzfbdsaj_)[email protected]#$%.zzzzzzzzzzz"),
		Port: workarounds.GolangDoesnotAllowPointerToUint16Literal(1),
	}
	_, err := ForwarderLoader(context.Background(), &ft)
	assert.NotEqual(t, nil, err, "Expect an error")
}
開發者ID:baris,項目名稱:metricproxy,代碼行數:9,代碼來源:carbonforwarder_test.go

示例5: TestInvalidListen

func TestInvalidListen(t *testing.T) {
	listenFrom := &config.ListenFrom{
		ListenAddr: workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:999999"),
	}
	sendTo := dptest.NewBasicSink()
	ctx := context.Background()
	_, err := ListenerLoader(ctx, sendTo, listenFrom)
	assert.Error(t, err)
}
開發者ID:baris,項目名稱:metricproxy,代碼行數:9,代碼來源:collectdlistener_test.go

示例6: TestForwarderLoaderOldVersion

func TestForwarderLoaderOldVersion(t *testing.T) {
	forwardTo := config.ForwardTo{
		FormatVersion:    workarounds.GolangDoesnotAllowPointerToUintLiteral(1),
		DefaultAuthToken: workarounds.GolangDoesnotAllowPointerToStringLiteral("AUTH_TOKEN"),
	}
	ctx := context.Background()
	_, err := ForwarderLoader(ctx, &forwardTo)
	assert.NoError(t, err)
}
開發者ID:tomzhang,項目名稱:metricproxy,代碼行數:9,代碼來源:signalfxforwarder_test.go

示例7: TestCarbonInvalidListenerLoader

func TestCarbonInvalidListenerLoader(t *testing.T) {
	ctx := context.Background()
	listenFrom := &config.ListenFrom{
		ListenAddr: workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:999999"),
	}
	sendTo := dptest.NewBasicSink()
	_, err := ListenerLoader(ctx, sendTo, listenFrom)
	assert.NotEqual(t, nil, err, "Should get an error making")
}
開發者ID:baris,項目名稱:metricproxy,代碼行數:9,代碼來源:carbonlistener_test.go

示例8: TestNewProtobufDataPoint

func TestNewProtobufDataPoint(t *testing.T) {
	protoDatapoint := &com_signalfx_metrics_protobuf.DataPoint{
		Source: workarounds.GolangDoesnotAllowPointerToStringLiteral("asource"),
		Metric: workarounds.GolangDoesnotAllowPointerToStringLiteral("ametric"),
		Value:  &com_signalfx_metrics_protobuf.Datum{IntValue: workarounds.GolangDoesnotAllowPointerToIntLiteral(2)},
		Dimensions: []*com_signalfx_metrics_protobuf.Dimension{{
			Key:   workarounds.GolangDoesnotAllowPointerToStringLiteral("key"),
			Value: workarounds.GolangDoesnotAllowPointerToStringLiteral("value"),
		}},
	}
	dp, err := NewProtobufDataPointWithType(protoDatapoint, com_signalfx_metrics_protobuf.MetricType_COUNTER)
	assert.Equal(t, "asource", dp.Dimensions["sf_source"], "Line should be invalid")
	assert.NoError(t, err)
	assert.Equal(t, datapoint.Count, dp.MetricType, "Line should be invalid")

	v := com_signalfx_metrics_protobuf.MetricType_CUMULATIVE_COUNTER
	protoDatapoint.MetricType = &v
	dp, err = NewProtobufDataPointWithType(protoDatapoint, com_signalfx_metrics_protobuf.MetricType_COUNTER)
	assert.NoError(t, err)
	assert.Equal(t, datapoint.Counter, dp.MetricType, "Line should be invalid")

	item := &BodySendFormatV2{
		Metric: "ametric",
		Value:  3.0,
	}
	assert.Contains(t, item.String(), "ametric", "Should get metric name back")
	f, _ := ValueToValue(item.Value)
	assert.Equal(t, datapoint.NewFloatValue(3.0), f, "Should get value 3 back")

	item.Value = 3
	i, _ := ValueToValue(item.Value)
	assert.Equal(t, datapoint.NewIntValue(3), i, "Should get value 3 back")

	item.Value = int64(3)
	ValueToValue(item.Value)

	item.Value = "abc"
	s, _ := ValueToValue(item.Value)
	assert.Equal(t, datapoint.NewStringValue("abc"), s, "Should get value abc back")

	item.Value = struct{}{}
	_, err = ValueToValue(item.Value)
	assert.Error(t, err)
}
開發者ID:tomzhang,項目名稱:metricproxy,代碼行數:44,代碼來源:signalfx_test.go

示例9: TestForwarderLoaderDefaults

func TestForwarderLoaderDefaults(t *testing.T) {
	forwardTo := config.ForwardTo{
		FormatVersion:    workarounds.GolangDoesnotAllowPointerToUintLiteral(2),
		DefaultAuthToken: workarounds.GolangDoesnotAllowPointerToStringLiteral("AUTH_TOKEN"),
	}
	ctx := context.Background()
	forwarder, err := ForwarderLoader(ctx, &forwardTo)
	assert.Nil(t, err)
	defer forwarder.Close()
}
開發者ID:tomzhang,項目名稱:metricproxy,代碼行數:10,代碼來源:signalfxforwarder_test.go

示例10: TestLoader

func TestLoader(t *testing.T) {
	listenFrom := config.ListenFrom{}
	listenFrom.ListenAddr = workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:0")
	ctx := context.Background()
	forwardTo := dptest.NewBasicSink()
	l, err := ListenerLoader(ctx, forwardTo, &listenFrom)
	port := nettest.TCPPort(l.psocket)

	ft := config.ForwardTo{
		Host: workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1"),
		Port: workarounds.GolangDoesnotAllowPointerToUint16Literal(port),
	}
	f, err := ForwarderLoader(context.Background(), &ft)
	assert.NoError(t, err)
	dpSent := dptest.DP()
	dpSent.Dimensions = map[string]string{}
	assert.NoError(t, f.AddDatapoints(ctx, []*datapoint.Datapoint{dpSent}))
	dpSeen := forwardTo.Next()
	assert.Equal(t, dpSent.Metric, dpSeen.Metric)
	assert.Equal(t, numStats+1, len(f.Stats()))
}
開發者ID:baris,項目名稱:metricproxy,代碼行數:21,代碼來源:carbonforwarder_test.go

示例11: TestFilenameForwarderBadWrite

func TestFilenameForwarderBadWrite(t *testing.T) {
	ctx := context.Background()
	fileObj, _ := ioutil.TempFile("", "gotest")
	defer os.Remove(fileObj.Name())
	conf := &config.ForwardTo{
		Filename: workarounds.GolangDoesnotAllowPointerToStringLiteral(fileObj.Name()),
	}
	f, _ := ForwarderLoader(conf)
	f.writeString = func(f *os.File, s string) (ret int, err error) {
		return 0, errors.New("nope")
	}
	assert.Error(t, f.AddDatapoints(ctx, []*datapoint.Datapoint{dptest.DP()}))
	assert.Error(t, f.AddEvents(ctx, []*event.Event{dptest.E()}))
}
開發者ID:baris,項目名稱:metricproxy,代碼行數:14,代碼來源:csvforwarder_test.go

示例12: TestFilenameForwarder

func TestFilenameForwarder(t *testing.T) {
	ctx := context.Background()
	fileObj, _ := ioutil.TempFile("", "gotest")
	filename := fileObj.Name()
	defer os.Remove(filename)
	conf := &config.ForwardTo{
		Filename: workarounds.GolangDoesnotAllowPointerToStringLiteral(fileObj.Name()),
	}
	f, err := ForwarderLoader(conf)
	defer f.Close()
	assert.NoError(t, err)
	assert.NoError(t, f.AddDatapoints(ctx, []*datapoint.Datapoint{dptest.DP()}))
	assert.NoError(t, f.AddEvents(ctx, []*event.Event{dptest.E()}))
	assert.Equal(t, 0, len(f.Stats()))
}
開發者ID:baris,項目名稱:metricproxy,代碼行數:15,代碼來源:csvforwarder_test.go

示例13: setupServerForwarder

func setupServerForwarder(t *testing.T) (*dptest.BasicSink, *ListenerServer, *Forwarder) {
	// TODO: Break this out into smaller tests
	listenFromSignalfx := config.ListenFrom{}
	listenFromSignalfx.ListenAddr = workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:0")

	finalDatapointDestination := dptest.NewBasicSink()
	ctx := context.Background()
	l, err := ListenerLoader(ctx, finalDatapointDestination, &listenFromSignalfx)
	assert.Equal(t, nil, err, "Expect no error")

	port := nettest.TCPPort(l.listener)

	forwardTo := config.ForwardTo{
		URL:              workarounds.GolangDoesnotAllowPointerToStringLiteral(fmt.Sprintf("http://127.0.0.1:%d/v2/datapoint", port)),
		TimeoutDuration:  workarounds.GolangDoesnotAllowPointerToDurationLiteral(time.Second * 1),
		DefaultAuthToken: workarounds.GolangDoesnotAllowPointerToStringLiteral("AUTH_TOKEN"),
		DefaultSource:    workarounds.GolangDoesnotAllowPointerToStringLiteral("proxy-source"),
		SourceDimensions: workarounds.GolangDoesnotAllowPointerToStringLiteral("username,ignored,hostname"),
	}

	_, forwarder, err := ForwarderLoader1(ctx, &forwardTo)
	assert.NoError(t, err, "Expect no error")
	return finalDatapointDestination, l, forwarder
}
開發者ID:tomzhang,項目名稱:metricproxy,代碼行數:24,代碼來源:signalfxforwarder_test.go

示例14: TestCreation

func TestCreation(t *testing.T) {
	listenFrom := config.ListenFrom{}
	listenFrom.ListenAddr = workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:0")
	forwardTo := dptest.NewBasicSink()
	ctx := context.Background()
	l, err := ListenerLoader(ctx, forwardTo, &listenFrom)
	defer l.Close()
	assert.Equal(t, nil, err, "Expect no error")
	assert.Equal(t, numStats, len(l.Stats()), "Expect no stats")
	forwarder, err := NewForwarder("127.0.0.1", nettest.TCPPort(l.psocket), time.Second, []string{"zzfirst"}, 10)
	defer forwarder.Close()
	assert.Equal(t, nil, err, "Expect no error")
	assert.Equal(t, 1, len(forwarder.pool.conns))
	timeToSend := time.Now().Round(time.Second)
	dpSent := dptest.DP()
	dpSent.Timestamp = timeToSend
	log.Info("Sending a dp")
	forwarder.AddDatapoints(ctx, []*datapoint.Datapoint{dpSent})
	log.Info("Looking for DP back")
	dpSeen := forwardTo.Next()

	assert.Equal(t, "randtest."+dpSent.Metric, dpSeen.Metric, "Expect metric back")
	assert.Equal(t, dpSent.Timestamp, dpSeen.Timestamp, "Expect metric back")

	// Test creating a new connection if pool is empty
	for forwarder.pool.Get() != nil {
	}

	forwarder.AddDatapoints(ctx, []*datapoint.Datapoint{dpSent})
	dpSeen = forwardTo.Next()
	assert.Equal(t, "randtest."+dpSent.Metric, dpSeen.Metric, "Expect metric back")
	assert.Equal(t, dpSent.Timestamp, dpSeen.Timestamp, "Expect metric back")
	//
	// Test creation error if pool is empty
	for forwarder.pool.Get() != nil {
	}

	forwarder.dialer = func(network, address string, timeout time.Duration) (net.Conn, error) {
		return nil, errors.New("nope")
	}
	assert.Error(t, forwarder.AddDatapoints(ctx, []*datapoint.Datapoint{dpSeen}))

	forwarder.dialer = net.DialTimeout
	assert.NoError(t, forwarder.AddDatapoints(ctx, []*datapoint.Datapoint{dpSeen}), "Should get the conn back")

}
開發者ID:baris,項目名稱:metricproxy,代碼行數:46,代碼來源:carbonforwarder_test.go

示例15: TestCarbonNoWriteEvents

func TestCarbonNoWriteEvents(t *testing.T) {
	listenFrom := config.ListenFrom{}
	listenFrom.ListenAddr = workarounds.GolangDoesnotAllowPointerToStringLiteral("127.0.0.1:0")
	forwardTo := dptest.NewBasicSink()
	ctx := context.Background()
	l, err := ListenerLoader(ctx, forwardTo, &listenFrom)
	defer l.Close()
	assert.Equal(t, nil, err, "Expect no error")
	assert.Equal(t, numStats, len(l.Stats()), "Expect no stats")
	forwarder, err := NewForwarder("127.0.0.1", nettest.TCPPort(l.psocket), time.Second, []string{"zzfirst"}, 10)
	assert.Equal(t, nil, err, "Expect no error")
	assert.Equal(t, 1, len(forwarder.pool.conns))
	timeToSend := time.Now().Round(time.Second)
	eSent := dptest.E()
	eSent.Timestamp = timeToSend
	eSent.Meta["blarg"] = "abcd 123 123"
	log.Info("Sending a e")
	forwarder.AddEvents(ctx, []*event.Event{eSent})
	assert.Equal(t, 0, len(forwardTo.EventsChan))

}
開發者ID:baris,項目名稱:metricproxy,代碼行數:21,代碼來源:carbonforwarder_test.go


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