. "github.com/cloudfoundry/hm9000/models"
	. "github.com/cloudfoundry/hm9000/testhelpers/app"

	"github.com/cloudfoundry/go_cfmessagebus/fake_cfmessagebus"
	"github.com/cloudfoundry/hm9000/config"
	"github.com/cloudfoundry/hm9000/testhelpers/fakelogger"
	"github.com/cloudfoundry/hm9000/testhelpers/fakestore"
	"github.com/cloudfoundry/hm9000/testhelpers/faketimeprovider"
)

var _ = Describe("Actual state listener", func() {
	var (
		app          App
		anotherApp   App
		store        *fakestore.FakeStore
		listener     *ActualStateListener
		timeProvider *faketimeprovider.FakeTimeProvider
		messageBus   *fake_cfmessagebus.FakeMessageBus
		logger       *fakelogger.FakeLogger
		conf         config.Config
	)

	BeforeEach(func() {
		var err error
		conf, err = config.DefaultConfig()
		Ω(err).ShouldNot(HaveOccured())

		timeProvider = &faketimeprovider.FakeTimeProvider{
			TimeToProvide: time.Now(),
		}

		app = NewApp()
type brokenReader struct{}

func (b *brokenReader) Read([]byte) (int, error) {
	return 0, errors.New("oh no you didn't!")
}

func (b *brokenReader) Close() error {
	return nil
}

var _ = Describe("DesiredStateFetcher", func() {
	var (
		conf           config.Config
		fakeMessageBus *fake_cfmessagebus.FakeMessageBus
		fetcher        *DesiredStateFetcher
		httpClient     *fakehttpclient.FakeHttpClient
		timeProvider   *faketimeprovider.FakeTimeProvider
		store          *fakestore.FakeStore
		resultChan     chan DesiredStateFetcherResult
	)

	BeforeEach(func() {
		var err error
		conf, err = config.DefaultConfig()
		Ω(err).ShouldNot(HaveOccured())

		resultChan = make(chan DesiredStateFetcherResult, 1)
		timeProvider = &faketimeprovider.FakeTimeProvider{
			TimeToProvide: time.Now(),
		}