Skip to content

Commit

Permalink
implement tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ElizabethMRichardson committed Mar 13, 2024
1 parent c779555 commit 5abf4dd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion output/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func MarshalEntries(ctx context.Context, output *Output, entries []source.Entry,
if alias == "" {
aliasArray, arrayErr := expr.EvaluateArray[string](ctx, aliasSource, entry, logger)
if arrayErr != nil {
return nil, errors.Wrap(err, fmt.Sprintf("aliases.%d: evaluating entry alias array", idx))
return nil, errors.Wrap(err, fmt.Sprintf("aliases.%d: evaluating entry alias", idx))
}
toAdd = append(toAdd, aliasArray...)
} else {
Expand Down
60 changes: 30 additions & 30 deletions output/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,11 @@ var _ = Describe("Marshalling data", func() {
var (
ctx context.Context
catalogTypeOutput *Output
entries []source.Entry
logger kitlog.Logger
)

ctx = context.Background()

sourceEntry1 := source.Entry{
"id": "P123",
"name": "Component name",
"important": true,
"importance_score": 100,
"description": "A super important component. A structurally integral component tbh.",
"metadata": map[string]any{
"namespace": "Infrastructure",
"aliases": []string{"oneAlias", "anotherAlias"},
},
}
sourceEntry2 := source.Entry{
"id": "P123",
"name": "Component name",
"important": true,
"importance_score": 100,
"description": "A super important component. A structurally integral component tbh.",
"metadata": map[string]any{
"namespace": "Infrastructure",
},
"aliases": []string{"andAnotherAlias"},
}

sourceConfig := SourceConfig{
Name: "$.name",
ExternalID: "$.external_id",
Expand All @@ -55,17 +31,41 @@ var _ = Describe("Marshalling data", func() {
Source: sourceConfig,
}

entries = append(entries, sourceEntry1, sourceEntry2)

logger = kitlog.NewLogfmtLogger(kitlog.NewSyncWriter(os.Stderr))

When("doing the thing with the aliases", func() {
It("does the right shit", func() {
When("Marshalling alias data where the entry has an array of aliases", func() {
It("correctly populates the array on the resulting entry with all values", func() {
sourceEntry := source.Entry{
"id": "P1234",
"name": "Component name 1",
"description": "A super important component. A structurally integral component tbh.",
"aliases": []string{"aliasInAnArray", "anotherAliasInAnArray"},
}

entries := []source.Entry{sourceEntry}

res, err := MarshalEntries(ctx, catalogTypeOutput, entries, logger)
expectedResult := []string{"oneAlias", "anotherAlias"}

expectedAliasResult := []string{"aliasInAnArray", "anotherAliasInAnArray"}
Expect(err).NotTo(HaveOccurred())
Expect(res[0].Aliases).To(Equal(expectedResult))
Expect(res[0].Aliases).To(Equal(expectedAliasResult))

})
})

When("Marshalling alias data where the entry has a single string alias", func() {
It("correctly populates the alias array on the resulting entry with the single value", func() {
sourceEntry := source.Entry{
"id": "P1235",
"name": "Component name 2",
"description": "A super important component. A structurally integral component tbh.",
"aliases": "singleAlias",
}
entries := []source.Entry{sourceEntry}
res, err := MarshalEntries(ctx, catalogTypeOutput, entries, logger)
expectedAliasResult := []string{"singleAlias"}
Expect(err).NotTo(HaveOccurred())
Expect(res[0].Aliases).To(Equal(expectedAliasResult))
})
})
})

0 comments on commit 5abf4dd

Please sign in to comment.