-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a test for the NMDC database and fixed up study ID retrieval.
- Loading branch information
1 parent
ceb42cc
commit eaf6968
Showing
3 changed files
with
173 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package nmdc | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/kbase/dts/config" | ||
"github.com/kbase/dts/databases" | ||
"github.com/kbase/dts/dtstest" | ||
"github.com/kbase/dts/endpoints" | ||
"github.com/kbase/dts/endpoints/globus" | ||
) | ||
|
||
const nmdcConfig string = ` | ||
databases: | ||
nmdc: | ||
name: National Microbiome Data Collaborative | ||
organization: DOE | ||
endpoints: | ||
nersc: globus-nmdc-nersc | ||
emsl: globus-nmdc-emsl | ||
endpoints: | ||
globus-nmdc-nersc: | ||
name: NMDC (NERSC) | ||
id: ${DTS_GLOBUS_TEST_ENDPOINT} | ||
provider: globus | ||
root: / | ||
auth: | ||
client_id: ${DTS_GLOBUS_CLIENT_ID} | ||
client_secret: ${DTS_GLOBUS_CLIENT_SECRET} | ||
globus-nmdc-emsl: | ||
name: NMDC Bulk Data Cache | ||
id: ${DTS_GLOBUS_TEST_ENDPOINT} | ||
provider: globus | ||
root: / | ||
auth: | ||
client_id: ${DTS_GLOBUS_CLIENT_ID} | ||
client_secret: ${DTS_GLOBUS_CLIENT_SECRET} | ||
globus-jdp: | ||
name: Globus NERSC DTN | ||
id: ${DTS_GLOBUS_TEST_ENDPOINT} | ||
provider: globus | ||
auth: | ||
client_id: ${DTS_GLOBUS_CLIENT_ID} | ||
client_secret: ${DTS_GLOBUS_CLIENT_SECRET} | ||
` | ||
|
||
// since NMDC doesn't support search queries at this time, we search for | ||
// data objects related to a study | ||
var nmdcSearchParams map[string]json.RawMessage | ||
|
||
// this function gets called at the begіnning of a test session | ||
func setup() { | ||
dtstest.EnableDebugLogging() | ||
config.Init([]byte(nmdcConfig)) | ||
databases.RegisterDatabase("nmdc", NewDatabase) | ||
endpoints.RegisterEndpointProvider("globus", globus.NewEndpoint) | ||
|
||
// construct NMDC-specific search parameters for a study | ||
nmdcSearchParams = make(map[string]json.RawMessage) | ||
studyId, _ := json.Marshal("nmdc:sty-11-5tgfr349") | ||
nmdcSearchParams["study_id"] = studyId | ||
} | ||
|
||
// this function gets called after all tests have been run | ||
func breakdown() { | ||
} | ||
|
||
func TestNewDatabase(t *testing.T) { | ||
assert := assert.New(t) | ||
orcid := os.Getenv("DTS_KBASE_TEST_ORCID") | ||
db, err := NewDatabase(orcid) | ||
assert.NotNil(db, "NMDC database not created") | ||
assert.Nil(err, "NMDC database creation encountered an error") | ||
} | ||
|
||
func TestNewDatabaseWithoutOrcid(t *testing.T) { | ||
assert := assert.New(t) | ||
db, err := NewDatabase("") | ||
assert.Nil(db, "Invalid NMDC database somehow created") | ||
assert.NotNil(err, "NMDC database creation without ORCID encountered no error") | ||
} | ||
|
||
func TestSearch(t *testing.T) { | ||
assert := assert.New(t) | ||
orcid := os.Getenv("DTS_KBASE_TEST_ORCID") | ||
db, _ := NewDatabase(orcid) | ||
|
||
params := databases.SearchParameters{ | ||
Query: "", | ||
Specific: nmdcSearchParams, | ||
} | ||
results, err := db.Search(params) | ||
assert.True(len(results.Resources) > 0, "NMDC search query returned no results") | ||
assert.Nil(err, "NMDC search query encountered an error") | ||
} | ||
|
||
func TestResources(t *testing.T) { | ||
assert := assert.New(t) | ||
orcid := os.Getenv("DTS_KBASE_TEST_ORCID") | ||
db, _ := NewDatabase(orcid) | ||
params := databases.SearchParameters{ | ||
Query: "", | ||
Specific: nmdcSearchParams, | ||
} | ||
results, _ := db.Search(params) | ||
fileIds := make([]string, len(results.Resources)) | ||
for i, res := range results.Resources { | ||
fileIds[i] = res.Id | ||
} | ||
resources, err := db.Resources(fileIds[:10]) | ||
assert.Nil(err, "NMDC resource query encountered an error") | ||
assert.Equal(10, len(resources), | ||
"NMDC resource query didn't return requested number of results") | ||
for i, resource := range resources { | ||
jdpSearchResult := results.Resources[i] | ||
assert.Equal(jdpSearchResult.Id, resource.Id, "Resource ID mismatch") | ||
assert.Equal(jdpSearchResult.Name, resource.Name, "Resource name mismatch") | ||
assert.Equal(jdpSearchResult.Path, resource.Path, "Resource path mismatch") | ||
assert.Equal(jdpSearchResult.Format, resource.Format, "Resource format mismatch") | ||
assert.Equal(jdpSearchResult.Bytes, resource.Bytes, "Resource size mismatch") | ||
assert.Equal(jdpSearchResult.MediaType, resource.MediaType, "Resource media type mismatch") | ||
assert.Equal(jdpSearchResult.Credit.Identifier, resource.Credit.Identifier, "Resource credit ID mismatch") | ||
assert.Equal(jdpSearchResult.Credit.ResourceType, resource.Credit.ResourceType, "Resource credit resource type mismatch") | ||
} | ||
} | ||
|
||
// this runs setup, runs all tests, and does breakdown | ||
func TestMain(m *testing.M) { | ||
setup() | ||
status := m.Run() | ||
breakdown() | ||
os.Exit(status) | ||
} |