Skip to content

Commit

Permalink
Merge branch 'develop' into feature/handle-null-keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
bpathak-ons committed Mar 17, 2022
2 parents 7366949 + e1479c4 commit f957aef
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fmt:
.PHONY: audit
audit:
go list -m all | nancy sleuth

.PHONY: lint
lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.43.0
Expand Down
2 changes: 2 additions & 0 deletions event/producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
Summary: "",
ReleaseDate: "",
Title: "",
Topics: []string{""},
}

expectedVersionMetadataEvent = models.SearchDataImport{
Expand All @@ -52,6 +53,7 @@ var (
Summary: "",
ReleaseDate: someReleaseDate,
Title: someTitle,
Topics: []string{"testtopic1", "testtopic2"},
}
)

Expand Down
3 changes: 3 additions & 0 deletions handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func TestHandlerForZebedeeReturningMandatoryFields(t *testing.T) {
Summary: "",
ReleaseDate: "",
Title: "testTitle",
Topics: []string{"testtopic1", "testtopic2"},
}

kafkaProducerMock := &kafkatest.IProducerMock{
Expand Down Expand Up @@ -181,6 +182,7 @@ func TestHandlerForZebedeeReturningAllFields(t *testing.T) {
Summary: "testSummary",
ReleaseDate: "testReleaseDate",
Title: "testTitle",
Topics: []string{"testtopic"},
}

kafkaProducerMock := &kafkatest.IProducerMock{
Expand Down Expand Up @@ -264,6 +266,7 @@ func TestHandlerForDatasetVersionMetadata(t *testing.T) {
Summary: "",
ReleaseDate: "2020-11-07T00:00:00.000Z",
Title: "someTitle",
Topics: []string{"testtopic1", "testtopic2"},
}

kafkaProducerMock := &kafkatest.IProducerMock{
Expand Down
1 change: 1 addition & 0 deletions models/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ type SearchDataImport struct {
ReleaseDate string `avro:"release_date"`
Summary string `avro:"summary"`
Title string `avro:"title"`
Topics []string `avro:"topics"`
TraceID string `avro:"trace_id"`
}
8 changes: 8 additions & 0 deletions models/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func MapZebedeeDataToSearchDataImport(zebedeeData ZebedeeData, keywordsLimit int
Summary: zebedeeData.Description.Summary,
ReleaseDate: zebedeeData.Description.ReleaseDate,
Title: zebedeeData.Description.Title,
Topics: ValidateTopics(zebedeeData.Description.Topics),
}
return searchData
}
Expand Down Expand Up @@ -49,6 +50,13 @@ func RectifyKeywords(keywords []string, keywordsLimit int) []string {
return rectifiedKeywords[:keywordsLimit]
}

func ValidateTopics(topics []string) []string {
if topics == nil {
topics = []string{""}
}
return topics
}

// MapDatasetVersionToSearchDataImport performs default mapping of datasetAPI data to a version metadata struct.
func MapVersionMetadataToSearchDataImport(cmdData CMDData) SearchDataImport {
versionMetaData := SearchDataImport{
Expand Down
42 changes: 42 additions & 0 deletions models/mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const (
someReleaseDate = "2021-12-13"
someSummary = "Some Amazing Summary"
someTitle = "Some Incredible Title"

sometopic0 = "topic0"
sometopic1 = "topic1"
)

func TestMapZebedeeDataToSearchDataImport(t *testing.T) {
Expand All @@ -38,6 +41,7 @@ func TestMapZebedeeDataToSearchDataImport(t *testing.T) {
ReleaseDate: someReleaseDate,
Summary: someSummary,
Title: someTitle,
Topics: []string{sometopic0, sometopic1},
},
}
Convey("When mapped with a default keywords limit", func() {
Expand All @@ -58,6 +62,11 @@ func TestMapZebedeeDataToSearchDataImport(t *testing.T) {
So(result.Keywords[1], ShouldResemble, somekeyword1)
So(result.Keywords[2], ShouldResemble, somekeyword2)
So(result.Keywords[3], ShouldResemble, somekeyword3)

So(result.Topics, ShouldNotBeEmpty)
So(result.Topics, ShouldHaveLength, 2)
So(result.Topics[0], ShouldResemble, sometopic0)
So(result.Topics[1], ShouldResemble, sometopic1)
})
})
Convey("When mapped with a keywords limit of 2", func() {
Expand Down Expand Up @@ -170,6 +179,39 @@ func TestRectifyKeywords_EightKeywordsAndTenAsLimit(t *testing.T) {
})
}

func TestValidate_WithNiltopics(t *testing.T) {
Convey("Given a topics array is missing in zebedee response", t, func() {
Convey("When passed to validate the topics", func() {
actual := models.ValidateTopics(nil)
Convey("Then topics should be populated with an empty string array", func() {
So(actual, ShouldResemble, []string{""})
})
})
})
}

func TestValidate_WithEmptytopics(t *testing.T) {
Convey("Given a empty topics array as received from zebedee", t, func() {
Convey("When passed to validate the topics", func() {
actual := models.ValidateTopics([]string{""})
Convey("Then topics should be populated with an empty string array", func() {
So(actual, ShouldResemble, []string{""})
})
})
})
}

func TestValidate_WithEmptytopicsSize0(t *testing.T) {
Convey("Given a topics array of size 0 received from zebedee", t, func() {
Convey("When passed to validate the topics", func() {
actual := models.ValidateTopics([]string{})
Convey("Then topics should be populated with an string array of size 0", func() {
So(actual, ShouldResemble, []string{})
})
})
})
}

func TestMapDatasetVersionMetadataToSearchDataImport(t *testing.T) {
Convey("Given some valid DatasetAPI data with", t, func() {
CMDTestData := models.CMDData{
Expand Down
1 change: 1 addition & 0 deletions models/zebedee.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ type Description struct {
ReleaseDate string `json:"releaseDate"`
Summary string `json:"summary"`
Title string `json:"title"`
Topics []string `json:"topics,omitempty"`
}
1 change: 1 addition & 0 deletions schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var searchDataImport = `{
{"name": "release_date", "type": "string", "default": ""},
{"name": "summary", "type": "string", "default": ""},
{"name": "title", "type": "string", "default": ""},
{"name": "topics", "type": {"type":"array","items":"string"}},
{"name": "trace_id", "type": "string", "default": ""}
]
}`
Expand Down

0 comments on commit f957aef

Please sign in to comment.