From f74914c3e89086a27dbc8bcea96475286a9fd246 Mon Sep 17 00:00:00 2001 From: David Laing Date: Thu, 6 Aug 2020 13:48:35 +0100 Subject: [PATCH 1/4] Find existing property GUIDs for unchanged items --- ...ducts_property_collection_guid_assigner.go | 43 ++++++ ...operty_collection_guid_assigner_test.go.go | 132 ++++++++++++++++-- api/staged_products_service_test.go | 14 +- 3 files changed, 172 insertions(+), 17 deletions(-) diff --git a/api/staged_products_property_collection_guid_assigner.go b/api/staged_products_property_collection_guid_assigner.go index 7ef24c76e..ef422cc37 100644 --- a/api/staged_products_property_collection_guid_assigner.go +++ b/api/staged_products_property_collection_guid_assigner.go @@ -83,6 +83,19 @@ func (item responsePropertyCollectionItem) getFieldValue(fieldName string) strin return "" } +func (item responsePropertyCollectionItem) getFieldValuesExceptGUID() map[interface{}]interface{} { + extractedValues := make(map[interface{}]interface{}) + + for key, valueObj := range item.Data { + if key == "guid" { + continue + } + extractedValues[key] = valueObj.(map[interface{}]interface{})["value"] + } + + return extractedValues +} + func (item responsePropertyCollectionItem) getSortedFieldNames() []string { sortedFieldNames := make([]string, 0, len(item.Data)) for k := range item.Data { @@ -128,6 +141,32 @@ func assignExistingGUIDUsingLogicalKey(updatedCollection updatedPropertyCollecti return true } +func (existingCollection responsePropertyCollection) findGUIDForIEquivalentlItem(updatedProperty updatedPropertyCollectionItem) (string, bool) { + + for _, existingCollectionItem := range existingCollection { + //use the fact that fmt prints maps in order (see: https://tip.golang.org/doc/go1.12#fmt) to check for equivalence + if fmt.Sprintf("%+v", updatedProperty.Data) == fmt.Sprintf("%+v", existingCollectionItem.getFieldValuesExceptGUID()) { + return existingCollectionItem.getFieldValue("guid"), true + } + } + + return "", false +} + +func assignExistingGUIDUsingEquivalentValue(updatedCollection updatedPropertyCollection, existingCollection responsePropertyCollection) bool { + + foundEquivalentItems := false + + for _, updatedCollectionItem := range updatedCollection { + if guid, ok := existingCollection.findGUIDForIEquivalentlItem(updatedCollectionItem); ok { + updatedCollectionItem.setFieldValue("guid", guid) + foundEquivalentItems = true + } + } + + return foundEquivalentItems +} + func associateExistingCollectionGUIDs(updatedProperty interface{}, existingProperty ResponseProperty) error { updatedCollection, err := parseUpdatedPropertyCollection(updatedProperty) if err != nil { @@ -138,6 +177,10 @@ func associateExistingCollectionGUIDs(updatedProperty interface{}, existingPrope return err } + if assignExistingGUIDUsingEquivalentValue(updatedCollection, existingCollection) { + return nil + } + if assignExistingGUIDUsingLogicalKey(updatedCollection, existingCollection) { return nil } diff --git a/api/staged_products_property_collection_guid_assigner_test.go.go b/api/staged_products_property_collection_guid_assigner_test.go.go index 7727d8300..975889efd 100644 --- a/api/staged_products_property_collection_guid_assigner_test.go.go +++ b/api/staged_products_property_collection_guid_assigner_test.go.go @@ -1,6 +1,7 @@ package api //not in api_tests because we are intentionally testing some functionality internal to the package import ( + "encoding/json" "fmt" . "github.com/onsi/ginkgo" @@ -9,9 +10,17 @@ import ( ) var _ = Describe("ResponsePropertyCollection", func() { - unmarshalJSON := func(json string) interface{} { + unmarshalJSONLikeApiGetStagedProductProperties := func(json string) interface{} { var rawCollection interface{} - err := yaml.Unmarshal([]byte(json), &rawCollection) //use yaml.Unmarshal to simulate Api.GetStagedProductProperties() + err := yaml.Unmarshal([]byte(json), &rawCollection) + if err != nil { + panic(fmt.Errorf("Failed to parse json: %w", err)) + } + return rawCollection + } + unmarshalJSON := func(rawJSON string) interface{} { + var rawCollection interface{} + err := json.Unmarshal([]byte(rawJSON), &rawCollection) if err != nil { panic(fmt.Errorf("Failed to parse json: %w", err)) } @@ -19,7 +28,7 @@ var _ = Describe("ResponsePropertyCollection", func() { } When("parseResponsePropertyCollection", func() { It("parses all the elements in the collection", func() { - collection, err := parseResponsePropertyCollection(unmarshalJSON(`[ + collection, err := parseResponsePropertyCollection(unmarshalJSONLikeApiGetStagedProductProperties(`[ { "guid": { "type": "uuid", @@ -66,7 +75,7 @@ var _ = Describe("ResponsePropertyCollection", func() { }) When("extracting field values", func() { It("correctly extracts guids", func() { - collection, err := parseResponsePropertyCollection(unmarshalJSON(`[ + collection, err := parseResponsePropertyCollection(unmarshalJSONLikeApiGetStagedProductProperties(`[ { "guid": { "type": "uuid", @@ -95,7 +104,7 @@ var _ = Describe("ResponsePropertyCollection", func() { Expect(collection[0].getFieldValue("guid")).To(Equal("28bab1d3-4a4b-48d5-8dac-two")) }) It("correctly extracts strings", func() { - collection, err := parseResponsePropertyCollection(unmarshalJSON(`[ + collection, err := parseResponsePropertyCollection(unmarshalJSONLikeApiGetStagedProductProperties(`[ { "guid": { "type": "uuid", @@ -126,7 +135,7 @@ var _ = Describe("ResponsePropertyCollection", func() { }) When("finding the logical key field", func() { It("finds a 'name' logical key", func() { - collection, err := parseResponsePropertyCollection(unmarshalJSON(`[ + collection, err := parseResponsePropertyCollection(unmarshalJSONLikeApiGetStagedProductProperties(`[ { "guid": { "type": "uuid", @@ -158,7 +167,7 @@ var _ = Describe("ResponsePropertyCollection", func() { Expect(key).To(Equal("name")) }) It("fails to find a logical key when there isn't one", func() { - collection, err := parseResponsePropertyCollection(unmarshalJSON(`[ + collection, err := parseResponsePropertyCollection(unmarshalJSONLikeApiGetStagedProductProperties(`[ { "guid": { "type": "uuid", @@ -184,7 +193,7 @@ var _ = Describe("ResponsePropertyCollection", func() { }) It("finds a 'key' logical key", func() { - collection, err := parseResponsePropertyCollection(unmarshalJSON(`[ + collection, err := parseResponsePropertyCollection(unmarshalJSONLikeApiGetStagedProductProperties(`[ { "guid": { "type": "uuid", @@ -216,7 +225,7 @@ var _ = Describe("ResponsePropertyCollection", func() { Expect(key).To(Equal("key")) }) It("finds a logical key ending in 'name'", func() { - collection, err := parseResponsePropertyCollection(unmarshalJSON(`[ + collection, err := parseResponsePropertyCollection(unmarshalJSONLikeApiGetStagedProductProperties(`[ { "guid": { "type": "uuid", @@ -248,7 +257,7 @@ var _ = Describe("ResponsePropertyCollection", func() { Expect(key).To(Equal("sqlServerName")) }) It("picks 'name' as the logical key when there is a 'name' field AND a field that ends in 'name' (eg: Filename)", func() { - collection, err := parseResponsePropertyCollection(unmarshalJSON(`[ + collection, err := parseResponsePropertyCollection(unmarshalJSONLikeApiGetStagedProductProperties(`[ { "guid": { "type": "uuid", @@ -280,4 +289,107 @@ var _ = Describe("ResponsePropertyCollection", func() { Expect(key).To(Equal("name")) }) }) + When("matching based on item contents", func() { + It("finds items that are identical", func() { + existingCollection, err := parseResponsePropertyCollection(unmarshalJSONLikeApiGetStagedProductProperties(`[ + { + "guid": { + "type": "uuid", + "configurable": false, + "credential": false, + "value": "28bab1d3-4a4b-48d5-8dac-one", + "optional": false + }, + "a_property": { + "type": "string", + "configurable": true, + "credential": false, + "value": "\"value\" of 'first' item", + "optional": false + }, + "another_property": { + "type": "boolean", + "configurable": true, + "credential": false, + "value": true, + "optional": false + } + }, + { + "guid": { + "type": "uuid", + "configurable": false, + "credential": false, + "value": "28bab1d3-4a4b-48d5-8dac-two", + "optional": false + }, + "a_property": { + "type": "string", + "configurable": true, + "credential": false, + "value": "\"value\" of 'second' item", + "optional": false + }, + "another_property": { + "type": "boolean", + "configurable": true, + "credential": false, + "value": true, + "optional": false + } + } + ]`)) + Expect(err).To(BeNil()) + updatedCollection, err := parseUpdatedPropertyCollection(unmarshalJSON(`{ "value":[ + { + "a_property": "\"value\" of 'second' item", + "another_property": true + } + ]}`)) + Expect(err).To(BeNil()) + + guid, ok := existingCollection.findGUIDForIEquivalentlItem(updatedCollection[0]) + Expect(ok).To(BeTrue()) + Expect(guid).To(Equal("28bab1d3-4a4b-48d5-8dac-two")) + }) + It("finds items that are equivalent but have a different key order", func() { + existingCollection, err := parseResponsePropertyCollection(unmarshalJSONLikeApiGetStagedProductProperties(`[ + { + "guid": { + "type": "uuid", + "configurable": false, + "credential": false, + "value": "28bab1d3-4a4b-48d5-8dac-two", + "optional": false + }, + "a_property": { + "type": "string", + "configurable": true, + "credential": false, + "value": "\"value\" of 'second' item", + "optional": false + }, + "another_property": { + "type": "boolean", + "configurable": true, + "credential": false, + "value": true, + "optional": false + } + } + ]`)) + Expect(err).To(BeNil()) + updatedCollection, err := parseUpdatedPropertyCollection(unmarshalJSON(`{ "value":[ + { + "another_property": true, + "a_property": "\"value\" of 'second' item" + } + ]}`)) + Expect(err).To(BeNil()) + + guid, ok := existingCollection.findGUIDForIEquivalentlItem(updatedCollection[0]) + Expect(ok).To(BeTrue()) + Expect(guid).To(Equal("28bab1d3-4a4b-48d5-8dac-two")) + }) + }) }) diff --git a/api/staged_products_service_test.go b/api/staged_products_service_test.go index ec145de59..a0b5cb14d 100644 --- a/api/staged_products_service_test.go +++ b/api/staged_products_service_test.go @@ -485,11 +485,11 @@ valid options configurations include percentages ('50%'), counts ('2'), and 'def "value": "28bab1d3-4a4b-48d5-8dac-796adf078100", "optional": false }, - "name": { + "label": { "type": "string", "configurable": true, "credential": false, - "value": "the_name", + "value": "the_label", "optional": false }, "some_property": { @@ -619,7 +619,7 @@ valid options configurations include percentages ('50%'), counts ('2'), and 'def }) Context("configure product contains collection", func() { - It("adds the guid for elements that exist", func() { + It("adds the guid for elements that exist and haven't changed, but don't have a logical key field", func() { client.AppendHandlers( ghttp.CombineHandlers( ghttp.VerifyRequest("PUT", "/api/v0/staged/products/some-product-guid/properties"), @@ -629,8 +629,8 @@ valid options configurations include percentages ('50%'), counts ('2'), and 'def "key": "value", "some_collection": { "value": [{ - "name": "the_name", - "some_property": "property_value", + "label": "the_label", + "some_property": true, "guid": "28bab1d3-4a4b-48d5-8dac-796adf078100" }] } @@ -647,8 +647,8 @@ valid options configurations include percentages ('50%'), counts ('2'), and 'def "some_collection": { "value": [ { - "name": "the_name", - "some_property": "property_value" + "some_property": true, + "label": "the_label" } ] } From d17b3b7de0e3c435ea14951bb05dbc0616b95a93 Mon Sep 17 00:00:00 2001 From: David Laing Date: Fri, 7 Aug 2020 13:32:31 +0100 Subject: [PATCH 2/4] Update CHANGELOG --- CHANGELOG.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02a022a80..a74c7a4a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,7 +50,14 @@ can be found in [Pivotal Documentation](docs.pivotal.io/platform-automation). ## 6.2.0 ### Features -- `configure-product`'s _decorating collection with guid based on `name` logical key_ logic has been extended to also use `key` or fields ending in `name` as logical keys. Resolves [#207](https://github.com/pivotal-cf/om/issues/207) +- `configure-product`'s _decorating collection with guid_ logic has been extended to associate existing collection item guids based on (in order) + - equivalent item values + - equal logical keys (in order; ie. 'name' will be used over 'Filename' if both exist) + - `name` + - `key` + - fields ending in `name` (eg: `sqlServerName`) + + This addresses [#207](https://github.com/pivotal-cf/om/issues/207); improving GitOps style workflows ## 6.1.0 From 70325ba117ef5f46ea45716e62334d7092e011e6 Mon Sep 17 00:00:00 2001 From: David Laing Date: Tue, 11 Aug 2020 20:22:42 +0100 Subject: [PATCH 3/4] Associated the guid using different strategies for different items in the same collection --- ...ducts_property_collection_guid_assigner.go | 52 ++++---------- ...operty_collection_guid_assigner_test.go.go | 4 +- api/staged_products_service_test.go | 70 ++++++++++++++++++- 3 files changed, 82 insertions(+), 44 deletions(-) diff --git a/api/staged_products_property_collection_guid_assigner.go b/api/staged_products_property_collection_guid_assigner.go index ef422cc37..c51c79f44 100644 --- a/api/staged_products_property_collection_guid_assigner.go +++ b/api/staged_products_property_collection_guid_assigner.go @@ -121,27 +121,7 @@ func (item responsePropertyCollectionItem) findLogicalKeyField() (string, bool) return "", false } -func assignExistingGUIDUsingLogicalKey(updatedCollection updatedPropertyCollection, existingCollection responsePropertyCollection) bool { - //since all collection items have the same structure; only need to find the logical key from the first one - logicalKeyFieldName, found := existingCollection[0].findLogicalKeyField() - if !found { - return false - } - - for _, updatedCollectionItem := range updatedCollection { - updatedCollectionItemLogicalKeyValue := updatedCollectionItem.getFieldValue(logicalKeyFieldName) - for _, existingCollectionItem := range existingCollection { - if updatedCollectionItemLogicalKeyValue == existingCollectionItem.getFieldValue(logicalKeyFieldName) { - updatedCollectionItem.setFieldValue("guid", existingCollectionItem.getFieldValue("guid")) - break //move onto the next updatedCollectionItem - } - } - } - - return true -} - -func (existingCollection responsePropertyCollection) findGUIDForIEquivalentlItem(updatedProperty updatedPropertyCollectionItem) (string, bool) { +func (existingCollection responsePropertyCollection) findGUIDForEquivalentlItem(updatedProperty updatedPropertyCollectionItem) (string, bool) { for _, existingCollectionItem := range existingCollection { //use the fact that fmt prints maps in order (see: https://tip.golang.org/doc/go1.12#fmt) to check for equivalence @@ -153,20 +133,6 @@ func (existingCollection responsePropertyCollection) findGUIDForIEquivalentlItem return "", false } -func assignExistingGUIDUsingEquivalentValue(updatedCollection updatedPropertyCollection, existingCollection responsePropertyCollection) bool { - - foundEquivalentItems := false - - for _, updatedCollectionItem := range updatedCollection { - if guid, ok := existingCollection.findGUIDForIEquivalentlItem(updatedCollectionItem); ok { - updatedCollectionItem.setFieldValue("guid", guid) - foundEquivalentItems = true - } - } - - return foundEquivalentItems -} - func associateExistingCollectionGUIDs(updatedProperty interface{}, existingProperty ResponseProperty) error { updatedCollection, err := parseUpdatedPropertyCollection(updatedProperty) if err != nil { @@ -177,12 +143,18 @@ func associateExistingCollectionGUIDs(updatedProperty interface{}, existingPrope return err } - if assignExistingGUIDUsingEquivalentValue(updatedCollection, existingCollection) { - return nil - } + for _, updatedCollectionItem := range updatedCollection { + if guid, ok := existingCollection.findGUIDForEquivalentlItem(updatedCollectionItem); ok { + updatedCollectionItem.setFieldValue("guid", guid) + } else if logicalKeyFieldName, ok := existingCollection[0].findLogicalKeyField(); ok { + updatedCollectionItemLogicalKeyValue := updatedCollectionItem.getFieldValue(logicalKeyFieldName) + for _, existingCollectionItem := range existingCollection { + if updatedCollectionItemLogicalKeyValue == existingCollectionItem.getFieldValue(logicalKeyFieldName) { + updatedCollectionItem.setFieldValue("guid", existingCollectionItem.getFieldValue("guid")) + } + } + } - if assignExistingGUIDUsingLogicalKey(updatedCollection, existingCollection) { - return nil } return nil diff --git a/api/staged_products_property_collection_guid_assigner_test.go.go b/api/staged_products_property_collection_guid_assigner_test.go.go index 975889efd..c60edcfda 100644 --- a/api/staged_products_property_collection_guid_assigner_test.go.go +++ b/api/staged_products_property_collection_guid_assigner_test.go.go @@ -348,7 +348,7 @@ var _ = Describe("ResponsePropertyCollection", func() { ]}`)) Expect(err).To(BeNil()) - guid, ok := existingCollection.findGUIDForIEquivalentlItem(updatedCollection[0]) + guid, ok := existingCollection.findGUIDForEquivalentlItem(updatedCollection[0]) Expect(ok).To(BeTrue()) Expect(guid).To(Equal("28bab1d3-4a4b-48d5-8dac-two")) }) @@ -387,7 +387,7 @@ var _ = Describe("ResponsePropertyCollection", func() { ]}`)) Expect(err).To(BeNil()) - guid, ok := existingCollection.findGUIDForIEquivalentlItem(updatedCollection[0]) + guid, ok := existingCollection.findGUIDForEquivalentlItem(updatedCollection[0]) Expect(ok).To(BeTrue()) Expect(guid).To(Equal("28bab1d3-4a4b-48d5-8dac-two")) }) diff --git a/api/staged_products_service_test.go b/api/staged_products_service_test.go index a0b5cb14d..537cd66cd 100644 --- a/api/staged_products_service_test.go +++ b/api/staged_products_service_test.go @@ -522,10 +522,32 @@ valid options configurations include percentages ('50%'), counts ('2'), and 'def "optional": false }, "some_property": { - "type": "boolean", + "type": "string", "configurable": true, "credential": false, - "value": true, + "value": "some property value", + "optional": false + } + },{ + "guid": { + "type": "uuid", + "configurable": false, + "credential": false, + "value": "28bab1d3-4a4b-48d5-8dac-with-name-two", + "optional": false + }, + "name": { + "type": "string", + "configurable": true, + "credential": false, + "value": "the_name_two", + "optional": false + }, + "some_property": { + "type": "string", + "configurable": true, + "credential": false, + "value": "some property value two", "optional": false } }], @@ -767,6 +789,50 @@ valid options configurations include percentages ('50%'), counts ('2'), and 'def }) Expect(err).ToNot(HaveOccurred()) }) + It("adds the guid using different strategies for different items in the same collection", func() { + client.AppendHandlers( + ghttp.CombineHandlers( + ghttp.VerifyRequest("PUT", "/api/v0/staged/products/some-product-guid/properties"), + ghttp.VerifyContentType("application/json"), + ghttp.VerifyJSON(`{ + "properties": { + "key": "value", + "collection_with_name": { + "value": [{ + "name": "the_name", + "some_property": "some property value", + "guid": "28bab1d3-4a4b-48d5-8dac-with-name" + },{ + "name": "the_name_two", + "some_property": "changed, so should find guid based on logical key rather than equivalence", + "guid": "28bab1d3-4a4b-48d5-8dac-with-name-two" + }] + } + } + }`), + ghttp.RespondWith(http.StatusOK, `{}`), + ), + ) + + err := service.UpdateStagedProductProperties(api.UpdateStagedProductPropertiesInput{ + GUID: "some-product-guid", + Properties: `{ + "key": "value", + "collection_with_name": { + "value": [ + { + "name": "the_name", + "some_property": "some property value" + },{ + "name": "the_name_two", + "some_property": "changed, so should find guid based on logical key rather than equivalence" + } + ] + } + }`, + }) + Expect(err).ToNot(HaveOccurred()) + }) It("no guid added", func() { client.AppendHandlers( ghttp.CombineHandlers( From 8a43e6df7a8ce99414c59e2513e951d73832f691 Mon Sep 17 00:00:00 2001 From: David Laing Date: Tue, 11 Aug 2020 20:35:57 +0100 Subject: [PATCH 4/4] Detect a collection item's logical key using the updated rather than existing item data --- ...ducts_property_collection_guid_assigner.go | 52 +++---- ...operty_collection_guid_assigner_test.go.go | 129 +++--------------- 2 files changed, 46 insertions(+), 135 deletions(-) diff --git a/api/staged_products_property_collection_guid_assigner.go b/api/staged_products_property_collection_guid_assigner.go index c51c79f44..3c76c2653 100644 --- a/api/staged_products_property_collection_guid_assigner.go +++ b/api/staged_products_property_collection_guid_assigner.go @@ -22,6 +22,31 @@ func (item updatedPropertyCollectionItem) setFieldValue(fieldName string, value item.Data[fieldName] = value } +func (item updatedPropertyCollectionItem) getSortedFieldNames() []string { + sortedFieldNames := make([]string, 0, len(item.Data)) + for k := range item.Data { + sortedFieldNames = append(sortedFieldNames, fmt.Sprintf("%v", k)) + } + sort.Strings(sortedFieldNames) + + return sortedFieldNames +} + +func (item updatedPropertyCollectionItem) findLogicalKeyField() (string, bool) { + //search order is important; 'name' should be found before 'ending-with-name' + regexes := []string{"^name$", "^key$", "(?i)name$"} + for _, regex := range regexes { + compiledRegex := regexp.MustCompile(regex) + for _, fieldName := range item.getSortedFieldNames() { + if compiledRegex.MatchString(fieldName) { + return fieldName, true + } + } + } + + return "", false +} + func parseUpdatedPropertyCollection(updatedProperty interface{}) (updatedPropertyCollection, error) { var collection updatedPropertyCollection @@ -96,31 +121,6 @@ func (item responsePropertyCollectionItem) getFieldValuesExceptGUID() map[interf return extractedValues } -func (item responsePropertyCollectionItem) getSortedFieldNames() []string { - sortedFieldNames := make([]string, 0, len(item.Data)) - for k := range item.Data { - sortedFieldNames = append(sortedFieldNames, fmt.Sprintf("%v", k)) - } - sort.Strings(sortedFieldNames) - - return sortedFieldNames -} - -func (item responsePropertyCollectionItem) findLogicalKeyField() (string, bool) { - //search order is important; 'name' should be found before 'ending-with-name' - regexes := []string{"^name$", "^key$", "(?i)name$"} - for _, regex := range regexes { - compiledRegex := regexp.MustCompile(regex) - for _, fieldName := range item.getSortedFieldNames() { - if compiledRegex.MatchString(fieldName) { - return fieldName, true - } - } - } - - return "", false -} - func (existingCollection responsePropertyCollection) findGUIDForEquivalentlItem(updatedProperty updatedPropertyCollectionItem) (string, bool) { for _, existingCollectionItem := range existingCollection { @@ -146,7 +146,7 @@ func associateExistingCollectionGUIDs(updatedProperty interface{}, existingPrope for _, updatedCollectionItem := range updatedCollection { if guid, ok := existingCollection.findGUIDForEquivalentlItem(updatedCollectionItem); ok { updatedCollectionItem.setFieldValue("guid", guid) - } else if logicalKeyFieldName, ok := existingCollection[0].findLogicalKeyField(); ok { + } else if logicalKeyFieldName, ok := updatedCollectionItem.findLogicalKeyField(); ok { updatedCollectionItemLogicalKeyValue := updatedCollectionItem.getFieldValue(logicalKeyFieldName) for _, existingCollectionItem := range existingCollection { if updatedCollectionItemLogicalKeyValue == existingCollectionItem.getFieldValue(logicalKeyFieldName) { diff --git a/api/staged_products_property_collection_guid_assigner_test.go.go b/api/staged_products_property_collection_guid_assigner_test.go.go index c60edcfda..c60e61eb0 100644 --- a/api/staged_products_property_collection_guid_assigner_test.go.go +++ b/api/staged_products_property_collection_guid_assigner_test.go.go @@ -133,33 +133,14 @@ var _ = Describe("ResponsePropertyCollection", func() { Expect(collection[0].getFieldValue("name")).To(Equal("the_name")) }) }) - When("finding the logical key field", func() { + When("parseUpdatedPropertyCollection: finding the logical key field", func() { It("finds a 'name' logical key", func() { - collection, err := parseResponsePropertyCollection(unmarshalJSONLikeApiGetStagedProductProperties(`[ + collection, err := parseUpdatedPropertyCollection(unmarshalJSON(`{ "value":[ { - "guid": { - "type": "uuid", - "configurable": false, - "credential": false, - "value": "28bab1d3-4a4b-48d5-8dac-two", - "optional": false - }, - "name": { - "type": "string", - "configurable": true, - "credential": false, - "value": "the_name", - "optional": false - }, - "yet_another_property": { - "type": "boolean", - "configurable": true, - "credential": false, - "value": false, - "optional": false - } + "name": "the_name", + "yet_another_property": false } - ]`)) + ]}`)) Expect(err).To(BeNil()) key, ok := collection[0].findLogicalKeyField() @@ -167,24 +148,11 @@ var _ = Describe("ResponsePropertyCollection", func() { Expect(key).To(Equal("name")) }) It("fails to find a logical key when there isn't one", func() { - collection, err := parseResponsePropertyCollection(unmarshalJSONLikeApiGetStagedProductProperties(`[ + collection, err := parseUpdatedPropertyCollection(unmarshalJSON(`{ "value":[ { - "guid": { - "type": "uuid", - "configurable": false, - "credential": false, - "value": "28bab1d3-4a4b-48d5-8dac-one", - "optional": false - }, - "some_property": { - "type": "boolean", - "configurable": true, - "credential": false, - "value": "true", - "optional": false - } + "some_property": false } - ]`)) + ]}`)) Expect(err).To(BeNil()) key, ok := collection[0].findLogicalKeyField() @@ -193,31 +161,12 @@ var _ = Describe("ResponsePropertyCollection", func() { }) It("finds a 'key' logical key", func() { - collection, err := parseResponsePropertyCollection(unmarshalJSONLikeApiGetStagedProductProperties(`[ + collection, err := parseUpdatedPropertyCollection(unmarshalJSON(`{ "value":[ { - "guid": { - "type": "uuid", - "configurable": false, - "credential": false, - "value": "28bab1d3-4a4b-48d5-8dac-three", - "optional": false - }, - "key": { - "type": "string", - "configurable": true, - "credential": false, - "value": "the_key", - "optional": false - }, - "some_additional_property": { - "type": "boolean", - "configurable": true, - "credential": false, - "value": false, - "optional": false - } + "key": "the_key", + "some_additional_property": false } - ]`)) + ]}`)) Expect(err).To(BeNil()) key, ok := collection[0].findLogicalKeyField() @@ -225,31 +174,12 @@ var _ = Describe("ResponsePropertyCollection", func() { Expect(key).To(Equal("key")) }) It("finds a logical key ending in 'name'", func() { - collection, err := parseResponsePropertyCollection(unmarshalJSONLikeApiGetStagedProductProperties(`[ + collection, err := parseUpdatedPropertyCollection(unmarshalJSON(`{ "value":[ { - "guid": { - "type": "uuid", - "configurable": false, - "credential": false, - "value": "28bab1d3-4a4b-48d5-8dac-four", - "optional": false - }, - "sqlServerName": { - "type": "string", - "configurable": true, - "credential": false, - "value": "the_sqlserver_name", - "optional": false - }, - "some_additional_property": { - "type": "boolean", - "configurable": true, - "credential": false, - "value": false, - "optional": false - } + "sqlServerName": "the_sqlserver_name", + "some_additional_property": false } - ]`)) + ]}`)) Expect(err).To(BeNil()) key, ok := collection[0].findLogicalKeyField() @@ -257,31 +187,12 @@ var _ = Describe("ResponsePropertyCollection", func() { Expect(key).To(Equal("sqlServerName")) }) It("picks 'name' as the logical key when there is a 'name' field AND a field that ends in 'name' (eg: Filename)", func() { - collection, err := parseResponsePropertyCollection(unmarshalJSONLikeApiGetStagedProductProperties(`[ + collection, err := parseUpdatedPropertyCollection(unmarshalJSON(`{ "value":[ { - "guid": { - "type": "uuid", - "configurable": false, - "credential": false, - "value": "28bab1d3-4a4b-48d5-8dac-five", - "optional": false - }, - "name": { - "type": "string", - "configurable": true, - "credential": false, - "value": "the_name", - "optional": false - }, - "Filename": { - "type": "string", - "configurable": true, - "credential": false, - "value": "important_data.tgz", - "optional": false - } + "name": "the_name", + "Filename": "important_data.tgz" } - ]`)) + ]}`)) Expect(err).To(BeNil()) key, ok := collection[0].findLogicalKeyField()