Skip to content

Commit

Permalink
Add a basic integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall committed Jun 27, 2024
1 parent 7df0665 commit 6a84da8
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 10 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: check valid sh
run: shellcheck tests/*.sh

- uses: actions/setup-go@v4

- name: golangci-lint
Expand All @@ -22,5 +25,8 @@ jobs:
- name: Build
run: go build -v ./...

- name: Test with the Go CLI
- name: Unit tests
run: go test -v ./...

- name: Integration tests
run: ./tests/starter-site.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
go-islandora
islandora-starter-site
68 changes: 68 additions & 0 deletions fixtures/islandora_object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package islandora

import (
islandoraModel "github.com/lehigh-university-libraries/go-islandora/model"
)

type IslandoraObject struct {
Nid []islandoraModel.IntField `json:"nid"`
Vid []islandoraModel.IntField `json:"vid"`
Uuid []islandoraModel.IntField `json:"uuid"`
Language []islandoraModel.GenericField `json:"lang"`
RevisionTimestamp []islandoraModel.GenericField `json:"revision_timestamp"`
RevisionUid []islandoraModel.EntityReferenceField `json:"revision_uid"`
RevisionLog []islandoraModel.GenericField `json:"revision_log"`
Uid []islandoraModel.EntityReferenceField `json:"uid"`
Title []islandoraModel.GenericField `json:"title"`
Type []islandoraModel.GenericField `json:"type"`
Status []islandoraModel.BoolField `json:"status"`
Created []islandoraModel.GenericField `json:"created"`
Changed []islandoraModel.GenericField `json:"changed"`

FieldAbstract []islandoraModel.GenericField `json:"field_abstract,omitempty"`
FieldAltTitle []islandoraModel.GenericField `json:"field_alt_title,omitempty"`
FieldClassification []islandoraModel.GenericField `json:"field_classification,omitempty"`
FieldCoordinates []islandoraModel.GeoLocationField `json:"field_coordinates,omitempty"`
FieldCoordinatesText []islandoraModel.GenericField `json:"field_coordinates_text,omitempty"`
FieldCopyrightDate []islandoraModel.EdtfField `json:"field_copyright_date,omitempty"`
FieldDateCaptured []islandoraModel.EdtfField `json:"field_date_captured,omitempty"`
FieldDateModified []islandoraModel.EdtfField `json:"field_date_modified,omitempty"`
FieldDateValid []islandoraModel.EdtfField `json:"field_date_valid,omitempty"`
FieldDescription []islandoraModel.GenericField `json:"field_description,omitempty"`
FieldDeweyClassification []islandoraModel.GenericField `json:"field_dewey_classification,omitempty"`
FieldEdition []islandoraModel.GenericField `json:"field_edition,omitempty"`
FieldEdtfDate []islandoraModel.EdtfField `json:"field_edtf_date,omitempty"`
FieldEdtfDateCreated []islandoraModel.EdtfField `json:"field_edtf_date_created,omitempty"`
FieldEdtfDateIssued []islandoraModel.EdtfField `json:"field_edtf_date_issued,omitempty"`
FieldExtent []islandoraModel.GenericField `json:"field_extent,omitempty"`
FieldFrequency []islandoraModel.EntityReferenceField `json:"field_frequency,omitempty"`
FieldFullTitle []islandoraModel.GenericField `json:"field_full_title,omitempty"`
FieldGenre []islandoraModel.EntityReferenceField `json:"field_genre,omitempty"`
FieldGeographicSubject []islandoraModel.EntityReferenceField `json:"field_geographic_subject,omitempty"`
FieldIdentifier []islandoraModel.GenericField `json:"field_identifier,omitempty"`
FieldIsbn []islandoraModel.GenericField `json:"field_isbn,omitempty"`
FieldLanguage []islandoraModel.EntityReferenceField `json:"field_language,omitempty"`
FieldLccClassification []islandoraModel.GenericField `json:"field_lcc_classification,omitempty"`
FieldLinkedAgent []islandoraModel.TypedRelationField `json:"field_linked_agent,omitempty"`
FieldLocalIdentifier []islandoraModel.GenericField `json:"field_local_identifier,omitempty"`
FieldMemberOf []islandoraModel.EntityReferenceField `json:"field_member_of,omitempty"`
FieldModeOfIssuance []islandoraModel.EntityReferenceField `json:"field_mode_of_issuance,omitempty"`
FieldModel []islandoraModel.EntityReferenceField `json:"field_model,omitempty"`
FieldNote []islandoraModel.GenericField `json:"field_note,omitempty"`
FieldOclcNumber []islandoraModel.GenericField `json:"field_oclc_number,omitempty"`
FieldPhysicalForm []islandoraModel.EntityReferenceField `json:"field_physical_form,omitempty"`
FieldPid []islandoraModel.GenericField `json:"field_pid,omitempty"`
FieldPlacePublished []islandoraModel.GenericField `json:"field_place_published,omitempty"`
FieldPlacePublishedCountry []islandoraModel.EntityReferenceField `json:"field_place_published_country,omitempty"`
FieldPublisher []islandoraModel.GenericField `json:"field_publisher,omitempty"`
FieldRepresentativeImage []islandoraModel.EntityReferenceField `json:"field_representative_image,omitempty"`
FieldResourceType []islandoraModel.EntityReferenceField `json:"field_resource_type,omitempty"`
FieldRights []islandoraModel.GenericField `json:"field_rights,omitempty"`
FieldSubject []islandoraModel.EntityReferenceField `json:"field_subject,omitempty"`
FieldSubjectGeneral []islandoraModel.EntityReferenceField `json:"field_subject_general,omitempty"`
FieldSubjectsName []islandoraModel.EntityReferenceField `json:"field_subjects_name,omitempty"`
FieldTableOfContents []islandoraModel.GenericField `json:"field_table_of_contents,omitempty"`
FieldTemporalSubject []islandoraModel.EntityReferenceField `json:"field_temporal_subject,omitempty"`
FieldViewerOverride []islandoraModel.EntityReferenceField `json:"field_viewer_override,omitempty"`
FieldWeight []islandoraModel.IntField `json:"field_weight,omitempty"`
}
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func main() {
os.Exit(1)
}

slog.Info("Structs generated and written to %s", *output)
slog.Info("Structs generated and written", "file", *output)
}

func generateGoStruct(data StructData) (string, error) {
Expand All @@ -115,7 +115,6 @@ func generateGoStruct(data StructData) (string, error) {
}

func mapFieldTypeToGoType(fieldType string) string {
slog.Info(fieldType)
switch fieldType {
case "boolean":
return "[]islandoraModel.BoolField"
Expand Down
14 changes: 7 additions & 7 deletions node.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ type {{.StructName}} struct {
Nid []islandoraModel.IntField `json:"nid"`
Vid []islandoraModel.IntField `json:"vid"`
Uuid []islandoraModel.IntField `json:"uuid"`
Language []islandoraModel.Field `json:"lang"`
RevisionTimestamp []islandoraModel.Field `json:"revision_timestamp"`
Language []islandoraModel.GenericField `json:"lang"`
RevisionTimestamp []islandoraModel.GenericField `json:"revision_timestamp"`
RevisionUid []islandoraModel.EntityReferenceField `json:"revision_uid"`
RevisionLog []islandoraModel.Field `json:"revision_log"`
RevisionLog []islandoraModel.GenericField `json:"revision_log"`
Uid []islandoraModel.EntityReferenceField `json:"uid"`
Title []islandoraModel.Field `json:"title"`
Type []islandoraModel.Field `json:"type"`
Title []islandoraModel.GenericField `json:"title"`
Type []islandoraModel.GenericField `json:"type"`
Status []islandoraModel.BoolField `json:"status"`
Created []islandoraModel.Field `json:"created"`
Changed []islandoraModel.Field `json:"changed"`
Created []islandoraModel.GenericField `json:"created"`
Changed []islandoraModel.GenericField `json:"changed"`

{{range .Fields}} {{.Name}} {{.Type}} `json:"{{.Tag}},omitempty"`
{{end}}}
17 changes: 17 additions & 0 deletions tests/starter-site.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -eou pipefail

if [ ! -d ./islandora-starter-site ]; then
git clone [email protected]:Islandora-Devops/islandora-starter-site
fi

go run main.go \
--node-cex-yaml=./islandora-starter-site/config/sync/node.type.islandora_object.yml \
--output=islandora_object.go

go fmt islandora_object.go > /dev/null

diff islandora_object.go fixtures/islandora_object.go || (echo "Failure Maybe starter site updated its data model?" && exit 1)

echo "Generated struct matches expected output 🚀"

0 comments on commit 6a84da8

Please sign in to comment.