From 6a84da8ae7f849b0eef52e985e38e6ee7aa0b790 Mon Sep 17 00:00:00 2001 From: Joe Corall Date: Thu, 27 Jun 2024 11:48:21 -0400 Subject: [PATCH] Add a basic integration test --- .github/workflows/lint-test.yml | 8 +++- .gitignore | 1 + fixtures/islandora_object.go | 68 +++++++++++++++++++++++++++++++++ main.go | 3 +- node.go.tmpl | 14 +++---- tests/starter-site.sh | 17 +++++++++ 6 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 fixtures/islandora_object.go create mode 100755 tests/starter-site.sh diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml index e9a2f59..f0677c7 100644 --- a/.github/workflows/lint-test.yml +++ b/.github/workflows/lint-test.yml @@ -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 @@ -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 diff --git a/.gitignore b/.gitignore index 63d8881..e804739 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ go-islandora +islandora-starter-site diff --git a/fixtures/islandora_object.go b/fixtures/islandora_object.go new file mode 100644 index 0000000..b0bbb94 --- /dev/null +++ b/fixtures/islandora_object.go @@ -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"` +} diff --git a/main.go b/main.go index 87d28d1..3b6fe07 100644 --- a/main.go +++ b/main.go @@ -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) { @@ -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" diff --git a/node.go.tmpl b/node.go.tmpl index cee062b..249092f 100644 --- a/node.go.tmpl +++ b/node.go.tmpl @@ -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}}} diff --git a/tests/starter-site.sh b/tests/starter-site.sh new file mode 100755 index 0000000..71f7afd --- /dev/null +++ b/tests/starter-site.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -eou pipefail + +if [ ! -d ./islandora-starter-site ]; then + git clone git@github.com: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 🚀"