}) JustBeforeEach(func() { migration.SetStoreClient(storeClient) migration.SetCryptor(cryptor) migrationErr = migration.Up(logger) }) var validateConversionToProto = func(node *goetcd.Node, actual, expected format.Versioner) { value := node.Value Expect(value[:2]).To(BeEquivalentTo(format.BASE64[:])) payload, err := base64.StdEncoding.DecodeString(string(value[2:])) Expect(err).NotTo(HaveOccurred()) Expect(payload[0]).To(BeEquivalentTo(format.PROTO)) serializer.Unmarshal(logger, []byte(value), actual) Expect(actual).To(Equal(expected)) } It("converts all data stored in the etcd store to base 64 protobuf", func() { Expect(migrationErr).NotTo(HaveOccurred()) By("Converting DesiredLRPs to Encoded Proto") response, err := storeClient.Get(deprecations.DesiredLRPSchemaRoot, false, true) Expect(err).NotTo(HaveOccurred()) Expect(response.Node.Nodes).To(HaveLen(1)) for _, node := range response.Node.Nodes { var desiredLRP models.DesiredLRP value := node.Value err := serializer.Unmarshal(logger, []byte(value), &desiredLRP) Expect(err).NotTo(HaveOccurred())
var actualTask models.Task err = proto.Unmarshal(unencoded[2:], &actualTask) Expect(err).NotTo(HaveOccurred()) Expect(actualTask).To(Equal(*task)) }) }) }) Describe("Unmarshal", func() { Describe("LEGACY_FORMATTING", func() { It("unmarshals the JSON data as-is without an envelope", func() { payload, err := serializer.Marshal(logger, format.LEGACY_FORMATTING, task) Expect(err).NotTo(HaveOccurred()) var decodedTask models.Task err = serializer.Unmarshal(logger, payload, &decodedTask) Expect(err).NotTo(HaveOccurred()) Expect(*task).To(Equal(decodedTask)) }) }) Describe("FORMATTED_JSON", func() { It("unmarshals the JSON data from an UNENCODED envelope", func() { payload, err := serializer.Marshal(logger, format.FORMATTED_JSON, task) Expect(err).NotTo(HaveOccurred()) var decodedTask models.Task err = serializer.Unmarshal(logger, payload, &decodedTask) Expect(err).NotTo(HaveOccurred()) Expect(*task).To(Equal(decodedTask)) })
defer rows.Close() tasks := []*models.Task{} for rows.Next() { var taskTest models.Task var encryptedDefinition []byte err := rows.Scan(&taskTest.TaskGuid, &taskTest.Domain, &taskTest.UpdatedAt, &taskTest.CreatedAt, &taskTest.FirstCompletedAt, &taskTest.State, &taskTest.CellId, &taskTest.Result, &taskTest.Failed, &taskTest.FailureReason, &encryptedDefinition) Expect(err).NotTo(HaveOccurred()) taskTest.TaskDefinition = &models.TaskDefinition{} err = serializer.Unmarshal(logger, encryptedDefinition, taskTest.TaskDefinition) Expect(err).NotTo(HaveOccurred()) tasks = append(tasks, &taskTest) } Expect(tasks).To(HaveLen(tasksToCreate)) Expect(tasks).To(ConsistOf(existingTasks)) }) }) }) Describe("Down", func() { It("returns a not implemented error", func() { Expect(migration.Down(logger)).To(HaveOccurred()) })