Skip to content

Commit

Permalink
[schemas] set min length on required values
Browse files Browse the repository at this point in the history
  • Loading branch information
jbygdell committed Oct 12, 2024
1 parent 81ec27e commit 5e8231d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
17 changes: 13 additions & 4 deletions sda/internal/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,19 @@ func TestValidateJSONDatasetRelease(t *testing.T) {

msg, _ := json.Marshal(okMsg)
assert.Nil(t, ValidateJSON(fmt.Sprintf("%s/federated/dataset-release.json", schemaPath), msg))
assert.Nil(t, ValidateJSON(fmt.Sprintf("%s/isolated/dataset-release.json", schemaPath), msg))

badMsg := DatasetMapping{
Type: "release",
DatasetID: "ABCD00123456789",
DatasetID: "",
AccessionIDs: []string{
"c177c69c-dcc6-4174-8740-919b8f994122",
},
}

msg, _ = json.Marshal(badMsg)
assert.Error(t, ValidateJSON(fmt.Sprintf("%s/federated/dataset-release.json", schemaPath), msg))
assert.Error(t, ValidateJSON(fmt.Sprintf("%s/isolated/dataset-release.json", schemaPath), msg))
}

func TestValidateJSONInboxRemove(t *testing.T) {
Expand Down Expand Up @@ -215,18 +217,21 @@ func TestValidateJSONIngestionAccession(t *testing.T) {

msg, _ := json.Marshal(okMsg)
assert.Nil(t, ValidateJSON(fmt.Sprintf("%s/federated/ingestion-accession.json", schemaPath), msg))
assert.Nil(t, ValidateJSON(fmt.Sprintf("%s/isolated/ingestion-accession.json", schemaPath), msg))

badMsg := IngestionAccession{
User: "JohnDoe",
FilePath: "path/to file",
AccessionID: "ABCD00123456789",
AccessionID: "",
DecryptedChecksums: []Checksums{
{Type: "sha256", Value: "da886a89637d125ef9f15f6d676357f3a9e5e10306929f0bad246375af89c2e2"},
{Type: "md5", Value: "68b329da9893e34099c7d8ad5cb9c940"},
},
}

msg, _ = json.Marshal(badMsg)
assert.Error(t, ValidateJSON(fmt.Sprintf("%s/federated/ingestion-accession.json", schemaPath), msg))
assert.Error(t, ValidateJSON(fmt.Sprintf("%s/isolated/ingestion-accession.json", schemaPath), msg))
}

func TestValidateJSONIngestionCompletion(t *testing.T) {
Expand All @@ -242,18 +247,20 @@ func TestValidateJSONIngestionCompletion(t *testing.T) {

msg, _ := json.Marshal(okMsg)
assert.Nil(t, ValidateJSON(fmt.Sprintf("%s/federated/ingestion-completion.json", schemaPath), msg))
assert.Nil(t, ValidateJSON(fmt.Sprintf("%s/isolated/ingestion-completion.json", schemaPath), msg))

badMsg := IngestionCompletion{
User: "JohnDoe",
FilePath: "path/to file",
AccessionID: "EGAF00123456789",
AccessionID: "",
DecryptedChecksums: []Checksums{
{Type: "md5", Value: "68b329da9893e34099c7d8ad5cb9c940"},
},
}

msg, _ = json.Marshal(badMsg)
assert.Error(t, ValidateJSON(fmt.Sprintf("%s/federated/ingestion-completion.json", schemaPath), msg))
assert.Error(t, ValidateJSON(fmt.Sprintf("%s/isolated/ingestion-completion.json", schemaPath), msg))
}

func TestValidateJSONIngestionTrigger(t *testing.T) {
Expand All @@ -274,6 +281,7 @@ func TestValidateJSONIngestionTrigger(t *testing.T) {

msg, _ = json.Marshal(badMsg)
assert.Error(t, ValidateJSON(fmt.Sprintf("%s/federated/ingestion-trigger.json", schemaPath), msg))
assert.Error(t, ValidateJSON(fmt.Sprintf("%s/isolated/ingestion-trigger.json", schemaPath), msg))
}

func TestValidateJSONIngestionUserError(t *testing.T) {
Expand Down Expand Up @@ -374,9 +382,10 @@ func TestValidateJSONIsloatedIngestionAccession(t *testing.T) {
badMsg := IngestionAccession{
User: "JohnDoe",
FilePath: "path/to file",
AccessionID: "ABCD00123456789",
AccessionID: "",
DecryptedChecksums: []Checksums{
{Type: "sha256", Value: "da886a89637d125ef9f15f6d676357f3a9e5e10306929f0bad246375af89c2e2"},
{Type: "md5", Value: "68b329da9893e34099c7d8ad5cb9c940"},
},
}

Expand Down
1 change: 1 addition & 0 deletions sda/schemas/isolated/dataset-deprecate.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"type": "string",
"title": "The Accession identifier for the dataset",
"description": "The Accession identifier for the dataset",
"minLength": 2,
"examples": [
"anyidentifier"
]
Expand Down
1 change: 1 addition & 0 deletions sda/schemas/isolated/dataset-mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"type": "string",
"title": "The Accession identifier for the dataset",
"description": "The Accession identifier for the dataset",
"minLength": 2,
"pattern": "^\\S+$",
"examples": [
"anyidentifier"
Expand Down
1 change: 1 addition & 0 deletions sda/schemas/isolated/ingestion-accession.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"type": "string",
"title": "The Accession identifier",
"description": "The Accession identifier",
"minLength": 2,
"pattern": "^\\S+$",
"examples": [
"anyidentifier"
Expand Down

0 comments on commit 5e8231d

Please sign in to comment.