diff --git a/api/dimensions.go b/api/dimensions.go index beab1da0..ccdb7393 100644 --- a/api/dimensions.go +++ b/api/dimensions.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" "sort" + "strconv" "github.com/ONSdigital/dp-dataset-api/apierrors" errs "github.com/ONSdigital/dp-dataset-api/apierrors" @@ -32,6 +33,16 @@ func (api *DatasetAPI) getDimensions(w http.ResponseWriter, r *http.Request, lim logData := log.Data{"dataset_id": datasetID, "edition": edition, "version": version, "func": "getDimensions"} var err error + versionId, err := strconv.Atoi(version) + if err != nil { + log.Event(ctx, "invalid version request", log.ERROR, log.Error(err), logData) + return nil, 0, errs.ErrInvalidVersion + } + if !(versionId > 0) { + log.Event(ctx, "version is not a positive integer", log.ERROR, log.Error(err), logData) + return nil, 0, errs.ErrInvalidVersion + } + list, totalCount, err := func() ([]models.Dimension, int, error) { authorised := api.authenticate(r, logData) @@ -40,7 +51,7 @@ func (api *DatasetAPI) getDimensions(w http.ResponseWriter, r *http.Request, lim state = models.PublishedState } - versionDoc, err := api.dataStore.Backend.GetVersion(datasetID, edition, version, state) + versionDoc, err := api.dataStore.Backend.GetVersion(datasetID, edition, versionId, state) if err != nil { log.Event(ctx, "datastore.getversion returned an error", log.ERROR, log.Error(err), logData) return nil, 0, err @@ -141,6 +152,18 @@ func (api *DatasetAPI) getDimensionOptions(w http.ResponseWriter, r *http.Reques logData := log.Data{"dataset_id": datasetID, "edition": edition, "version": versionID, "dimension": dimension, "func": "getDimensionOptions"} authorised := api.authenticate(r, logData) + versionId, err := strconv.Atoi(versionID) + if err != nil { + log.Event(ctx, "invalid version requested", log.ERROR, log.Error(err), logData) + handleDimensionsErr(ctx, w, "invalid version", errs.ErrInvalidVersion, logData) + return nil, 0, err + } + if !(versionId > 0) { + log.Event(ctx, "version is not a positive integer", log.ERROR, log.Error(err), logData) + handleDimensionsErr(ctx, w, "failed due to version not a positive integer", errs.ErrInvalidVersion, logData) + return nil, 0, err + } + var state string if !authorised { state = models.PublishedState @@ -156,7 +179,7 @@ func (api *DatasetAPI) getDimensionOptions(w http.ResponseWriter, r *http.Reques } // ger version for provided dataset, edition and versionID - version, err := api.dataStore.Backend.GetVersion(datasetID, edition, versionID, state) + version, err := api.dataStore.Backend.GetVersion(datasetID, edition, versionId, state) if err != nil { handleDimensionsErr(ctx, w, "failed to get version", err, logData) return nil, 0, err diff --git a/api/dimensions_test.go b/api/dimensions_test.go index 6bd426ee..ad890e43 100644 --- a/api/dimensions_test.go +++ b/api/dimensions_test.go @@ -28,7 +28,7 @@ func TestGetDimensionsReturnsOk(t *testing.T) { r := httptest.NewRequest("GET", "http://localhost:22000/datasets/123/editions/2017/versions/1/dimensions", nil) w := httptest.NewRecorder() mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(datasetID, edition, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, edition string, version int, state string) (*models.Version, error) { return &models.Version{State: models.AssociatedState}, nil }, GetDimensionsFunc: func(datasetID, versionID string) ([]bson.M, error) { @@ -56,13 +56,13 @@ func TestGetDimensionsReturnsErrors(t *testing.T) { r := httptest.NewRequest("GET", "http://localhost:22000/datasets/123/editions/2017/versions/1/dimensions", nil) w := httptest.NewRecorder() mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(datasetID, edition, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, edition string, version int, state string) (*models.Version, error) { return nil, errs.ErrInternalServer }, } api := initAPIWithMockedStore(mockedDataStore) - api.getDimensions(w, r, 20, 0) + api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusInternalServerError) So(w.Body.String(), ShouldContainSubstring, errs.ErrInternalServer.Error()) @@ -74,13 +74,13 @@ func TestGetDimensionsReturnsErrors(t *testing.T) { r := httptest.NewRequest("GET", "http://localhost:22000/datasets/123/editions/2017/versions/1/dimensions", nil) w := httptest.NewRecorder() mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(datasetID, edition, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, edition string, version int, state string) (*models.Version, error) { return nil, errs.ErrVersionNotFound }, } api := initAPIWithMockedStore(mockedDataStore) - api.getDimensions(w, r, 20, 0) + api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) So(w.Body.String(), ShouldContainSubstring, errs.ErrVersionNotFound.Error()) @@ -92,7 +92,7 @@ func TestGetDimensionsReturnsErrors(t *testing.T) { r := httptest.NewRequest("GET", "http://localhost:22000/datasets/123/editions/2017/versions/1/dimensions", nil) w := httptest.NewRecorder() mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(datasetID, edition, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, edition string, version int, state string) (*models.Version, error) { return &models.Version{State: models.AssociatedState}, nil }, GetDimensionsFunc: func(datasetID, versionID string) ([]bson.M, error) { @@ -101,7 +101,7 @@ func TestGetDimensionsReturnsErrors(t *testing.T) { } api := initAPIWithMockedStore(mockedDataStore) - api.getDimensions(w, r, 20, 0) + api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) So(w.Body.String(), ShouldContainSubstring, errs.ErrDimensionsNotFound.Error()) @@ -113,13 +113,13 @@ func TestGetDimensionsReturnsErrors(t *testing.T) { r := httptest.NewRequest("GET", "http://localhost:22000/datasets/123/editions/2017/versions/1/dimensions", nil) w := httptest.NewRecorder() mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(datasetID, edition, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, edition string, version int, state string) (*models.Version, error) { return &models.Version{State: "gobbly-gook"}, nil }, } api := initAPIWithMockedStore(mockedDataStore) - api.getDimensions(w, r, 20, 0) + api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusInternalServerError) So(w.Body.String(), ShouldContainSubstring, errs.ErrInternalServer.Error()) @@ -135,7 +135,7 @@ func TestGetDimensionOptionsReturnsOk(t *testing.T) { // testing DataStore with 5 dimension options mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(datasetID, edition, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, edition string, version int, state string) (*models.Version, error) { return &models.Version{State: models.AssociatedState, ID: "v1"}, nil }, GetDimensionOptionsFunc: func(version *models.Version, dimensions string, offset, limit int) ([]*models.PublicDimensionOption, int, error) { @@ -283,7 +283,7 @@ func TestGetDimensionOptionsReturnsErrors(t *testing.T) { w := httptest.NewRecorder() api := initAPIWithMockedStore(&storetest.StorerMock{}) - api.getDimensionOptions(w, r, 20, 0) + api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) So(w.Body.String(), ShouldContainSubstring, errs.ErrTooManyQueryParameters.Error()) @@ -294,13 +294,13 @@ func TestGetDimensionOptionsReturnsErrors(t *testing.T) { r := httptest.NewRequest("GET", "http://localhost:22000/datasets/123/editions/2017/versions/1/dimensions/age/options", nil) w := httptest.NewRecorder() mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(datasetID, edition, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, edition string, version int, state string) (*models.Version, error) { return nil, errs.ErrVersionNotFound }, } api := initAPIWithMockedStore(mockedDataStore) - api.getDimensionOptions(w, r, 20, 0) + api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) So(w.Body.String(), ShouldContainSubstring, errs.ErrVersionNotFound.Error()) @@ -311,7 +311,7 @@ func TestGetDimensionOptionsReturnsErrors(t *testing.T) { r := httptest.NewRequest("GET", "http://localhost:22000/datasets/123/editions/2017/versions/1/dimensions/age/options", nil) w := httptest.NewRecorder() mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(datasetID, edition, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, edition string, version int, state string) (*models.Version, error) { return &models.Version{State: models.AssociatedState}, nil }, GetDimensionOptionsFunc: func(version *models.Version, dimensions string, offset, limit int) ([]*models.PublicDimensionOption, int, error) { @@ -320,7 +320,7 @@ func TestGetDimensionOptionsReturnsErrors(t *testing.T) { } api := initAPIWithMockedStore(mockedDataStore) - api.getDimensionOptions(w, r, 20, 0) + api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusInternalServerError) So(w.Body.String(), ShouldContainSubstring, errs.ErrInternalServer.Error()) @@ -332,7 +332,7 @@ func TestGetDimensionOptionsReturnsErrors(t *testing.T) { r := httptest.NewRequest("GET", "http://localhost:22000/datasets/123/editions/2017/versions/1/dimensions/age/options?id=id1", nil) w := httptest.NewRecorder() mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(datasetID, edition, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, edition string, version int, state string) (*models.Version, error) { return &models.Version{State: models.AssociatedState}, nil }, GetDimensionOptionsFromIDsFunc: func(version *models.Version, dimension string, ids []string) ([]*models.PublicDimensionOption, int, error) { @@ -341,7 +341,7 @@ func TestGetDimensionOptionsReturnsErrors(t *testing.T) { } api := initAPIWithMockedStore(mockedDataStore) - api.getDimensionOptions(w, r, 20, 0) + api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusInternalServerError) So(w.Body.String(), ShouldContainSubstring, errs.ErrInternalServer.Error()) @@ -353,14 +353,13 @@ func TestGetDimensionOptionsReturnsErrors(t *testing.T) { r := httptest.NewRequest("GET", "http://localhost:22000/datasets/123/editions/2017/versions/1/dimensions/age/options", nil) w := httptest.NewRecorder() mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(datasetID, edition, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, edition string, version int, state string) (*models.Version, error) { return &models.Version{State: "gobbly-gook"}, nil }, } api := initAPIWithMockedStore(mockedDataStore) - api.getDimensionOptions(w, r, 20, 0) - + api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusInternalServerError) So(w.Body.String(), ShouldContainSubstring, errs.ErrInternalServer.Error()) So(len(mockedDataStore.GetVersionCalls()), ShouldEqual, 1) diff --git a/api/metadata.go b/api/metadata.go index b075693f..04503cc1 100644 --- a/api/metadata.go +++ b/api/metadata.go @@ -3,6 +3,7 @@ package api import ( "encoding/json" "net/http" + "strconv" errs "github.com/ONSdigital/dp-dataset-api/apierrors" "github.com/ONSdigital/dp-dataset-api/models" @@ -20,8 +21,18 @@ func (api *DatasetAPI) getMetadata(w http.ResponseWriter, r *http.Request) { logData := log.Data{"dataset_id": datasetID, "edition": edition, "version": version} b, err := func() ([]byte, error) { + versionId, err := strconv.Atoi(version) + if err != nil { + log.Event(ctx, "failed due to invalid version request", log.ERROR, log.Error(err), logData) + return nil, errs.ErrInvalidVersion + } + if !(versionId > 0) { + log.Event(ctx, "version is not a positive integer", log.ERROR, log.Error(err), logData) + return nil, errs.ErrInvalidVersion + + } - versionDoc, err := api.dataStore.Backend.GetVersion(datasetID, edition, version, "") + versionDoc, err := api.dataStore.Backend.GetVersion(datasetID, edition, versionId, "") if err != nil { if err == errs.ErrVersionNotFound { log.Event(ctx, "getMetadata endpoint: failed to find version for dataset edition", log.ERROR, log.Error(err), logData) diff --git a/api/metadata_test.go b/api/metadata_test.go index 79107cd9..d51588f8 100644 --- a/api/metadata_test.go +++ b/api/metadata_test.go @@ -32,7 +32,7 @@ func TestGetMetadataReturnsOk(t *testing.T) { CheckEditionExistsFunc: func(datasetID, edition, state string) error { return nil }, - GetVersionFunc: func(datasetID, edition, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, edition string, version int, state string) (*models.Version, error) { return versionDoc, nil }, } @@ -93,7 +93,7 @@ func TestGetMetadataReturnsOk(t *testing.T) { CheckEditionExistsFunc: func(datasetID, edition, state string) error { return nil }, - GetVersionFunc: func(datasetID, edition, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, edition string, version int, state string) (*models.Version, error) { return versionDoc, nil }, } @@ -144,7 +144,7 @@ func TestGetMetadataReturnsError(t *testing.T) { w := httptest.NewRecorder() mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(datasetID, edition, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, edition string, version int, state string) (*models.Version, error) { return nil, errs.ErrInternalServer }, } @@ -173,7 +173,7 @@ func TestGetMetadataReturnsError(t *testing.T) { GetDatasetFunc: func(datasetID string) (*models.DatasetUpdate, error) { return nil, errs.ErrDatasetNotFound }, - GetVersionFunc: func(datasetID, edition, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, edition string, version int, state string) (*models.Version, error) { return nil, nil }, } @@ -208,7 +208,7 @@ func TestGetMetadataReturnsError(t *testing.T) { CheckEditionExistsFunc: func(datasetId, edition, state string) error { return nil }, - GetVersionFunc: func(datasetID, edition, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, edition string, version int, state string) (*models.Version, error) { return versionDoc, nil }, } @@ -243,7 +243,7 @@ func TestGetMetadataReturnsError(t *testing.T) { CheckEditionExistsFunc: func(datasetId, edition, state string) error { return errs.ErrEditionNotFound }, - GetVersionFunc: func(datasetID, edition, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, edition string, version int, state string) (*models.Version, error) { return versionDoc, nil }, } @@ -278,7 +278,7 @@ func TestGetMetadataReturnsError(t *testing.T) { CheckEditionExistsFunc: func(datasetId, edition, state string) error { return nil }, - GetVersionFunc: func(datasetID, edition, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, edition string, version int, state string) (*models.Version, error) { return nil, errs.ErrVersionNotFound }, } @@ -315,7 +315,7 @@ func TestGetMetadataReturnsError(t *testing.T) { CheckEditionExistsFunc: func(datasetId, edition, state string) error { return nil }, - GetVersionFunc: func(datasetID, edition, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, edition string, version int, state string) (*models.Version, error) { return &models.Version{State: "gobbly-gook"}, nil }, } diff --git a/api/publish_state_checker.go b/api/publish_state_checker.go index 4d6f89f5..567adba7 100644 --- a/api/publish_state_checker.go +++ b/api/publish_state_checker.go @@ -5,6 +5,7 @@ import ( "encoding/json" "io/ioutil" "net/http" + "strconv" errs "github.com/ONSdigital/dp-dataset-api/apierrors" "github.com/ONSdigital/dp-dataset-api/models" @@ -31,7 +32,19 @@ func (d *PublishCheck) Check(handle func(http.ResponseWriter, *http.Request), ac version := vars["version"] data := log.Data{"dataset_id": datasetID, "edition": edition, "version": version} - currentVersion, err := d.Datastore.GetVersion(datasetID, edition, version, "") + versionId, err := strconv.Atoi(version) + if err != nil { + log.Event(ctx, "failed due to invalid version request", log.ERROR, log.Error(err), data) + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + if !(versionId > 0) { + log.Event(ctx, "version is not a positive integer", log.ERROR, log.Error(err), data) + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + + currentVersion, err := d.Datastore.GetVersion(datasetID, edition, versionId, "") if err != nil { if err != errs.ErrVersionNotFound { log.Event(ctx, "errored whilst retrieving version resource", log.ERROR, log.Error(err), data) diff --git a/api/versions.go b/api/versions.go index 39e32aa2..8ea6dd10 100644 --- a/api/versions.go +++ b/api/versions.go @@ -7,6 +7,8 @@ import ( "net/http" "strings" + "strconv" + errs "github.com/ONSdigital/dp-dataset-api/apierrors" "github.com/ONSdigital/dp-dataset-api/models" dphttp "github.com/ONSdigital/dp-net/http" @@ -140,6 +142,16 @@ func (api *DatasetAPI) getVersion(w http.ResponseWriter, r *http.Request) { b, getVersionErr := func() ([]byte, error) { authorised := api.authenticate(r, logData) + versionId, err := strconv.Atoi(version) + if err != nil { + log.Event(ctx, "invalid version provided", log.ERROR, log.Error(err), logData) + return nil, errs.ErrInvalidVersion + } + if !(versionId > 0) { + log.Event(ctx, "version is not a positive integer", log.ERROR, log.Error(err), logData) + return nil, errs.ErrInvalidVersion + } + var state string if !authorised { state = models.PublishedState @@ -155,7 +167,7 @@ func (api *DatasetAPI) getVersion(w http.ResponseWriter, r *http.Request) { return nil, err } - results, err := api.dataStore.Backend.GetVersion(datasetID, edition, version, state) + results, err := api.dataStore.Backend.GetVersion(datasetID, edition, versionId, state) if err != nil { log.Event(ctx, "failed to find version for dataset edition", log.ERROR, log.Error(err), logData) return nil, err @@ -277,6 +289,15 @@ func (api *DatasetAPI) detachVersion(w http.ResponseWriter, r *http.Request) { return errs.ErrNotFound } + versionId, err := strconv.Atoi(version) + if err != nil { + log.Event(ctx, "detachVersion endpoint: invalid version request", log.ERROR, log.Error(err), logData) + return errs.ErrInvalidVersion + } + if !(versionId > 0) { + log.Event(ctx, "detachVersion endpoint: version is not a positive integer", log.ERROR, log.Error(err), logData) + return errs.ErrInvalidVersion + } editionDoc, err := api.dataStore.Backend.GetEdition(datasetID, edition, "") if err != nil { log.Event(ctx, "detachVersion endpoint: Cannot find the specified edition", log.ERROR, log.Error(errs.ErrEditionNotFound), logData) @@ -296,7 +317,7 @@ func (api *DatasetAPI) detachVersion(w http.ResponseWriter, r *http.Request) { return errs.ErrIncorrectStateToDetach } - versionDoc, err := api.dataStore.Backend.GetVersion(datasetID, edition, version, editionDoc.Next.State) + versionDoc, err := api.dataStore.Backend.GetVersion(datasetID, edition, versionId, editionDoc.Next.State) if err != nil { log.Event(ctx, "detachVersion endpoint: Cannot find the specified version", log.ERROR, log.Error(errs.ErrVersionNotFound), logData) return errs.ErrVersionNotFound @@ -361,12 +382,22 @@ func (api *DatasetAPI) updateVersion(ctx context.Context, body io.ReadCloser, ve return nil, nil, nil, err } + version, err := strconv.Atoi(versionDetails.version) + if err != nil { + log.Event(ctx, "putVersion endpoint: invalid version request", log.ERROR, log.Error(err), data) + return nil, nil, nil, errs.ErrInvalidVersion + } + if !(version > 0) { + log.Event(ctx, "putVersion endpoint: version is not a positive integer", log.ERROR, log.Error(err), data) + return nil, nil, nil, errs.ErrInvalidVersion + } + if err = api.dataStore.Backend.CheckEditionExists(versionDetails.datasetID, versionDetails.edition, ""); err != nil { log.Event(ctx, "putVersion endpoint: failed to find edition of dataset", log.ERROR, log.Error(err), data) return nil, nil, nil, err } - currentVersion, err := api.dataStore.Backend.GetVersion(versionDetails.datasetID, versionDetails.edition, versionDetails.version, "") + currentVersion, err := api.dataStore.Backend.GetVersion(versionDetails.datasetID, versionDetails.edition, version, "") if err != nil { log.Event(ctx, "putVersion endpoint: datastore.GetVersion returned an error", log.ERROR, log.Error(err), data) return nil, nil, nil, err @@ -622,6 +653,8 @@ func handleVersionAPIErr(ctx context.Context, err error, w http.ResponseWriter, status = http.StatusBadRequest case strings.HasPrefix(err.Error(), "invalid fields:"): status = http.StatusBadRequest + case strings.HasPrefix(err.Error(), "strconv.Atoi"): + status = http.StatusBadRequest default: err = errs.ErrInternalServer status = http.StatusInternalServerError diff --git a/api/versions_test.go b/api/versions_test.go index 18450726..1b33983c 100644 --- a/api/versions_test.go +++ b/api/versions_test.go @@ -234,7 +234,7 @@ func TestGetVersionReturnsOK(t *testing.T) { CheckEditionExistsFunc: func(datasetID, editionID, state string) error { return nil }, - GetVersionFunc: func(datasetID, editionID, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, editionID string, version int, state string) (*models.Version, error) { return &models.Version{ State: models.EditionConfirmedState, Links: &models.VersionLinks{ @@ -348,7 +348,7 @@ func TestGetVersionReturnsError(t *testing.T) { CheckEditionExistsFunc: func(datasetID, editionID, state string) error { return nil }, - GetVersionFunc: func(datasetID, editionID, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, editionID string, version int, state string) (*models.Version, error) { return nil, errs.ErrVersionNotFound }, } @@ -378,7 +378,7 @@ func TestGetVersionReturnsError(t *testing.T) { CheckEditionExistsFunc: func(datasetID, editionID, state string) error { return nil }, - GetVersionFunc: func(datasetID, editionID, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, editionID string, version int, state string) (*models.Version, error) { return nil, errs.ErrVersionNotFound }, } @@ -410,7 +410,7 @@ func TestGetVersionReturnsError(t *testing.T) { CheckEditionExistsFunc: func(datasetID, editionID, state string) error { return nil }, - GetVersionFunc: func(datasetID, editionID, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, editionID string, version int, state string) (*models.Version, error) { return &models.Version{ State: "gobbly-gook", Links: &models.VersionLinks{ @@ -462,7 +462,7 @@ func TestPutVersionReturnsSuccessfully(t *testing.T) { CheckEditionExistsFunc: func(string, string, string) error { return nil }, - GetVersionFunc: func(string, string, string, string) (*models.Version, error) { + GetVersionFunc: func(string, string, int, string) (*models.Version, error) { return &models.Version{ ID: "789", Links: &models.VersionLinks{ @@ -535,7 +535,7 @@ func TestPutVersionReturnsSuccessfully(t *testing.T) { CheckEditionExistsFunc: func(string, string, string) error { return nil }, - GetVersionFunc: func(string, string, string, string) (*models.Version, error) { + GetVersionFunc: func(string, string, int, string) (*models.Version, error) { return &models.Version{ State: models.AssociatedState, }, nil @@ -596,7 +596,7 @@ func TestPutVersionReturnsSuccessfully(t *testing.T) { CheckEditionExistsFunc: func(string, string, string) error { return nil }, - GetVersionFunc: func(string, string, string, string) (*models.Version, error) { + GetVersionFunc: func(string, string, int, string) (*models.Version, error) { return &models.Version{ State: models.EditionConfirmedState, }, nil @@ -661,7 +661,7 @@ func TestPutVersionReturnsSuccessfully(t *testing.T) { CheckEditionExistsFunc: func(string, string, string) error { return nil }, - GetVersionFunc: func(string, string, string, string) (*models.Version, error) { + GetVersionFunc: func(string, string, int, string) (*models.Version, error) { return &models.Version{ ID: "789", Links: &models.VersionLinks{ @@ -809,7 +809,7 @@ func updateVersionDownloadTest(r *http.Request) { CheckEditionExistsFunc: func(string, string, string) error { return nil }, - GetVersionFunc: func(string, string, string, string) (*models.Version, error) { + GetVersionFunc: func(string, string, int, string) (*models.Version, error) { return &models.Version{ ID: "789", Links: &models.VersionLinks{ @@ -883,7 +883,7 @@ func TestPutVersionGenerateDownloadsError(t *testing.T) { v.State = models.EditionConfirmedState mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(datasetID string, editionID string, version string, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID string, editionID string, version int, state string) (*models.Version, error) { return &v, nil }, GetDatasetFunc: func(datasetID string) (*models.DatasetUpdate, error) { @@ -941,7 +941,7 @@ func TestPutVersionGenerateDownloadsError(t *testing.T) { So(len(mockedDataStore.GetVersionCalls()), ShouldEqual, 2) So(mockedDataStore.GetVersionCalls()[0].DatasetID, ShouldEqual, "123") So(mockedDataStore.GetVersionCalls()[0].EditionID, ShouldEqual, "2017") - So(mockedDataStore.GetVersionCalls()[0].Version, ShouldEqual, "1") + So(mockedDataStore.GetVersionCalls()[0].Version, ShouldEqual, 1) So(len(mockedDataStore.UpdateVersionCalls()), ShouldEqual, 1) So(len(genCalls), ShouldEqual, 1) @@ -966,7 +966,7 @@ func TestPutEmptyVersion(t *testing.T) { Convey("given an existing version with empty downloads", t, func() { mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(datasetID string, editionID string, version string, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID string, editionID string, version int, state string) (*models.Version, error) { return &v, nil }, GetDatasetFunc: func(datasetID string) (*models.DatasetUpdate, error) { @@ -1007,7 +1007,7 @@ func TestPutEmptyVersion(t *testing.T) { Convey("given an existing version with a xls download already exists", t, func() { mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(datasetID string, editionID string, version string, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID string, editionID string, version int, state string) (*models.Version, error) { v.Downloads = xlsDownload return &v, nil }, @@ -1057,7 +1057,7 @@ func TestPutEmptyVersion(t *testing.T) { So(len(mockedDataStore.GetVersionCalls()), ShouldEqual, 2) So(mockedDataStore.GetVersionCalls()[0].DatasetID, ShouldEqual, "123") So(mockedDataStore.GetVersionCalls()[0].EditionID, ShouldEqual, "2017") - So(mockedDataStore.GetVersionCalls()[0].Version, ShouldEqual, "1") + So(mockedDataStore.GetVersionCalls()[0].Version, ShouldEqual, 1) So(mockedDataStore.GetVersionCalls()[0].State, ShouldEqual, "") So(len(mockedDataStore.UpsertEditionCalls()), ShouldEqual, 0) @@ -1084,7 +1084,7 @@ func TestPutVersionReturnsError(t *testing.T) { w := httptest.NewRecorder() mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(string, string, string, string) (*models.Version, error) { + GetVersionFunc: func(string, string, int, string) (*models.Version, error) { return &models.Version{State: models.AssociatedState}, nil }, GetDatasetFunc: func(datasetID string) (*models.DatasetUpdate, error) { @@ -1126,7 +1126,7 @@ func TestPutVersionReturnsError(t *testing.T) { w := httptest.NewRecorder() mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(string, string, string, string) (*models.Version, error) { + GetVersionFunc: func(string, string, int, string) (*models.Version, error) { return nil, errs.ErrInternalServer }, GetDatasetFunc: func(datasetID string) (*models.DatasetUpdate, error) { @@ -1168,7 +1168,7 @@ func TestPutVersionReturnsError(t *testing.T) { w := httptest.NewRecorder() mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(string, string, string, string) (*models.Version, error) { + GetVersionFunc: func(string, string, int, string) (*models.Version, error) { return &models.Version{}, errs.ErrVersionNotFound }, GetDatasetFunc: func(datasetID string) (*models.DatasetUpdate, error) { @@ -1214,7 +1214,7 @@ func TestPutVersionReturnsError(t *testing.T) { w := httptest.NewRecorder() mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(string, string, string, string) (*models.Version, error) { + GetVersionFunc: func(string, string, int, string) (*models.Version, error) { return &models.Version{}, errs.ErrVersionNotFound }, GetDatasetFunc: func(datasetID string) (*models.DatasetUpdate, error) { @@ -1260,7 +1260,7 @@ func TestPutVersionReturnsError(t *testing.T) { w := httptest.NewRecorder() mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(string, string, string, string) (*models.Version, error) { + GetVersionFunc: func(string, string, int, string) (*models.Version, error) { return &models.Version{}, errs.ErrVersionNotFound }, GetDatasetFunc: func(datasetID string) (*models.DatasetUpdate, error) { @@ -1309,7 +1309,7 @@ func TestPutVersionReturnsError(t *testing.T) { So(err, ShouldBeNil) w := httptest.NewRecorder() mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(string, string, string, string) (*models.Version, error) { + GetVersionFunc: func(string, string, int, string) (*models.Version, error) { return &models.Version{ State: "associated", }, nil @@ -1349,7 +1349,7 @@ func TestPutVersionReturnsError(t *testing.T) { w := httptest.NewRecorder() mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(string, string, string, string) (*models.Version, error) { + GetVersionFunc: func(string, string, int, string) (*models.Version, error) { return &models.Version{ State: models.PublishedState, }, nil @@ -1392,7 +1392,7 @@ func TestPutVersionReturnsError(t *testing.T) { w := httptest.NewRecorder() mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(string, string, string, string) (*models.Version, error) { + GetVersionFunc: func(string, string, int, string) (*models.Version, error) { return &models.Version{State: "associated"}, nil }, GetDatasetFunc: func(datasetID string) (*models.DatasetUpdate, error) { @@ -1446,7 +1446,7 @@ func TestPutVersionReturnsError(t *testing.T) { CheckEditionExistsFunc: func(string, string, string) error { return nil }, - GetVersionFunc: func(string, string, string, string) (*models.Version, error) { + GetVersionFunc: func(string, string, int, string) (*models.Version, error) { return &models.Version{ ID: "789", Links: &models.VersionLinks{ @@ -1520,7 +1520,7 @@ func TestPutVersionReturnsError(t *testing.T) { }, } - mockedDataStore.GetVersion("789", "2017", "1", "") + mockedDataStore.GetVersion("789", "2017", 1, "") mockedDataStore.GetEdition("123", "2017", "") mockedDataStore.UpdateVersion("a1b2c3", &models.Version{}) mockedDataStore.GetDataset("123") @@ -1702,7 +1702,7 @@ func TestDetachVersionReturnOK(t *testing.T) { LatestVersion: &models.LinkObject{ ID: "1"}}}}, nil }, - GetVersionFunc: func(datasetID string, editionID string, version string, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID string, editionID string, version int, state string) (*models.Version, error) { return &models.Version{}, nil }, GetDatasetFunc: func(ID string) (*models.DatasetUpdate, error) { @@ -1761,7 +1761,7 @@ func TestDetachVersionReturnOK(t *testing.T) { LatestVersion: &models.LinkObject{ ID: "1"}}}}, nil }, - GetVersionFunc: func(datasetID string, editionID string, version string, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID string, editionID string, version int, state string) (*models.Version, error) { return &models.Version{}, nil }, GetDatasetFunc: func(ID string) (*models.DatasetUpdate, error) { @@ -1929,7 +1929,7 @@ func TestDetachVersionReturnsError(t *testing.T) { State: models.PublishedState, Links: &models.EditionUpdateLinks{LatestVersion: &models.LinkObject{ID: "1"}}}}, nil }, - GetVersionFunc: func(datasetID, editionID, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, editionID string, version int, state string) (*models.Version, error) { return &models.Version{}, nil }, } @@ -1968,7 +1968,7 @@ func TestDetachVersionReturnsError(t *testing.T) { State: models.EditionConfirmedState, Links: &models.EditionUpdateLinks{LatestVersion: &models.LinkObject{ID: "1"}}}}, nil }, - GetVersionFunc: func(datasetID, editionID, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, editionID string, version int, state string) (*models.Version, error) { return nil, errs.ErrVersionNotFound }, } @@ -2012,7 +2012,7 @@ func TestDetachVersionReturnsError(t *testing.T) { return &models.DatasetUpdate{}, nil }, - GetVersionFunc: func(datasetID, editionID, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, editionID string, version int, state string) (*models.Version, error) { return &models.Version{}, nil }, UpdateVersionFunc: func(ID string, version *models.Version) error { @@ -2055,7 +2055,7 @@ func TestDetachVersionReturnsError(t *testing.T) { State: models.EditionConfirmedState, Links: &models.EditionUpdateLinks{LatestVersion: &models.LinkObject{ID: "1"}}}}, nil }, - GetVersionFunc: func(datasetID, editionID, version, state string) (*models.Version, error) { + GetVersionFunc: func(datasetID, editionID string, version int, state string) (*models.Version, error) { return &models.Version{}, nil }, diff --git a/api/webendpoints_test.go b/api/webendpoints_test.go index f50ce0a4..96031512 100644 --- a/api/webendpoints_test.go +++ b/api/webendpoints_test.go @@ -211,7 +211,7 @@ func TestWebSubnetVersionEndpoint(t *testing.T) { editionSearchState = state return nil }, - GetVersionFunc: func(id string, editionID, version string, state string) (*models.Version, error) { + GetVersionFunc: func(id string, editionID string, version int, state string) (*models.Version, error) { versionSearchState = state return &models.Version{ID: "124", State: models.PublishedState, Links: &models.VersionLinks{ @@ -240,7 +240,7 @@ func TestWebSubnetDimensionsEndpoint(t *testing.T) { var versionSearchState string w := httptest.NewRecorder() mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(id string, editionID, version string, state string) (*models.Version, error) { + GetVersionFunc: func(id string, editionID string, version int, state string) (*models.Version, error) { versionSearchState = state return &models.Version{ID: "124", State: models.PublishedState, Links: &models.VersionLinks{ @@ -270,7 +270,7 @@ func TestWebSubnetDimensionOptionsEndpoint(t *testing.T) { var versionSearchState string w := httptest.NewRecorder() mockedDataStore := &storetest.StorerMock{ - GetVersionFunc: func(id string, editionID, version string, state string) (*models.Version, error) { + GetVersionFunc: func(id string, editionID string, version int, state string) (*models.Version, error) { versionSearchState = state return &models.Version{ID: "124", State: models.PublishedState, Links: &models.VersionLinks{ diff --git a/apierrors/errors.go b/apierrors/errors.go index b1c3ef60..09a1aabf 100644 --- a/apierrors/errors.go +++ b/apierrors/errors.go @@ -51,6 +51,7 @@ var ( ErrUnauthorised = errors.New("unauthorised access to API") ErrVersionMissingState = errors.New("missing state from version") ErrVersionNotFound = errors.New("version not found") + ErrInvalidVersion = errors.New("invalid version requested") ErrVersionAlreadyExists = errors.New("an unpublished version of this dataset already exists") ErrNotFound = errors.New("not found") @@ -82,6 +83,7 @@ var ( ErrUnableToReadMessage: true, ErrTypeMismatch: true, ErrDatasetTypeInvalid: true, + ErrInvalidVersion: true, } ConflictRequestMap = map[error]bool{ diff --git a/mongo/dataset_store.go b/mongo/dataset_store.go index ee091c9e..f80a4444 100644 --- a/mongo/dataset_store.go +++ b/mongo/dataset_store.go @@ -3,7 +3,7 @@ package mongo import ( "context" "errors" - "strconv" + "sync" "time" @@ -332,18 +332,14 @@ func buildVersionsQuery(datasetID, editionID, state string) bson.M { } // GetVersion retrieves a version document for a dataset edition -func (m *Mongo) GetVersion(id, editionID, versionID, state string) (*models.Version, error) { +func (m *Mongo) GetVersion(id, editionID string, versionID int, state string) (*models.Version, error) { s := m.Session.Copy() defer s.Close() - versionNumber, err := strconv.Atoi(versionID) - if err != nil { - return nil, err - } - selector := buildVersionQuery(id, editionID, state, versionNumber) + selector := buildVersionQuery(id, editionID, state, versionID) var version models.Version - err = s.DB(m.Database).C("instances").Find(selector).One(&version) + err := s.DB(m.Database).C("instances").Find(selector).One(&version) if err != nil { if err == mgo.ErrNotFound { return nil, errs.ErrVersionNotFound diff --git a/store/datastore.go b/store/datastore.go index 4d05949f..ab23530b 100644 --- a/store/datastore.go +++ b/store/datastore.go @@ -36,7 +36,7 @@ type dataMongoDB interface { GetInstance(ID string) (*models.Instance, error) GetNextVersion(datasetID, editionID string) (int, error) GetUniqueDimensionAndOptions(ID, dimension string) (*models.DimensionValues, error) - GetVersion(datasetID, editionID, version, state string) (*models.Version, error) + GetVersion(datasetID, editionID string, version int, state string) (*models.Version, error) GetVersions(ctx context.Context, datasetID, editionID, state string, offset, limit int) ([]models.Version, int, error) UpdateDataset(ctx context.Context, ID string, dataset *models.Dataset, currentState string) error UpdateDatasetWithAssociation(ID, state string, version *models.Version) error diff --git a/store/datastoretest/datastore.go b/store/datastoretest/datastore.go index 8ca54f20..f4f8531b 100755 --- a/store/datastoretest/datastore.go +++ b/store/datastoretest/datastore.go @@ -17,124 +17,124 @@ var _ store.Storer = &StorerMock{} // StorerMock is a mock implementation of store.Storer. // -// func TestSomethingThatUsesStorer(t *testing.T) { +// func TestSomethingThatUsesStorer(t *testing.T) { // -// // make and configure a mocked store.Storer -// mockedStorer := &StorerMock{ -// AddDimensionToInstanceFunc: func(dimension *models.CachedDimensionOption) error { -// panic("mock out the AddDimensionToInstance method") -// }, -// AddEventToInstanceFunc: func(instanceID string, event *models.Event) error { -// panic("mock out the AddEventToInstance method") -// }, -// AddInstanceFunc: func(instance *models.Instance) (*models.Instance, error) { -// panic("mock out the AddInstance method") -// }, -// AddVersionDetailsToInstanceFunc: func(ctx context.Context, instanceID string, datasetID string, edition string, version int) error { -// panic("mock out the AddVersionDetailsToInstance method") -// }, -// CheckDatasetExistsFunc: func(ID string, state string) error { -// panic("mock out the CheckDatasetExists method") -// }, -// CheckEditionExistsFunc: func(ID string, editionID string, state string) error { -// panic("mock out the CheckEditionExists method") -// }, -// DeleteDatasetFunc: func(ID string) error { -// panic("mock out the DeleteDataset method") -// }, -// DeleteEditionFunc: func(ID string) error { -// panic("mock out the DeleteEdition method") -// }, -// GetDatasetFunc: func(ID string) (*models.DatasetUpdate, error) { -// panic("mock out the GetDataset method") -// }, -// GetDatasetsFunc: func(ctx context.Context, offset int, limit int, authorised bool) ([]*models.DatasetUpdate, int, error) { -// panic("mock out the GetDatasets method") -// }, -// GetDimensionOptionsFunc: func(version *models.Version, dimension string, offset int, limit int) ([]*models.PublicDimensionOption, int, error) { -// panic("mock out the GetDimensionOptions method") -// }, -// GetDimensionOptionsFromIDsFunc: func(version *models.Version, dimension string, ids []string) ([]*models.PublicDimensionOption, int, error) { -// panic("mock out the GetDimensionOptionsFromIDs method") -// }, -// GetDimensionsFunc: func(datasetID string, versionID string) ([]bson.M, error) { -// panic("mock out the GetDimensions method") -// }, -// GetDimensionsFromInstanceFunc: func(ID string) (*models.DimensionNodeResults, error) { -// panic("mock out the GetDimensionsFromInstance method") -// }, -// GetEditionFunc: func(ID string, editionID string, state string) (*models.EditionUpdate, error) { -// panic("mock out the GetEdition method") -// }, -// GetEditionsFunc: func(ctx context.Context, ID string, state string, offset int, limit int, authorised bool) ([]*models.EditionUpdate, int, error) { -// panic("mock out the GetEditions method") -// }, -// GetInstanceFunc: func(ID string) (*models.Instance, error) { -// panic("mock out the GetInstance method") -// }, -// GetInstancesFunc: func(ctx context.Context, states []string, datasets []string, offset int, limit int) ([]*models.Instance, int, error) { -// panic("mock out the GetInstances method") -// }, -// GetNextVersionFunc: func(datasetID string, editionID string) (int, error) { -// panic("mock out the GetNextVersion method") -// }, -// GetUniqueDimensionAndOptionsFunc: func(ID string, dimension string) (*models.DimensionValues, error) { -// panic("mock out the GetUniqueDimensionAndOptions method") -// }, -// GetVersionFunc: func(datasetID string, editionID string, version string, state string) (*models.Version, error) { -// panic("mock out the GetVersion method") -// }, -// GetVersionsFunc: func(ctx context.Context, datasetID string, editionID string, state string, offset int, limit int) ([]models.Version, int, error) { -// panic("mock out the GetVersions method") -// }, -// SetInstanceIsPublishedFunc: func(ctx context.Context, instanceID string) error { -// panic("mock out the SetInstanceIsPublished method") -// }, -// UpdateBuildHierarchyTaskStateFunc: func(id string, dimension string, state string) error { -// panic("mock out the UpdateBuildHierarchyTaskState method") -// }, -// UpdateBuildSearchTaskStateFunc: func(id string, dimension string, state string) error { -// panic("mock out the UpdateBuildSearchTaskState method") -// }, -// UpdateDatasetFunc: func(ctx context.Context, ID string, dataset *models.Dataset, currentState string) error { -// panic("mock out the UpdateDataset method") -// }, -// UpdateDatasetWithAssociationFunc: func(ID string, state string, version *models.Version) error { -// panic("mock out the UpdateDatasetWithAssociation method") -// }, -// UpdateDimensionNodeIDAndOrderFunc: func(dimension *models.DimensionOption) error { -// panic("mock out the UpdateDimensionNodeIDAndOrder method") -// }, -// UpdateImportObservationsTaskStateFunc: func(id string, state string) error { -// panic("mock out the UpdateImportObservationsTaskState method") -// }, -// UpdateInstanceFunc: func(ctx context.Context, ID string, instance *models.Instance) error { -// panic("mock out the UpdateInstance method") -// }, -// UpdateObservationInsertedFunc: func(ID string, observationInserted int64) error { -// panic("mock out the UpdateObservationInserted method") -// }, -// UpdateVersionFunc: func(ID string, version *models.Version) error { -// panic("mock out the UpdateVersion method") -// }, -// UpsertContactFunc: func(ID string, update interface{}) error { -// panic("mock out the UpsertContact method") -// }, -// UpsertDatasetFunc: func(ID string, datasetDoc *models.DatasetUpdate) error { -// panic("mock out the UpsertDataset method") -// }, -// UpsertEditionFunc: func(datasetID string, edition string, editionDoc *models.EditionUpdate) error { -// panic("mock out the UpsertEdition method") -// }, -// UpsertVersionFunc: func(ID string, versionDoc *models.Version) error { -// panic("mock out the UpsertVersion method") -// }, -// } +// // make and configure a mocked store.Storer +// mockedStorer := &StorerMock{ +// AddDimensionToInstanceFunc: func(dimension *models.CachedDimensionOption) error { +// panic("mock out the AddDimensionToInstance method") +// }, +// AddEventToInstanceFunc: func(instanceID string, event *models.Event) error { +// panic("mock out the AddEventToInstance method") +// }, +// AddInstanceFunc: func(instance *models.Instance) (*models.Instance, error) { +// panic("mock out the AddInstance method") +// }, +// AddVersionDetailsToInstanceFunc: func(ctx context.Context, instanceID string, datasetID string, edition string, version int) error { +// panic("mock out the AddVersionDetailsToInstance method") +// }, +// CheckDatasetExistsFunc: func(ID string, state string) error { +// panic("mock out the CheckDatasetExists method") +// }, +// CheckEditionExistsFunc: func(ID string, editionID string, state string) error { +// panic("mock out the CheckEditionExists method") +// }, +// DeleteDatasetFunc: func(ID string) error { +// panic("mock out the DeleteDataset method") +// }, +// DeleteEditionFunc: func(ID string) error { +// panic("mock out the DeleteEdition method") +// }, +// GetDatasetFunc: func(ID string) (*models.DatasetUpdate, error) { +// panic("mock out the GetDataset method") +// }, +// GetDatasetsFunc: func(ctx context.Context, offset int, limit int, authorised bool) ([]*models.DatasetUpdate, int, error) { +// panic("mock out the GetDatasets method") +// }, +// GetDimensionOptionsFunc: func(version *models.Version, dimension string, offset int, limit int) ([]*models.PublicDimensionOption, int, error) { +// panic("mock out the GetDimensionOptions method") +// }, +// GetDimensionOptionsFromIDsFunc: func(version *models.Version, dimension string, ids []string) ([]*models.PublicDimensionOption, int, error) { +// panic("mock out the GetDimensionOptionsFromIDs method") +// }, +// GetDimensionsFunc: func(datasetID string, versionID string) ([]bson.M, error) { +// panic("mock out the GetDimensions method") +// }, +// GetDimensionsFromInstanceFunc: func(ID string) (*models.DimensionNodeResults, error) { +// panic("mock out the GetDimensionsFromInstance method") +// }, +// GetEditionFunc: func(ID string, editionID string, state string) (*models.EditionUpdate, error) { +// panic("mock out the GetEdition method") +// }, +// GetEditionsFunc: func(ctx context.Context, ID string, state string, offset int, limit int, authorised bool) ([]*models.EditionUpdate, int, error) { +// panic("mock out the GetEditions method") +// }, +// GetInstanceFunc: func(ID string) (*models.Instance, error) { +// panic("mock out the GetInstance method") +// }, +// GetInstancesFunc: func(ctx context.Context, states []string, datasets []string, offset int, limit int) ([]*models.Instance, int, error) { +// panic("mock out the GetInstances method") +// }, +// GetNextVersionFunc: func(datasetID string, editionID string) (int, error) { +// panic("mock out the GetNextVersion method") +// }, +// GetUniqueDimensionAndOptionsFunc: func(ID string, dimension string) (*models.DimensionValues, error) { +// panic("mock out the GetUniqueDimensionAndOptions method") +// }, +// GetVersionFunc: func(datasetID string, editionID string, version int, state string) (*models.Version, error) { +// panic("mock out the GetVersion method") +// }, +// GetVersionsFunc: func(ctx context.Context, datasetID string, editionID string, state string, offset int, limit int) ([]models.Version, int, error) { +// panic("mock out the GetVersions method") +// }, +// SetInstanceIsPublishedFunc: func(ctx context.Context, instanceID string) error { +// panic("mock out the SetInstanceIsPublished method") +// }, +// UpdateBuildHierarchyTaskStateFunc: func(id string, dimension string, state string) error { +// panic("mock out the UpdateBuildHierarchyTaskState method") +// }, +// UpdateBuildSearchTaskStateFunc: func(id string, dimension string, state string) error { +// panic("mock out the UpdateBuildSearchTaskState method") +// }, +// UpdateDatasetFunc: func(ctx context.Context, ID string, dataset *models.Dataset, currentState string) error { +// panic("mock out the UpdateDataset method") +// }, +// UpdateDatasetWithAssociationFunc: func(ID string, state string, version *models.Version) error { +// panic("mock out the UpdateDatasetWithAssociation method") +// }, +// UpdateDimensionNodeIDAndOrderFunc: func(dimension *models.DimensionOption) error { +// panic("mock out the UpdateDimensionNodeIDAndOrder method") +// }, +// UpdateImportObservationsTaskStateFunc: func(id string, state string) error { +// panic("mock out the UpdateImportObservationsTaskState method") +// }, +// UpdateInstanceFunc: func(ctx context.Context, ID string, instance *models.Instance) error { +// panic("mock out the UpdateInstance method") +// }, +// UpdateObservationInsertedFunc: func(ID string, observationInserted int64) error { +// panic("mock out the UpdateObservationInserted method") +// }, +// UpdateVersionFunc: func(ID string, version *models.Version) error { +// panic("mock out the UpdateVersion method") +// }, +// UpsertContactFunc: func(ID string, update interface{}) error { +// panic("mock out the UpsertContact method") +// }, +// UpsertDatasetFunc: func(ID string, datasetDoc *models.DatasetUpdate) error { +// panic("mock out the UpsertDataset method") +// }, +// UpsertEditionFunc: func(datasetID string, edition string, editionDoc *models.EditionUpdate) error { +// panic("mock out the UpsertEdition method") +// }, +// UpsertVersionFunc: func(ID string, versionDoc *models.Version) error { +// panic("mock out the UpsertVersion method") +// }, +// } // -// // use mockedStorer in code that requires store.Storer -// // and then make assertions. +// // use mockedStorer in code that requires store.Storer +// // and then make assertions. // -// } +// } type StorerMock struct { // AddDimensionToInstanceFunc mocks the AddDimensionToInstance method. AddDimensionToInstanceFunc func(dimension *models.CachedDimensionOption) error @@ -197,7 +197,7 @@ type StorerMock struct { GetUniqueDimensionAndOptionsFunc func(ID string, dimension string) (*models.DimensionValues, error) // GetVersionFunc mocks the GetVersion method. - GetVersionFunc func(datasetID string, editionID string, version string, state string) (*models.Version, error) + GetVersionFunc func(datasetID string, editionID string, version int, state string) (*models.Version, error) // GetVersionsFunc mocks the GetVersions method. GetVersionsFunc func(ctx context.Context, datasetID string, editionID string, state string, offset int, limit int) ([]models.Version, int, error) @@ -413,7 +413,7 @@ type StorerMock struct { // EditionID is the editionID argument value. EditionID string // Version is the version argument value. - Version string + Version int // State is the state argument value. State string } @@ -1322,14 +1322,14 @@ func (mock *StorerMock) GetUniqueDimensionAndOptionsCalls() []struct { } // GetVersion calls GetVersionFunc. -func (mock *StorerMock) GetVersion(datasetID string, editionID string, version string, state string) (*models.Version, error) { +func (mock *StorerMock) GetVersion(datasetID string, editionID string, version int, state string) (*models.Version, error) { if mock.GetVersionFunc == nil { panic("StorerMock.GetVersionFunc: method is nil but Storer.GetVersion was just called") } callInfo := struct { DatasetID string EditionID string - Version string + Version int State string }{ DatasetID: datasetID, @@ -1349,13 +1349,13 @@ func (mock *StorerMock) GetVersion(datasetID string, editionID string, version s func (mock *StorerMock) GetVersionCalls() []struct { DatasetID string EditionID string - Version string + Version int State string } { var calls []struct { DatasetID string EditionID string - Version string + Version int State string } mock.lockGetVersion.RLock() diff --git a/store/datastoretest/graph.go b/store/datastoretest/graph.go index b7c6176c..454d3925 100644 --- a/store/datastoretest/graph.go +++ b/store/datastoretest/graph.go @@ -16,34 +16,34 @@ var _ store.GraphDB = &GraphDBMock{} // GraphDBMock is a mock implementation of store.GraphDB. // -// func TestSomethingThatUsesGraphDB(t *testing.T) { +// func TestSomethingThatUsesGraphDB(t *testing.T) { // -// // make and configure a mocked store.GraphDB -// mockedGraphDB := &GraphDBMock{ -// AddVersionDetailsToInstanceFunc: func(ctx context.Context, instanceID string, datasetID string, edition string, version int) error { -// panic("mock out the AddVersionDetailsToInstance method") -// }, -// CheckerFunc: func(contextMoqParam context.Context, checkState *healthcheck.CheckState) error { -// panic("mock out the Checker method") -// }, -// CloseFunc: func(ctx context.Context) error { -// panic("mock out the Close method") -// }, -// SetInstanceIsPublishedFunc: func(ctx context.Context, instanceID string) error { -// panic("mock out the SetInstanceIsPublished method") -// }, -// } +// // make and configure a mocked store.GraphDB +// mockedGraphDB := &GraphDBMock{ +// AddVersionDetailsToInstanceFunc: func(ctx context.Context, instanceID string, datasetID string, edition string, version int) error { +// panic("mock out the AddVersionDetailsToInstance method") +// }, +// CheckerFunc: func(in1 context.Context, in2 *healthcheck.CheckState) error { +// panic("mock out the Checker method") +// }, +// CloseFunc: func(ctx context.Context) error { +// panic("mock out the Close method") +// }, +// SetInstanceIsPublishedFunc: func(ctx context.Context, instanceID string) error { +// panic("mock out the SetInstanceIsPublished method") +// }, +// } // -// // use mockedGraphDB in code that requires store.GraphDB -// // and then make assertions. +// // use mockedGraphDB in code that requires store.GraphDB +// // and then make assertions. // -// } +// } type GraphDBMock struct { // AddVersionDetailsToInstanceFunc mocks the AddVersionDetailsToInstance method. AddVersionDetailsToInstanceFunc func(ctx context.Context, instanceID string, datasetID string, edition string, version int) error // CheckerFunc mocks the Checker method. - CheckerFunc func(contextMoqParam context.Context, checkState *healthcheck.CheckState) error + CheckerFunc func(in1 context.Context, in2 *healthcheck.CheckState) error // CloseFunc mocks the Close method. CloseFunc func(ctx context.Context) error @@ -68,10 +68,10 @@ type GraphDBMock struct { } // Checker holds details about calls to the Checker method. Checker []struct { - // ContextMoqParam is the contextMoqParam argument value. - ContextMoqParam context.Context - // CheckState is the checkState argument value. - CheckState *healthcheck.CheckState + // In1 is the in1 argument value. + In1 context.Context + // In2 is the in2 argument value. + In2 *healthcheck.CheckState } // Close holds details about calls to the Close method. Close []struct { @@ -140,33 +140,33 @@ func (mock *GraphDBMock) AddVersionDetailsToInstanceCalls() []struct { } // Checker calls CheckerFunc. -func (mock *GraphDBMock) Checker(contextMoqParam context.Context, checkState *healthcheck.CheckState) error { +func (mock *GraphDBMock) Checker(in1 context.Context, in2 *healthcheck.CheckState) error { if mock.CheckerFunc == nil { panic("GraphDBMock.CheckerFunc: method is nil but GraphDB.Checker was just called") } callInfo := struct { - ContextMoqParam context.Context - CheckState *healthcheck.CheckState + In1 context.Context + In2 *healthcheck.CheckState }{ - ContextMoqParam: contextMoqParam, - CheckState: checkState, + In1: in1, + In2: in2, } mock.lockChecker.Lock() mock.calls.Checker = append(mock.calls.Checker, callInfo) mock.lockChecker.Unlock() - return mock.CheckerFunc(contextMoqParam, checkState) + return mock.CheckerFunc(in1, in2) } // CheckerCalls gets all the calls that were made to Checker. // Check the length with: // len(mockedGraphDB.CheckerCalls()) func (mock *GraphDBMock) CheckerCalls() []struct { - ContextMoqParam context.Context - CheckState *healthcheck.CheckState + In1 context.Context + In2 *healthcheck.CheckState } { var calls []struct { - ContextMoqParam context.Context - CheckState *healthcheck.CheckState + In1 context.Context + In2 *healthcheck.CheckState } mock.lockChecker.RLock() calls = mock.calls.Checker diff --git a/store/datastoretest/mongo.go b/store/datastoretest/mongo.go index f389b9f7..09b44855 100644 --- a/store/datastoretest/mongo.go +++ b/store/datastoretest/mongo.go @@ -18,124 +18,124 @@ var _ store.MongoDB = &MongoDBMock{} // MongoDBMock is a mock implementation of store.MongoDB. // -// func TestSomethingThatUsesMongoDB(t *testing.T) { +// func TestSomethingThatUsesMongoDB(t *testing.T) { // -// // make and configure a mocked store.MongoDB -// mockedMongoDB := &MongoDBMock{ -// AddDimensionToInstanceFunc: func(dimension *models.CachedDimensionOption) error { -// panic("mock out the AddDimensionToInstance method") -// }, -// AddEventToInstanceFunc: func(instanceID string, event *models.Event) error { -// panic("mock out the AddEventToInstance method") -// }, -// AddInstanceFunc: func(instance *models.Instance) (*models.Instance, error) { -// panic("mock out the AddInstance method") -// }, -// CheckDatasetExistsFunc: func(ID string, state string) error { -// panic("mock out the CheckDatasetExists method") -// }, -// CheckEditionExistsFunc: func(ID string, editionID string, state string) error { -// panic("mock out the CheckEditionExists method") -// }, -// CheckerFunc: func(contextMoqParam context.Context, checkState *healthcheck.CheckState) error { -// panic("mock out the Checker method") -// }, -// CloseFunc: func(contextMoqParam context.Context) error { -// panic("mock out the Close method") -// }, -// DeleteDatasetFunc: func(ID string) error { -// panic("mock out the DeleteDataset method") -// }, -// DeleteEditionFunc: func(ID string) error { -// panic("mock out the DeleteEdition method") -// }, -// GetDatasetFunc: func(ID string) (*models.DatasetUpdate, error) { -// panic("mock out the GetDataset method") -// }, -// GetDatasetsFunc: func(ctx context.Context, offset int, limit int, authorised bool) ([]*models.DatasetUpdate, int, error) { -// panic("mock out the GetDatasets method") -// }, -// GetDimensionOptionsFunc: func(version *models.Version, dimension string, offset int, limit int) ([]*models.PublicDimensionOption, int, error) { -// panic("mock out the GetDimensionOptions method") -// }, -// GetDimensionOptionsFromIDsFunc: func(version *models.Version, dimension string, ids []string) ([]*models.PublicDimensionOption, int, error) { -// panic("mock out the GetDimensionOptionsFromIDs method") -// }, -// GetDimensionsFunc: func(datasetID string, versionID string) ([]bson.M, error) { -// panic("mock out the GetDimensions method") -// }, -// GetDimensionsFromInstanceFunc: func(ID string) (*models.DimensionNodeResults, error) { -// panic("mock out the GetDimensionsFromInstance method") -// }, -// GetEditionFunc: func(ID string, editionID string, state string) (*models.EditionUpdate, error) { -// panic("mock out the GetEdition method") -// }, -// GetEditionsFunc: func(ctx context.Context, ID string, state string, offset int, limit int, authorised bool) ([]*models.EditionUpdate, int, error) { -// panic("mock out the GetEditions method") -// }, -// GetInstanceFunc: func(ID string) (*models.Instance, error) { -// panic("mock out the GetInstance method") -// }, -// GetInstancesFunc: func(ctx context.Context, states []string, datasets []string, offset int, limit int) ([]*models.Instance, int, error) { -// panic("mock out the GetInstances method") -// }, -// GetNextVersionFunc: func(datasetID string, editionID string) (int, error) { -// panic("mock out the GetNextVersion method") -// }, -// GetUniqueDimensionAndOptionsFunc: func(ID string, dimension string) (*models.DimensionValues, error) { -// panic("mock out the GetUniqueDimensionAndOptions method") -// }, -// GetVersionFunc: func(datasetID string, editionID string, version string, state string) (*models.Version, error) { -// panic("mock out the GetVersion method") -// }, -// GetVersionsFunc: func(ctx context.Context, datasetID string, editionID string, state string, offset int, limit int) ([]models.Version, int, error) { -// panic("mock out the GetVersions method") -// }, -// UpdateBuildHierarchyTaskStateFunc: func(id string, dimension string, state string) error { -// panic("mock out the UpdateBuildHierarchyTaskState method") -// }, -// UpdateBuildSearchTaskStateFunc: func(id string, dimension string, state string) error { -// panic("mock out the UpdateBuildSearchTaskState method") -// }, -// UpdateDatasetFunc: func(ctx context.Context, ID string, dataset *models.Dataset, currentState string) error { -// panic("mock out the UpdateDataset method") -// }, -// UpdateDatasetWithAssociationFunc: func(ID string, state string, version *models.Version) error { -// panic("mock out the UpdateDatasetWithAssociation method") -// }, -// UpdateDimensionNodeIDAndOrderFunc: func(dimension *models.DimensionOption) error { -// panic("mock out the UpdateDimensionNodeIDAndOrder method") -// }, -// UpdateImportObservationsTaskStateFunc: func(id string, state string) error { -// panic("mock out the UpdateImportObservationsTaskState method") -// }, -// UpdateInstanceFunc: func(ctx context.Context, ID string, instance *models.Instance) error { -// panic("mock out the UpdateInstance method") -// }, -// UpdateObservationInsertedFunc: func(ID string, observationInserted int64) error { -// panic("mock out the UpdateObservationInserted method") -// }, -// UpdateVersionFunc: func(ID string, version *models.Version) error { -// panic("mock out the UpdateVersion method") -// }, -// UpsertContactFunc: func(ID string, update interface{}) error { -// panic("mock out the UpsertContact method") -// }, -// UpsertDatasetFunc: func(ID string, datasetDoc *models.DatasetUpdate) error { -// panic("mock out the UpsertDataset method") -// }, -// UpsertEditionFunc: func(datasetID string, edition string, editionDoc *models.EditionUpdate) error { -// panic("mock out the UpsertEdition method") -// }, -// UpsertVersionFunc: func(ID string, versionDoc *models.Version) error { -// panic("mock out the UpsertVersion method") -// }, -// } +// // make and configure a mocked store.MongoDB +// mockedMongoDB := &MongoDBMock{ +// AddDimensionToInstanceFunc: func(dimension *models.CachedDimensionOption) error { +// panic("mock out the AddDimensionToInstance method") +// }, +// AddEventToInstanceFunc: func(instanceID string, event *models.Event) error { +// panic("mock out the AddEventToInstance method") +// }, +// AddInstanceFunc: func(instance *models.Instance) (*models.Instance, error) { +// panic("mock out the AddInstance method") +// }, +// CheckDatasetExistsFunc: func(ID string, state string) error { +// panic("mock out the CheckDatasetExists method") +// }, +// CheckEditionExistsFunc: func(ID string, editionID string, state string) error { +// panic("mock out the CheckEditionExists method") +// }, +// CheckerFunc: func(in1 context.Context, in2 *healthcheck.CheckState) error { +// panic("mock out the Checker method") +// }, +// CloseFunc: func(in1 context.Context) error { +// panic("mock out the Close method") +// }, +// DeleteDatasetFunc: func(ID string) error { +// panic("mock out the DeleteDataset method") +// }, +// DeleteEditionFunc: func(ID string) error { +// panic("mock out the DeleteEdition method") +// }, +// GetDatasetFunc: func(ID string) (*models.DatasetUpdate, error) { +// panic("mock out the GetDataset method") +// }, +// GetDatasetsFunc: func(ctx context.Context, offset int, limit int, authorised bool) ([]*models.DatasetUpdate, int, error) { +// panic("mock out the GetDatasets method") +// }, +// GetDimensionOptionsFunc: func(version *models.Version, dimension string, offset int, limit int) ([]*models.PublicDimensionOption, int, error) { +// panic("mock out the GetDimensionOptions method") +// }, +// GetDimensionOptionsFromIDsFunc: func(version *models.Version, dimension string, ids []string) ([]*models.PublicDimensionOption, int, error) { +// panic("mock out the GetDimensionOptionsFromIDs method") +// }, +// GetDimensionsFunc: func(datasetID string, versionID string) ([]bson.M, error) { +// panic("mock out the GetDimensions method") +// }, +// GetDimensionsFromInstanceFunc: func(ID string) (*models.DimensionNodeResults, error) { +// panic("mock out the GetDimensionsFromInstance method") +// }, +// GetEditionFunc: func(ID string, editionID string, state string) (*models.EditionUpdate, error) { +// panic("mock out the GetEdition method") +// }, +// GetEditionsFunc: func(ctx context.Context, ID string, state string, offset int, limit int, authorised bool) ([]*models.EditionUpdate, int, error) { +// panic("mock out the GetEditions method") +// }, +// GetInstanceFunc: func(ID string) (*models.Instance, error) { +// panic("mock out the GetInstance method") +// }, +// GetInstancesFunc: func(ctx context.Context, states []string, datasets []string, offset int, limit int) ([]*models.Instance, int, error) { +// panic("mock out the GetInstances method") +// }, +// GetNextVersionFunc: func(datasetID string, editionID string) (int, error) { +// panic("mock out the GetNextVersion method") +// }, +// GetUniqueDimensionAndOptionsFunc: func(ID string, dimension string) (*models.DimensionValues, error) { +// panic("mock out the GetUniqueDimensionAndOptions method") +// }, +// GetVersionFunc: func(datasetID string, editionID string, version int, state string) (*models.Version, error) { +// panic("mock out the GetVersion method") +// }, +// GetVersionsFunc: func(ctx context.Context, datasetID string, editionID string, state string, offset int, limit int) ([]models.Version, int, error) { +// panic("mock out the GetVersions method") +// }, +// UpdateBuildHierarchyTaskStateFunc: func(id string, dimension string, state string) error { +// panic("mock out the UpdateBuildHierarchyTaskState method") +// }, +// UpdateBuildSearchTaskStateFunc: func(id string, dimension string, state string) error { +// panic("mock out the UpdateBuildSearchTaskState method") +// }, +// UpdateDatasetFunc: func(ctx context.Context, ID string, dataset *models.Dataset, currentState string) error { +// panic("mock out the UpdateDataset method") +// }, +// UpdateDatasetWithAssociationFunc: func(ID string, state string, version *models.Version) error { +// panic("mock out the UpdateDatasetWithAssociation method") +// }, +// UpdateDimensionNodeIDAndOrderFunc: func(dimension *models.DimensionOption) error { +// panic("mock out the UpdateDimensionNodeIDAndOrder method") +// }, +// UpdateImportObservationsTaskStateFunc: func(id string, state string) error { +// panic("mock out the UpdateImportObservationsTaskState method") +// }, +// UpdateInstanceFunc: func(ctx context.Context, ID string, instance *models.Instance) error { +// panic("mock out the UpdateInstance method") +// }, +// UpdateObservationInsertedFunc: func(ID string, observationInserted int64) error { +// panic("mock out the UpdateObservationInserted method") +// }, +// UpdateVersionFunc: func(ID string, version *models.Version) error { +// panic("mock out the UpdateVersion method") +// }, +// UpsertContactFunc: func(ID string, update interface{}) error { +// panic("mock out the UpsertContact method") +// }, +// UpsertDatasetFunc: func(ID string, datasetDoc *models.DatasetUpdate) error { +// panic("mock out the UpsertDataset method") +// }, +// UpsertEditionFunc: func(datasetID string, edition string, editionDoc *models.EditionUpdate) error { +// panic("mock out the UpsertEdition method") +// }, +// UpsertVersionFunc: func(ID string, versionDoc *models.Version) error { +// panic("mock out the UpsertVersion method") +// }, +// } // -// // use mockedMongoDB in code that requires store.MongoDB -// // and then make assertions. +// // use mockedMongoDB in code that requires store.MongoDB +// // and then make assertions. // -// } +// } type MongoDBMock struct { // AddDimensionToInstanceFunc mocks the AddDimensionToInstance method. AddDimensionToInstanceFunc func(dimension *models.CachedDimensionOption) error @@ -153,10 +153,10 @@ type MongoDBMock struct { CheckEditionExistsFunc func(ID string, editionID string, state string) error // CheckerFunc mocks the Checker method. - CheckerFunc func(contextMoqParam context.Context, checkState *healthcheck.CheckState) error + CheckerFunc func(in1 context.Context, in2 *healthcheck.CheckState) error // CloseFunc mocks the Close method. - CloseFunc func(contextMoqParam context.Context) error + CloseFunc func(in1 context.Context) error // DeleteDatasetFunc mocks the DeleteDataset method. DeleteDatasetFunc func(ID string) error @@ -201,7 +201,7 @@ type MongoDBMock struct { GetUniqueDimensionAndOptionsFunc func(ID string, dimension string) (*models.DimensionValues, error) // GetVersionFunc mocks the GetVersion method. - GetVersionFunc func(datasetID string, editionID string, version string, state string) (*models.Version, error) + GetVersionFunc func(datasetID string, editionID string, version int, state string) (*models.Version, error) // GetVersionsFunc mocks the GetVersions method. GetVersionsFunc func(ctx context.Context, datasetID string, editionID string, state string, offset int, limit int) ([]models.Version, int, error) @@ -282,15 +282,15 @@ type MongoDBMock struct { } // Checker holds details about calls to the Checker method. Checker []struct { - // ContextMoqParam is the contextMoqParam argument value. - ContextMoqParam context.Context - // CheckState is the checkState argument value. - CheckState *healthcheck.CheckState + // In1 is the in1 argument value. + In1 context.Context + // In2 is the in2 argument value. + In2 *healthcheck.CheckState } // Close holds details about calls to the Close method. Close []struct { - // ContextMoqParam is the contextMoqParam argument value. - ContextMoqParam context.Context + // In1 is the in1 argument value. + In1 context.Context } // DeleteDataset holds details about calls to the DeleteDataset method. DeleteDataset []struct { @@ -413,7 +413,7 @@ type MongoDBMock struct { // EditionID is the editionID argument value. EditionID string // Version is the version argument value. - Version string + Version int // State is the state argument value. State string } @@ -746,33 +746,33 @@ func (mock *MongoDBMock) CheckEditionExistsCalls() []struct { } // Checker calls CheckerFunc. -func (mock *MongoDBMock) Checker(contextMoqParam context.Context, checkState *healthcheck.CheckState) error { +func (mock *MongoDBMock) Checker(in1 context.Context, in2 *healthcheck.CheckState) error { if mock.CheckerFunc == nil { panic("MongoDBMock.CheckerFunc: method is nil but MongoDB.Checker was just called") } callInfo := struct { - ContextMoqParam context.Context - CheckState *healthcheck.CheckState + In1 context.Context + In2 *healthcheck.CheckState }{ - ContextMoqParam: contextMoqParam, - CheckState: checkState, + In1: in1, + In2: in2, } mock.lockChecker.Lock() mock.calls.Checker = append(mock.calls.Checker, callInfo) mock.lockChecker.Unlock() - return mock.CheckerFunc(contextMoqParam, checkState) + return mock.CheckerFunc(in1, in2) } // CheckerCalls gets all the calls that were made to Checker. // Check the length with: // len(mockedMongoDB.CheckerCalls()) func (mock *MongoDBMock) CheckerCalls() []struct { - ContextMoqParam context.Context - CheckState *healthcheck.CheckState + In1 context.Context + In2 *healthcheck.CheckState } { var calls []struct { - ContextMoqParam context.Context - CheckState *healthcheck.CheckState + In1 context.Context + In2 *healthcheck.CheckState } mock.lockChecker.RLock() calls = mock.calls.Checker @@ -781,29 +781,29 @@ func (mock *MongoDBMock) CheckerCalls() []struct { } // Close calls CloseFunc. -func (mock *MongoDBMock) Close(contextMoqParam context.Context) error { +func (mock *MongoDBMock) Close(in1 context.Context) error { if mock.CloseFunc == nil { panic("MongoDBMock.CloseFunc: method is nil but MongoDB.Close was just called") } callInfo := struct { - ContextMoqParam context.Context + In1 context.Context }{ - ContextMoqParam: contextMoqParam, + In1: in1, } mock.lockClose.Lock() mock.calls.Close = append(mock.calls.Close, callInfo) mock.lockClose.Unlock() - return mock.CloseFunc(contextMoqParam) + return mock.CloseFunc(in1) } // CloseCalls gets all the calls that were made to Close. // Check the length with: // len(mockedMongoDB.CloseCalls()) func (mock *MongoDBMock) CloseCalls() []struct { - ContextMoqParam context.Context + In1 context.Context } { var calls []struct { - ContextMoqParam context.Context + In1 context.Context } mock.lockClose.RLock() calls = mock.calls.Close @@ -1334,14 +1334,14 @@ func (mock *MongoDBMock) GetUniqueDimensionAndOptionsCalls() []struct { } // GetVersion calls GetVersionFunc. -func (mock *MongoDBMock) GetVersion(datasetID string, editionID string, version string, state string) (*models.Version, error) { +func (mock *MongoDBMock) GetVersion(datasetID string, editionID string, version int, state string) (*models.Version, error) { if mock.GetVersionFunc == nil { panic("MongoDBMock.GetVersionFunc: method is nil but MongoDB.GetVersion was just called") } callInfo := struct { DatasetID string EditionID string - Version string + Version int State string }{ DatasetID: datasetID, @@ -1361,13 +1361,13 @@ func (mock *MongoDBMock) GetVersion(datasetID string, editionID string, version func (mock *MongoDBMock) GetVersionCalls() []struct { DatasetID string EditionID string - Version string + Version int State string } { var calls []struct { DatasetID string EditionID string - Version string + Version int State string } mock.lockGetVersion.RLock()