示例#1
0
	var (
		values jsonstruct.JSONStruct
	)

	Describe("SetString()", func() {
		It("overrides existing values", func() {
			err := json.Unmarshal([]byte(`{
				"this": "that",
				"parent": {
					"child": "value"
				}
			}`), &values)

			Expect(err).NotTo(HaveOccurred())

			Expect(values.SetString(".this", "something else")).To(Succeed())

			value, ok := values.String(".this")
			Expect(ok).To(BeTrue())
			Expect(value).To(Equal("something else"))

			Expect(values.SetString(".parent.child", "new value")).To(Succeed())

			value, ok = values.String(".parent.child")
			Expect(ok).To(BeTrue())
			Expect(value).To(Equal("new value"))
		})

		It("can set a string to empty string", func() {
			values = jsonstruct.New()
			Expect(values.SetString(".value", "something")).To(Succeed())
示例#2
0
			port = 49282
		}
		port++

		go func() {
			defer GinkgoRecover()
			err := http.ListenAndServe(fmt.Sprintf("localhost:%d", port), http.HandlerFunc(handle))
			Expect(err).NotTo(HaveOccurred())
		}()

		events = []*vitosse.Event{}

		time.Sleep(50 * time.Millisecond)

		config = jsonstruct.New()
		config.SetString(sse.RemoteWriterAddr, "localhost")
		config.SetInt(sse.Port, port)

		reader = sse.Reader{}
	})

	It("connects to a writer via HTTP and reads SSE messages", func() {
		event := &vitosse.Event{
			ID:   "event-id",
			Name: "event-name",
			Data: make([]byte, 100),
		}
		events = append(events, event)
		events = append(events, event)

		err := reader.Init(config)
示例#3
0
var _ = Describe("Scheme", func() {
	var (
		writer *mocks.MockWriter
		reader *mocks.MockReader
		scheme *simple.Scheme
		config jsonstruct.JSONStruct
	)

	BeforeEach(func() {
		writer = mocks.NewMockWriter()
		reader = mocks.NewMockReader()
		scheme = &simple.Scheme{}
		config = jsonstruct.New()
		config.SetInt(simple.BytesPerMessage, 1000)
		config.SetInt(simple.MessagesPerRun, 100)
		config.SetString(simple.WaitForLastMessage, "100ms")
	})

	Context("with a short wait time", func() {
		JustBeforeEach(func() {
			config.SetString(simple.WaitForLastMessage, "100ms")
			err := scheme.Init(config)
			Expect(err).NotTo(HaveOccurred())
		})

		It("writes messages to a writer", func() {
			wg := sync.WaitGroup{}
			wg.Add(1)
			go func() {
				defer wg.Done()
				scheme.RunWriter(writer)