Пример #1
0
	"encoding/json"
	"github.com/cloudfoundry/go_cfmessagebus/mock_cfmessagebus"
	. "github.com/cloudfoundry/hm9000/models"

	"testing"
)

func TestMessagePublisher(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Message Publisher Suite")
}

var _ = Describe("MessagePublisher", func() {
	var (
		publisher      *MessagePublisher
		fakeMessageBus *mock_cfmessagebus.MockMessageBus
	)

	BeforeEach(func() {
		fakeMessageBus = mock_cfmessagebus.NewMockMessageBus()
		publisher = NewMessagePublisher(fakeMessageBus)
	})

	It("can publish hearbeats", func() {
		heartbeat := Heartbeat{
			DeaGuid: "ABC",
			InstanceHeartbeats: []InstanceHeartbeat{
				InstanceHeartbeat{
					CCPartition:    "default",
					AppGuid:        "abc",
					AppVersion:     "123",
	. "github.com/onsi/gomega"

	"github.com/cloudfoundry/go_cfmessagebus/mock_cfmessagebus"
	. "github.com/cloudfoundry/hm9000/models"

	"testing"
)

func TestStartStopListener(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Start Stop Listener Suite")
}

var _ = Describe("StartStopListener", func() {
	var (
		listener       *StartStopListener
		fakeMessageBus *mock_cfmessagebus.MockMessageBus
	)

	jsonStartMessage := `{
	            "droplet":"abc",
	            "last_updated":1377816348,
	            "version":"123",
	            "indices":[1,2],
	            "running":{"123":2},
	            "flapping":false
	        }`

	jsonStopMessage := `{
	            "droplet":"abc",
	            "last_updated":1377816348,
	            "version":"123",
)

type UserCountResponse struct {
	Counts struct {
		User int `json:"user"`
	} `json:"counts"`
}

func TestDesiredStateServer(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Desired State Server Suite")
}

var server *DesiredStateServer
var didRunGlobalBeforeEach bool
var fakeMessageBus *mock_cfmessagebus.MockMessageBus

var _ = BeforeEach(func() {
	if !didRunGlobalBeforeEach {
		fakeMessageBus = mock_cfmessagebus.NewMockMessageBus()
		server = NewDesiredStateServer(fakeMessageBus)
		go server.SpinUp(6000)
		didRunGlobalBeforeEach = true
	}

	server.Reset()
})

var _ = Describe("making requests", func() {
	var serverURL = "http://localhost:6000"