"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() {
			It("returns the error", func() {
				payload = "aliens lol"
				decodedAuctioneerPresence := &models.AuctioneerPresence{}
				err := models.FromJSON([]byte(payload), decodedAuctioneerPresence)

				Expect(err).To(HaveOccurred())
			})
		})
	})
Example #2
0
			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() {
			It("returns the error", func() {
				decodedTask := &models.Task{}
				err := models.FromJSON([]byte("aliens lol"), decodedTask)
				Expect(err).To(HaveOccurred())
			})
		})

		Context("with invalid action", func() {
			var expectedTask models.Task
Example #3
0
				"port_range": {
					"start": 1,
					"end": 1024
				},
				"log": true
			},
		  {
				"protocol": "udp",
				"destinations": ["8.8.0.0/16"],
				"ports": [53],
				"log": false
			}
		],
		"completion_callback_url":{"Scheme":"http","Opaque":"","User":{},"Host":"a.b.c","Path":"/d/e/f","RawQuery":"","Fragment":""}
	}`
		err := oldmodels.FromJSON([]byte(taskPayload), &oldTask)
		Expect(err).NotTo(HaveOccurred())

		task = models.Task{
			TaskDefinition: &models.TaskDefinition{
				RootFs: "docker:///docker.com/docker",
				EnvironmentVariables: []*models.EnvironmentVariable{
					{
						Name:  "ENV_VAR_NAME",
						Value: "an environmment value",
					},
				},
				Action: models.WrapAction(&models.DownloadAction{
					From:     "old_location",
					To:       "new_location",
					CacheKey: "the-cache-key",
			})
		})
	})

	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() {
			It("returns the error", func() {
				payload = "aliens lol"
				decodedCellPresence := &models.CellPresence{}
				err := models.FromJSON([]byte(payload), decodedCellPresence)

				Expect(err).To(HaveOccurred())
			})
		})
	})
				},
			}
		})

		Describe("To JSON", func() {
			It("should JSONify", func() {
				marshalled, err := json.Marshal(&lrp)
				Expect(err).NotTo(HaveOccurred())
				Expect(string(marshalled)).To(MatchJSON(lrpPayload))
			})
		})

		Describe("FromJSON", func() {
			It("returns a LRP with correct fields", func() {
				aLRP := &models.ActualLRP{}
				err := models.FromJSON([]byte(lrpPayload), aLRP)
				Expect(err).NotTo(HaveOccurred())

				Expect(aLRP).To(Equal(&lrp))
			})

			Context("with an invalid payload", func() {
				It("returns the error", func() {
					aLRP := &models.ActualLRP{}
					err := models.FromJSON([]byte("something lol"), aLRP)
					Expect(err).To(HaveOccurred())
				})
			})

			for field, payload := range map[string]string{
				"process_guid":  `{"instance_guid": "instance_guid", "cell_id": "cell_id", "domain": "domain"}`,
	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() {
			Expect(err).NotTo(HaveOccurred())
			Expect(decodedLRPStartRequest).To(Equal(&lrpStart))
		})

		Context("with an invalid payload", func() {
			BeforeEach(func() {
				lrpStartPayload = "aliens lol"
			})

			It("returns the error", func() {
				Expect(err).To(HaveOccurred())
			})