@@ -9,14 +9,15 @@ import (
99 "os"
1010 "path/filepath"
1111 "testing"
12+ "time"
1213
13- "github.com/NBISweden/sda-bpctl/helpers"
1414 "github.com/NBISweden/sda-bpctl/internal/models"
1515)
1616
1717type mockClient struct {
18- FilesToReturn []models.FileInfo
19- Response * http.Response
18+ FilesToReturn []models.FileInfo
19+ FilesWithStatus []models.FileInfo
20+ Response * http.Response
2021}
2122
2223func (m * mockClient ) GetUsersFilesWithPrefix () ([]models.FileInfo , error ) {
@@ -51,14 +52,26 @@ func (m *mockClient) PostDatasetCreate(payload []byte) ([]byte, error) {
5152 return response , nil
5253}
5354
55+ func (m * mockClient ) GetFilesWithStatus (status string ) ([]models.FileInfo , error ) {
56+ return m .FilesWithStatus , nil
57+ }
58+
59+ func (m * mockClient ) WaitForStatus (target int , status string , interval time.Duration , timeout time.Duration ) ([]models.FileInfo , error ) {
60+ return nil , nil
61+ }
62+
5463func newMockClient (userID string , datasetFolder string ) * mockClient {
5564 mock := & mockClient {
5665 FilesToReturn : []models.FileInfo {
5766 // Data is mocked so we expect 2 files to be included in the accession (file1.c4gh and file2.c4gh)
58- {InboxPath : fmt .Sprintf ("/%s/%s/file1.c4gh" , userID , datasetFolder ), Status : "verified " },
59- {InboxPath : fmt .Sprintf ("/%s/%s/file2.c4gh" , userID , datasetFolder ), Status : "verified " },
67+ {InboxPath : fmt .Sprintf ("/%s/%s/file1.c4gh" , userID , datasetFolder ), Status : "ready " },
68+ {InboxPath : fmt .Sprintf ("/%s/%s/file2.c4gh" , userID , datasetFolder ), Status : "ready " },
6069 {InboxPath : fmt .Sprintf ("/%s/%s/file3.c4gh" , userID , datasetFolder ), Status : "error" },
61- {InboxPath : fmt .Sprintf ("/%s/%s/file4.c4gh" , userID , "DATASET_OTHER" ), Status : "verified" },
70+ {InboxPath : fmt .Sprintf ("/%s/%s/file4.c4gh" , userID , "DATASET_OTHER" ), Status : "ready" },
71+ },
72+ FilesWithStatus : []models.FileInfo {
73+ {InboxPath : fmt .Sprintf ("/%s/%s/file1.c4gh" , userID , datasetFolder ), Status : "ready" },
74+ {InboxPath : fmt .Sprintf ("/%s/%s/file2.c4gh" , userID , datasetFolder ), Status : "ready" },
6275 },
6376 Response : & http.Response {StatusCode : http .StatusOK , Body : io .NopCloser (bytes .NewBufferString ("ok" ))},
6477 }
@@ -80,19 +93,19 @@ func TestAccession(t *testing.T) {
8093 t .Run ("Test Accession" , func (t * testing.T ) {
8194
8295 accessionCmd .Flag ("data-directory" ).Value .Set (workingDirectory )
83- files , err := mock .GetUsersFiles ()
96+
97+ files , err := mock .GetFilesWithStatus ("ready" )
8498 if err != nil {
85- t .Error ( err )
99+ t .Fail ( )
86100 }
87101
88- paths := helpers .GetPathsForAccessionIDs (files , datasetFolder )
89- nrPaths := len (paths )
90- if nrPaths != expectedPaths {
91- t .Logf ("recieved %d/%d paths for accessionIDs" , nrPaths , expectedPaths )
102+ nrFiles := len (files )
103+ if nrFiles != expectedPaths {
104+ t .Logf ("recieved %d/%d paths for accessionIDs" , nrFiles , expectedPaths )
92105 t .Fail ()
93106 }
94107
95- accessionIDs , err := postAccessionIDs (mock , paths , userID )
108+ accessionIDs , err := postAccessionIDs (mock , files , userID )
96109 nrAccessionIDs := len (accessionIDs )
97110 if nrAccessionIDs != expectedPaths {
98111 t .Logf ("recieved %d/%d accessionIDs" , nrAccessionIDs , expectedPaths )
0 commit comments