package desiredstatefetcher_test import ( "encoding/json" "fmt" . "github.com/cloudfoundry/hm9000/desiredstatefetcher" "github.com/cloudfoundry/hm9000/testhelpers/app" . "github.com/cloudfoundry/hm9000/testhelpers/custommatchers" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Desired State Server Response JSON", func() { var ( a app.App response DesiredStateServerResponse ) BeforeEach(func() { a = app.NewApp() desired, _ := json.Marshal(a.DesiredState(0)) responseJson := fmt.Sprintf(` { "results":{"%s":%s}, "bulk_token":{"id":17} } `, a.AppGuid, string(desired)) var err error response, err = NewDesiredStateServerResponse([]byte(responseJson)) Ω(err).ShouldNot(HaveOccured())
. "github.com/cloudfoundry/hm9000/store" . "github.com/cloudfoundry/hm9000/testhelpers/custommatchers" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/cloudfoundry/hm9000/config" "github.com/cloudfoundry/hm9000/models" "github.com/cloudfoundry/hm9000/storeadapter" "github.com/cloudfoundry/hm9000/testhelpers/app" ) var _ = Describe("Desired State", func() { var ( store Store etcdAdapter storeadapter.StoreAdapter conf config.Config app1 app.App app2 app.App app3 app.App ) BeforeEach(func() { var err error conf, err = config.DefaultConfig() Ω(err).ShouldNot(HaveOccured()) etcdAdapter = storeadapter.NewETCDStoreAdapter(etcdRunner.NodeURLS(), conf.StoreMaxConcurrentRequests) err = etcdAdapter.Connect() Ω(err).ShouldNot(HaveOccured()) app1 = app.NewApp() app2 = app.NewApp() app3 = app.NewApp()
Describe("Fetching batches", func() { var response DesiredStateServerResponse BeforeEach(func() { fakeMessageBus.Requests[conf.CCAuthMessageBusSubject][0].Callback([]byte(`{"user":"******","password":"******"}`)) }) It("should request a batch size with an empty bulk token", func() { query := httpClient.LastRequest().URL.Query() Ω(query.Get("batch_size")).Should(Equal(fmt.Sprintf("%d", conf.DesiredStateBatchSize))) Ω(query.Get("bulk_token")).Should(Equal("{}")) }) Context("when a response with desired state is received", func() { var ( a1 app.App a2 app.App ) BeforeEach(func() { a1 = app.NewApp() a2 = app.NewApp() response = DesiredStateServerResponse{ Results: map[string]models.DesiredAppState{ a1.AppGuid: a1.DesiredState(0), a2.AppGuid: a2.DesiredState(0), }, BulkToken: BulkToken{ Id: 5, }, }
import ( . "github.com/cloudfoundry/hm9000/analyzer" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/cloudfoundry/hm9000/config" "github.com/cloudfoundry/hm9000/models" "github.com/cloudfoundry/hm9000/storeadapter" "github.com/cloudfoundry/hm9000/testhelpers/app" ) var _ = Describe("Analyzer", func() { var ( analyzer *Analyzer etcdStoreAdapter storeadapter.StoreAdapter conf config.Config a1 app.App a2 app.App ) BeforeEach(func() { var err error conf, err = config.DefaultConfig() Ω(err).ShouldNot(HaveOccured()) etcdStoreAdapter = storeadapter.NewETCDStoreAdapter(etcdRunner.NodeURLS(), conf.StoreMaxConcurrentRequests) err = etcdStoreAdapter.Connect() Ω(err).ShouldNot(HaveOccured()) a1 = app.NewApp() a2 = app.NewApp()
import ( "errors" . "github.com/cloudfoundry/hm9000/testhelpers/fakestore" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/cloudfoundry/hm9000/models" "github.com/cloudfoundry/hm9000/storeadapter" "github.com/cloudfoundry/hm9000/testhelpers/app" . "github.com/cloudfoundry/hm9000/testhelpers/custommatchers" "time" ) var _ = Describe("FakeStore", func() { var store *FakeStore var app1 app.App var app2 app.App BeforeEach(func() { store = NewFakeStore() app1 = app.NewApp() app2 = app.NewApp() }) It("should start off empty", func() { desired, err := store.GetDesiredState() Ω(desired).Should(BeEmpty()) Ω(err).ShouldNot(HaveOccured()) actual, err := store.GetActualState() Ω(actual).Should(BeEmpty())
"github.com/cloudfoundry/hm9000/desiredstatefetcher" "github.com/cloudfoundry/hm9000/helpers/httpclient" "github.com/cloudfoundry/hm9000/helpers/timeprovider" "github.com/cloudfoundry/hm9000/models" "github.com/cloudfoundry/hm9000/store" "github.com/cloudfoundry/hm9000/storeadapter" "github.com/cloudfoundry/hm9000/testhelpers/app" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Fetching from CC and storing the result in the Store", func() { var ( fetcher *desiredstatefetcher.DesiredStateFetcher a1 app.App a2 app.App a3 app.App resultChan chan desiredstatefetcher.DesiredStateFetcherResult ) BeforeEach(func() { resultChan = make(chan desiredstatefetcher.DesiredStateFetcherResult, 1) a1 = app.NewApp() a2 = app.NewApp() a3 = app.NewApp() stateServer.SetDesiredState([]models.DesiredAppState{ a1.DesiredState(0), a2.DesiredState(0), a3.DesiredState(0), })