Example #1
0
File: main.go Project: st3v/cfkit
func appHandler(rw http.ResponseWriter, req *http.Request) {
	app, err := env.Application()
	if err != nil {
		fmt.Fprint(rw, err.Error())
		rw.WriteHeader(http.StatusInternalServerError)
		return
	}

	out, err := json.Marshal(app)
	if err != nil {
		fmt.Fprint(rw, err.Error())
		rw.WriteHeader(http.StatusInternalServerError)
		return
	}

	fmt.Fprint(rw, string(out))
}
Example #2
0
		// override os.Exit in tests
		atomic.StoreInt32(&exitCode, 0)
		exit = func(i int) {
			atomic.AddInt32(&exitCode, 1)
		}

		fakeClient = new(fake.Client)
		fakeClient.HeartbeatIntervalReturns(10 * time.Millisecond)

		clientProvider = func() (Client, error) {
			return fakeClient, nil
		}

		var err error
		expectedApp, err = env.Application()
		Expect(err).ToNot(HaveOccurred())
	})

	AfterEach(func() {
		Disable()
		clientProvider = origClientProvider
		os.Unsetenv("VCAP_APPLICATION")
	})

	Describe(".Enable", func() {
		It("registers the app with eureka", func() {
			Enable()
			Eventually(fakeClient.RegisterCallCount).Should(Equal(1))
			Expect(fakeClient.RegisterArgsForCall(0)).To(Equal(expectedApp))
		})
Example #3
0
		BeforeEach(func() {
			os.Setenv("VCAP_APPLICATION", vcapApplication)
			os.Setenv("CF_INSTANCE_IP", "1.2.3.4")
			os.Setenv("CF_INSTANCE_PORT", "12345")
			os.Setenv("CF_INSTANCE_ADDR", "1.2.3.4:12345")
		})

		AfterEach(func() {
			os.Unsetenv("VCAP_APPLICATION")
			os.Unsetenv("CF_INSTANCE_IP")
			os.Unsetenv("CF_INSTANCE_PORT")
			os.Unsetenv("CF_INSTANCE_ADDR")
		})

		It("does not return an error", func() {
			_, err := env.Application()
			Expect(err).ToNot(HaveOccurred())
		})

		It("correctly initializes all values", func() {
			app, _ := env.Application()
			Expect(app.ID).To(Equal("e16ad474-0e22-42d4-98c7-d41ed0eec123"))
			Expect(app.Name).To(Equal("cfkit"))
			Expect(app.URIs).To(HaveLen(1))
			Expect(app.URIs[0]).To(Equal("cfkit.cfapps.io"))
			Expect(app.Host).To(Equal("0.0.0.0"))
			Expect(app.Port).To(Equal(63940))
			Expect(app.Addr).To(Equal("0.0.0.0:63940"))
			Expect(app.Version).To(Equal("e53f75c2-3723-47dd-b988-67c296a998ca"))
			Expect(app.Limits.Memory).To(Equal(64))
			Expect(app.Limits.Disk).To(Equal(1024))