コード例 #1
0
ファイル: testing_test.go プロジェクト: muhqu/gotestit
func TestSend(t *testing.T) {
	bufferSize := 4096
	loggregatorClient := l.NewLoggregatorClient("localhost:9876", gosteno.NewLogger("TestLogger"), bufferSize)

	udpAddr, err := net.ResolveUDPAddr("udp", "localhost:9876")
	if err != nil {
		t.Errorf("Expected no error, but got %v", err)
	}

	udpListener, err := net.ListenUDP("udp", udpAddr)
	defer udpListener.Close()
	if err != nil {
		t.Errorf("Expected no error, but got %v", err)
	}

	expectedOutput := []byte("Important Testmessage")
	loggregatorClient.Send(expectedOutput)

	buffer := make([]byte, bufferSize)
	readCount, _, err := udpListener.ReadFromUDP(buffer)
	if err != nil {
		t.Errorf("Expected no error, but got %v", err)
	}

	received := string(buffer[:readCount])
	if string(expectedOutput) != received {
		t.Errorf("Expected %s to equal %s", string(expectedOutput), received)
	}
}
コード例 #2
0
ファイル: testing_test.go プロジェクト: muhqu/gotestit
func TestDontSendEmptyData(t *testing.T) {
	bufferSize := 4096
	loggregatorClient := l.NewLoggregatorClient("localhost:9876", gosteno.NewLogger("TestLogger"), bufferSize)

	udpAddr, err := net.ResolveUDPAddr("udp", "localhost:9876")
	if err != nil {
		t.Errorf("Expected no error, but got %v", err)
	}

	udpListener, err := net.ListenUDP("udp", udpAddr)
	defer udpListener.Close()
	if err != nil {
		t.Errorf("Expected no error, but got %v", err)
	}

	firstMessage := []byte("")
	secondMessage := []byte("hi")
	loggregatorClient.Send(firstMessage)
	loggregatorClient.Send(secondMessage)

	buffer := make([]byte, bufferSize)
	readCount, _, err := udpListener.ReadFromUDP(buffer)

	if err != nil {
		t.Errorf("Expected no error, but got %v", err)
	}

	received := string(buffer[:readCount])
	if string(secondMessage) != received {
		t.Errorf("Expected %s to equal %s", string(secondMessage), received)
	}
}
コード例 #3
0
ファイル: zen_test.go プロジェクト: muhqu/gotestit
func TestLoggregatorClient(t *testing.T) {
	Desc(t, "loggregator client", func(it It) {
		bufferSize := 4096
		loggregatorClient := l.NewLoggregatorClient("localhost:9876", gosteno.NewLogger("TestLogger"), bufferSize)

		udpAddr, err := net.ResolveUDPAddr("udp", "localhost:9876")
		it("does not fail resolving UPD Addr", func(expect Expect) {
			expect(err).ToEqual(nil)
		})

		udpListener, err := net.ListenUDP("udp", udpAddr)
		defer udpListener.Close()
		it("does not fail listening to UPD", func(expect Expect) {
			expect(err).ToEqual(nil)
		})

		it("should send data", func(expect Expect) {
			expectedOutput := []byte("Important Testmessage")
			loggregatorClient.Send(expectedOutput)

			buffer := make([]byte, bufferSize)
			readCount, _, err := udpListener.ReadFromUDP(buffer)
			expect(err).ToEqual(nil)

			received := string(buffer[:readCount])
			expect(string(expectedOutput)).ToEqual(received)
		})
		it("should not send empty data", func(expect Expect) {
			firstMessage := []byte("")
			secondMessage := []byte("hi")
			loggregatorClient.Send(firstMessage)
			loggregatorClient.Send(secondMessage)

			buffer := make([]byte, bufferSize)
			readCount, _, err := udpListener.ReadFromUDP(buffer)
			expect(err).ToEqual(nil)

			received := string(buffer[:readCount])
			expect(string(secondMessage)).ToEqual(received)
		})
	})
}
コード例 #4
0
ファイル: testify_test.go プロジェクト: muhqu/gotestit
func TestSend(t *testing.T) {
	bufferSize := 4096
	loggregatorClient := l.NewLoggregatorClient("localhost:9876", gosteno.NewLogger("TestLogger"), bufferSize)

	udpAddr, err := net.ResolveUDPAddr("udp", "localhost:9876")
	assert.NoError(t, err)

	udpListener, err := net.ListenUDP("udp", udpAddr)
	defer udpListener.Close()
	assert.NoError(t, err)

	expectedOutput := []byte("Important Testmessage")
	loggregatorClient.Send(expectedOutput)

	buffer := make([]byte, bufferSize)
	readCount, _, err := udpListener.ReadFromUDP(buffer)
	assert.NoError(t, err)

	received := string(buffer[:readCount])
	assert.Equal(t, string(expectedOutput), received)
}
コード例 #5
0
ファイル: gospec_test.go プロジェクト: muhqu/gotestit
func LoggregatorClientSpec(c gospec.Context) {
	bufferSize := 4096
	loggregatorClient := l.NewLoggregatorClient("localhost:9876", gosteno.NewLogger("TestLogger"), bufferSize)

	udpAddr, err := net.ResolveUDPAddr("udp", "localhost:9876")
	c.Expect(err, IsNil)
	c.Expect(err, Not(Equals), 1)

	udpListener, err := net.ListenUDP("udp", udpAddr)
	defer udpListener.Close()
	c.Expect(err, IsNil)

	c.Specify("That it sends data", func() {
		expectedOutput := []byte("Important Testmessage")
		loggregatorClient.Send(expectedOutput)

		buffer := make([]byte, bufferSize)
		readCount, _, err := udpListener.ReadFromUDP(buffer)
		c.Expect(err, IsNil)

		received := string(buffer[:readCount])
		c.Expect(string(expectedOutput), Equals, received)
	})
	c.Specify("That it does not send empty data", func() {
		firstMessage := []byte("")
		secondMessage := []byte("hi")
		loggregatorClient.Send(firstMessage)
		loggregatorClient.Send(secondMessage)

		buffer := make([]byte, bufferSize)
		readCount, _, err := udpListener.ReadFromUDP(buffer)
		c.Expect(err, Equals, nil)

		received := string(buffer[:readCount])
		c.Expect(string(secondMessage), Equals, received)
	})
}
コード例 #6
0
ファイル: testify_test.go プロジェクト: muhqu/gotestit
func TestDontSendEmptyData(t *testing.T) {
	bufferSize := 4096
	loggregatorClient := l.NewLoggregatorClient("localhost:9876", gosteno.NewLogger("TestLogger"), bufferSize)

	udpAddr, err := net.ResolveUDPAddr("udp", "localhost:9876")
	assert.NoError(t, err)

	udpListener, err := net.ListenUDP("udp", udpAddr)
	defer udpListener.Close()
	assert.NoError(t, err)

	firstMessage := []byte("")
	secondMessage := []byte("hi")
	loggregatorClient.Send(firstMessage)
	loggregatorClient.Send(secondMessage)

	buffer := make([]byte, bufferSize)
	readCount, _, err := udpListener.ReadFromUDP(buffer)

	assert.NoError(t, err)

	received := string(buffer[:readCount])
	assert.Equal(t, string(secondMessage), received)
}