Example #1
0
	"github.com/cloudfoundry-incubator/receptor/serialization"
	"github.com/cloudfoundry-incubator/runtime-schema/bbs/shared"
	"github.com/cloudfoundry-incubator/runtime-schema/models"
	"github.com/tedsuo/ifrit/ginkgomon"

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

var _ = Describe("Cell API", func() {
	var cellPresence models.CellPresence

	BeforeEach(func() {
		capacity := models.NewCellCapacity(128, 1024, 6)
		cellPresence = models.NewCellPresence("cell-0", "1.2.3.4", "the-zone", capacity, []string{}, []string{})
		value, err := models.ToJSON(cellPresence)

		_, err = consulSession.SetPresence(shared.CellSchemaPath(cellPresence.CellID), value)
		Expect(err).NotTo(HaveOccurred())

		receptorProcess = ginkgomon.Invoke(receptorRunner)
	})

	AfterEach(func() {
		ginkgomon.Kill(receptorProcess)
	})

	Describe("GET /v1/cells", func() {
		var cellResponses []receptor.CellResponse
		var getErr error
	var auctioneerPresence models.AuctioneerPresence

	var payload string

	BeforeEach(func() {
		auctioneerPresence = models.NewAuctioneerPresence("some-id", "some-address")

		payload = `{
    "auctioneer_id":      "some-id",
    "auctioneer_address": "some-address"
  }`
	})

	Describe("ToJSON", func() {
		It("should JSONify", func() {
			json, err := models.ToJSON(&auctioneerPresence)
			Expect(err).NotTo(HaveOccurred())
			Expect(string(json)).To(MatchJSON(payload))
		})
	})

	Describe("FromJSON", func() {
		It("returns an AuctioneerPresence with correct fields", func() {
			decodedAuctioneerPresence := &models.AuctioneerPresence{}
			err := models.FromJSON([]byte(payload), decodedAuctioneerPresence)
			Expect(err).NotTo(HaveOccurred())

			Expect(decodedAuctioneerPresence).To(Equal(&auctioneerPresence))
		})

		Context("with an invalid payload", func() {
Example #3
0
						Path: "ls",
						User: "******",
					},
					EgressRules: []models.SecurityGroupRule{
						{Protocol: "invalid"},
					},
				},
			},
		} {
			testValidatorErrorCase(testCase)
		}
	})

	Describe("Marshal", func() {
		It("should JSONify", func() {
			json, err := models.ToJSON(&task)
			Expect(err).NotTo(HaveOccurred())
			Expect(string(json)).To(MatchJSON(taskPayload))
		})
	})

	Describe("Unmarshal", func() {
		It("returns a Task with correct fields", func() {
			decodedTask := &models.Task{}
			err := models.FromJSON([]byte(taskPayload), decodedTask)
			Expect(err).NotTo(HaveOccurred())

			Expect(decodedTask).To(Equal(&task))
		})

		Context("with an invalid payload", func() {
	}`

	BeforeEach(func() {
		rule = models.SecurityGroupRule{
			Protocol:     models.TCPProtocol,
			Destinations: []string{"1.2.3.4/16"},
			PortRange: &models.PortRange{
				Start: 1,
				End:   1024,
			},
		}
	})

	Describe("To JSON", func() {
		It("should JSONify a rule", func() {
			json, err := models.ToJSON(&rule)
			Expect(err).NotTo(HaveOccurred())
			Expect(string(json)).To(MatchJSON(rulePayload))
		})

		It("should JSONify icmp info", func() {
			icmpRule := models.SecurityGroupRule{
				Protocol:     models.ICMPProtocol,
				Destinations: []string{"1.2.3.4/16"},
				IcmpInfo:     &models.ICMPInfo{},
			}

			json, err := models.ToJSON(&icmpRule)
			Expect(err).NotTo(HaveOccurred())
			Expect(string(json)).To(MatchJSON(`{"protocol": "icmp", "destinations": ["1.2.3.4/16"], "icmp_info": {"type":0,"code":0}, "log":false }`))
		})
					BeforeEach(func() {
						cellPresence.Capacity.DiskMB = -1
					})
					It("returns an error", func() {
						err := cellPresence.Validate()
						Expect(err).To(HaveOccurred())
						Expect(err.Error()).To(ContainSubstring("disk_mb"))
					})
				})
			})
		})
	})

	Describe("ToJSON", func() {
		It("should JSONify", func() {
			json, err := models.ToJSON(&cellPresence)
			Expect(err).NotTo(HaveOccurred())
			Expect(string(json)).To(MatchJSON(payload))
		})
	})

	Describe("FromJSON", func() {
		It("returns a CellPresence with correct fields", func() {
			decodedCellPresence := &models.CellPresence{}
			err := models.FromJSON([]byte(payload), decodedCellPresence)
			Expect(err).NotTo(HaveOccurred())

			Expect(decodedCellPresence).To(Equal(&cellPresence))
		})

		Context("with an invalid payload", func() {
				MetricsGuid: "metrics-guid",
				Action: &models.DownloadAction{
					From: "http://example.com",
					To:   "/tmp/internet",
				},
				ModificationTag: models.ModificationTag{
					Epoch: "some-epoch",
					Index: 50,
				},
			},
		}
	})

	Describe("ToJSON", func() {
		It("should JSONify", func() {
			jsonPayload, err := models.ToJSON(&lrpStart)
			Expect(err).NotTo(HaveOccurred())
			Expect(string(jsonPayload)).To(MatchJSON(lrpStartPayload))
		})
	})

	Describe("FromJSON", func() {
		var decodedLRPStartRequest *models.LRPStartRequest
		var err error

		JustBeforeEach(func() {
			decodedLRPStartRequest = &models.LRPStartRequest{}
			err = models.FromJSON([]byte(lrpStartPayload), decodedLRPStartRequest)
		})

		It("returns a LRP with correct fields", func() {