Beispiel #1
0
func Parse(buffer []byte) (Config, error) {
	config := Config{}
	err := json.Unmarshal(buffer, &config)
	if err != nil {
		return Config{}, err
	}

	if config.Additional == nil {
		config.Additional = jsonstruct.New()
	}

	return config, nil
}
Beispiel #2
0
		if port == 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)
Beispiel #3
0
package jsonstruct_test

import (
	"github.com/myshkin5/jsonstruct"

	"reflect"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Copy", func() {
	It("does a deep copy with no shared mutables", func() {
		orig := jsonstruct.New()
		orig.SetInt(".int-val", 737)
		orig.SetString(".sub.sub.value", "neat string")

		copy := orig.DeepCopy()

		Expect(reflect.ValueOf(orig)).NotTo(Equal(reflect.ValueOf(copy)))

		Expect(orig["int-val"]).To(Equal(copy["int-val"]))

		origSub := orig["sub"].(map[string]interface{})
		copySub, ok := copy["sub"].(map[string]interface{})
		Expect(ok).To(BeTrue())
		Expect(reflect.ValueOf(origSub)).NotTo(Equal(reflect.ValueOf(copySub)))

		origSubSub := origSub["sub"]
		copySubSub := copySub["sub"]
		Expect(reflect.ValueOf(origSubSub)).NotTo(Equal(reflect.ValueOf(copySubSub)))
Beispiel #4
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Reader", func() {
	var (
		port   int
		reader udp.Reader
	)

	BeforeEach(func() {
		if port == 0 {
			port = 51010
		}
		port++
		config := jsonstruct.New()
		config.SetInt(udp.Port, port)

		reader = udp.Reader{}
		err := reader.Init(config)
		Expect(err).NotTo(HaveOccurred())
	})

	It("reads from a UDP port", func() {
		done := make(chan struct{})
		messages := make(chan []byte, 100)
		go func() {
			defer GinkgoRecover()
			messageRead := make([]byte, 1024)
			for {
				bytesRead, err := reader.Read(messageRead)
Beispiel #5
0
			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())
			Expect(values.SetString(".value", "")).To(Succeed())

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

			Expect(values.SetString(".another", "")).To(Succeed())

			another, ok := values.String(".another")
			Expect(ok).To(BeTrue())
			Expect(another).To(Equal(""))
		})

		It("can set values multiple levels deep", func() {