diff --git a/api/api.go b/api/api.go index 4ba7a19c..6e24f042 100644 --- a/api/api.go +++ b/api/api.go @@ -13,6 +13,7 @@ import ( "github.com/ONSdigital/dp-dataset-api/application" "github.com/ONSdigital/dp-dataset-api/config" "github.com/ONSdigital/dp-dataset-api/dimension" + "github.com/ONSdigital/dp-dataset-api/download" "github.com/ONSdigital/dp-dataset-api/instance" "github.com/ONSdigital/dp-dataset-api/models" "github.com/ONSdigital/dp-dataset-api/pagination" @@ -62,53 +63,59 @@ type DownloadsGenerator interface { Generate(ctx context.Context, datasetID, instanceID, edition, version string) error } +type SearchContentUpdatedProducer struct { + Producer download.KafkaProducer +} + // DatasetAPI manages importing filters against a dataset type DatasetAPI struct { - Router *mux.Router - dataStore store.DataStore - urlBuilder *url.Builder - enableURLRewriting bool - host string - downloadServiceToken string - EnablePrePublishView bool - downloadGenerators map[models.DatasetType]DownloadsGenerator - enablePrivateEndpoints bool - enableDetachDataset bool - enableDeleteStaticVersion bool - authMiddleware auth.Middleware - instancePublishedChecker *instance.PublishCheck - versionPublishedChecker *PublishCheck - MaxRequestOptions int - defaultLimit int - smDatasetAPI *application.StateMachineDatasetAPI - filesAPIClient filesAPISDK.Clienter - authToken string - permissionsChecker auth.PermissionsChecker - idClient *clientsidentity.Client + Router *mux.Router + dataStore store.DataStore + urlBuilder *url.Builder + enableURLRewriting bool + host string + downloadServiceToken string + EnablePrePublishView bool + downloadGenerators map[models.DatasetType]DownloadsGenerator + enablePrivateEndpoints bool + enableDetachDataset bool + enableDeleteStaticVersion bool + authMiddleware auth.Middleware + instancePublishedChecker *instance.PublishCheck + versionPublishedChecker *PublishCheck + MaxRequestOptions int + defaultLimit int + smDatasetAPI *application.StateMachineDatasetAPI + filesAPIClient filesAPISDK.Clienter + authToken string + permissionsChecker auth.PermissionsChecker + idClient *clientsidentity.Client + searchContentUpdatedProducer *SearchContentUpdatedProducer } // Setup creates a new Dataset API instance and register the API routes based on the application configuration. -func Setup(ctx context.Context, cfg *config.Configuration, router *mux.Router, dataStore store.DataStore, urlBuilder *url.Builder, downloadGenerators map[models.DatasetType]DownloadsGenerator, authMiddleware auth.Middleware, enableURLRewriting bool, smDatasetAPI *application.StateMachineDatasetAPI, permissionsChecker auth.PermissionsChecker, idClient *clientsidentity.Client) *DatasetAPI { +func Setup(ctx context.Context, cfg *config.Configuration, router *mux.Router, dataStore store.DataStore, urlBuilder *url.Builder, downloadGenerators map[models.DatasetType]DownloadsGenerator, authMiddleware auth.Middleware, enableURLRewriting bool, smDatasetAPI *application.StateMachineDatasetAPI, permissionsChecker auth.PermissionsChecker, idClient *clientsidentity.Client, searchContentUpdatedProducer *SearchContentUpdatedProducer) *DatasetAPI { api := &DatasetAPI{ - dataStore: dataStore, - host: cfg.DatasetAPIURL, - downloadServiceToken: cfg.DownloadServiceSecretKey, - EnablePrePublishView: cfg.EnablePrivateEndpoints, - Router: router, - urlBuilder: urlBuilder, - enableURLRewriting: enableURLRewriting, - downloadGenerators: downloadGenerators, - enablePrivateEndpoints: cfg.EnablePrivateEndpoints, - enableDetachDataset: cfg.EnableDetachDataset, - enableDeleteStaticVersion: cfg.EnableDeleteStaticVersion, - authMiddleware: authMiddleware, - versionPublishedChecker: nil, - instancePublishedChecker: nil, - MaxRequestOptions: cfg.MaxRequestOptions, - defaultLimit: cfg.DefaultLimit, - smDatasetAPI: smDatasetAPI, - permissionsChecker: permissionsChecker, - idClient: idClient, + dataStore: dataStore, + host: cfg.DatasetAPIURL, + downloadServiceToken: cfg.DownloadServiceSecretKey, + EnablePrePublishView: cfg.EnablePrivateEndpoints, + Router: router, + urlBuilder: urlBuilder, + enableURLRewriting: enableURLRewriting, + downloadGenerators: downloadGenerators, + enablePrivateEndpoints: cfg.EnablePrivateEndpoints, + enableDetachDataset: cfg.EnableDetachDataset, + enableDeleteStaticVersion: cfg.EnableDeleteStaticVersion, + authMiddleware: authMiddleware, + versionPublishedChecker: nil, + instancePublishedChecker: nil, + MaxRequestOptions: cfg.MaxRequestOptions, + defaultLimit: cfg.DefaultLimit, + smDatasetAPI: smDatasetAPI, + permissionsChecker: permissionsChecker, + idClient: idClient, + searchContentUpdatedProducer: searchContentUpdatedProducer, } paginator := pagination.NewPaginator(cfg.DefaultLimit, cfg.DefaultOffset, cfg.DefaultMaxLimit) diff --git a/api/dataset_test.go b/api/dataset_test.go index c7a2e53e..519fb7fe 100644 --- a/api/dataset_test.go +++ b/api/dataset_test.go @@ -25,6 +25,7 @@ import ( storetest "github.com/ONSdigital/dp-dataset-api/store/datastoretest" "github.com/ONSdigital/dp-dataset-api/url" filesAPISDKMocks "github.com/ONSdigital/dp-files-api/sdk/mocks" + kafka "github.com/ONSdigital/dp-kafka/v4" dprequest "github.com/ONSdigital/dp-net/v3/request" "github.com/gorilla/mux" @@ -61,8 +62,18 @@ var ( mu sync.Mutex ) +func getSearchContentUpdatedMock() *mocks.KafkaProducerMock { + producerMock := &mocks.KafkaProducerMock{ + OutputFunc: func() chan kafka.BytesMessage { + return make(chan kafka.BytesMessage, 1) + }, + } + + return producerMock +} + // GetAPIWithCMDMocks also used in other tests, so exported -func GetAPIWithCMDMocks(mockedDataStore store.Storer, mockedGeneratedDownloads DownloadsGenerator, authorisationMock *authMock.MiddlewareMock) *DatasetAPI { +func GetAPIWithCMDMocks(mockedDataStore store.Storer, mockedGeneratedDownloads DownloadsGenerator, authorisationMock *authMock.MiddlewareMock, searchContentUpdated SearchContentUpdatedProducer) *DatasetAPI { mu.Lock() defer mu.Unlock() cfg, err := config.Get() @@ -171,7 +182,7 @@ func GetAPIWithCMDMocks(mockedDataStore store.Storer, mockedGeneratedDownloads D }, } - return Setup(testContext, cfg, mux.NewRouter(), store.DataStore{Backend: mockedDataStore}, urlBuilder, mockedMapGeneratedDownloads, authorisationMock, enableURLRewriting, &mockStatemachineDatasetAPI, permissionsChecker, testIdentityClient) + return Setup(testContext, cfg, mux.NewRouter(), store.DataStore{Backend: mockedDataStore}, urlBuilder, mockedMapGeneratedDownloads, authorisationMock, enableURLRewriting, &mockStatemachineDatasetAPI, permissionsChecker, testIdentityClient, &searchContentUpdated) } // GetAPIWithCMDMocks also used in other tests, so exported @@ -231,7 +242,7 @@ func GetAPIWithCantabularMocks(mockedDataStore store.Storer, mockedGeneratedDown permissionsChecker := &authMock.PermissionsCheckerMock{} - return Setup(testContext, cfg, mux.NewRouter(), store.DataStore{Backend: mockedDataStore}, urlBuilder, mockedMapGeneratedDownloads, authorisationMock, enableURLRewriting, &mockStatemachineDatasetAPI, permissionsChecker, testIdentityClient) + return Setup(testContext, cfg, mux.NewRouter(), store.DataStore{Backend: mockedDataStore}, urlBuilder, mockedMapGeneratedDownloads, authorisationMock, enableURLRewriting, &mockStatemachineDatasetAPI, permissionsChecker, testIdentityClient, nil) } func createRequestWithAuth(method, target string, body io.Reader) *http.Request { @@ -265,7 +276,7 @@ func TestGetDatasetsUnauthorised(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusUnauthorized) @@ -290,7 +301,7 @@ func TestGetDatasetsForbidden(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusForbidden) @@ -323,7 +334,7 @@ func TestGetDatasetsReturnsOK(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) actualResponse, actualTotalCount, err := api.getDatasets(w, r, 11, 12) @@ -355,7 +366,7 @@ func TestGetDatasetsReturnsOK(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) actualResponse, actualTotalCount, err := api.getDatasets(w, r, 11, 12) @@ -387,7 +398,7 @@ func TestGetDatasetsReturnsOK(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) actualResponse, actualTotalCount, err := api.getDatasets(w, r, 11, 12) So(actualResponse, ShouldResemble, []*models.Dataset{{ID: "123-456", Type: "static", IsBasedOn: &models.IsBasedOn{ID: "Example"}}}) @@ -424,7 +435,7 @@ func TestGetDatasetsReturnsOK(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) actualResponse, actualTotalCount, err := api.getDatasets(w, r, 10, 0) @@ -464,7 +475,7 @@ func TestGetDatasetsReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) actualResponse, actualTotalCount, err := api.getDatasets(w, r, 6, 7) assertInternalServerErr(w) @@ -497,7 +508,7 @@ func TestGetDatasetsReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) actualResponse, actualTotalCount, err := api.getDatasets(w, r, 6, 7) So(len(mockedDataStore.GetDatasetsCalls()), ShouldEqual, 0) @@ -526,7 +537,7 @@ func TestGetDatasetsReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) actualResponse, actualTotalCount, err := api.getDatasets(w, r, 6, 7) So(len(mockedDataStore.GetDatasetsCalls()), ShouldEqual, 0) @@ -559,7 +570,7 @@ func TestGetDatasetsReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) actualResponse, actualTotalCount, err := api.getDatasets(w, r, 6, 7) So(len(mockedDataStore.GetDatasetsByQueryParamsCalls()), ShouldEqual, 1) @@ -586,7 +597,7 @@ func TestGetDatasetUnauthorised(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusUnauthorized) @@ -609,7 +620,7 @@ func TestGetDatasetForbidden(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusForbidden) @@ -637,7 +648,7 @@ func TestGetDatasetReturnsOK(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusOK) @@ -663,7 +674,7 @@ func TestGetDatasetReturnsOK(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusOK) @@ -688,7 +699,7 @@ func TestGetDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) assertInternalServerErr(w) @@ -713,7 +724,7 @@ func TestGetDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -740,7 +751,7 @@ func TestGetDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -770,7 +781,7 @@ func TestGetDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -804,7 +815,7 @@ func TestGetDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -838,7 +849,7 @@ func TestGetDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -872,7 +883,7 @@ func TestGetDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -906,7 +917,7 @@ func TestGetDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -940,7 +951,7 @@ func TestGetDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -974,7 +985,7 @@ func TestGetDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -1005,7 +1016,7 @@ func TestPostDatasetsReturnsCreated(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusCreated) @@ -1039,7 +1050,7 @@ func TestPostDatasetsReturnsCreated(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusCreated) @@ -1073,7 +1084,7 @@ func TestPostDatasetsReturnsCreated(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusCreated) @@ -1107,7 +1118,7 @@ func TestPostDatasetsReturnsCreated(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusCreated) @@ -1141,7 +1152,7 @@ func TestPostDatasetsReturnsCreated(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusCreated) @@ -1175,7 +1186,7 @@ func TestPostDatasetsReturnsCreated(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusCreated) @@ -1211,7 +1222,7 @@ func TestPostDatasetsReturnsCreated(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusCreated) @@ -1246,7 +1257,7 @@ func TestPostDatasetsReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusConflict) @@ -1280,7 +1291,7 @@ func TestPostDatasetsReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusInternalServerError) @@ -1317,7 +1328,7 @@ func TestPostDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -1351,7 +1362,7 @@ func TestPostDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) assertInternalServerErr(w) @@ -1378,7 +1389,7 @@ func TestPostDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusUnauthorized) @@ -1400,7 +1411,7 @@ func TestPostDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusForbidden) @@ -1432,7 +1443,7 @@ func TestPostDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusConflict) @@ -1467,7 +1478,7 @@ func TestPostDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Body.String(), ShouldResemble, "invalid fields: [QMI]\n") @@ -1502,7 +1513,7 @@ func TestPostDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Body.String(), ShouldResemble, "invalid fields: [QMI]\n") @@ -1537,7 +1548,7 @@ func TestPostDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Body.String(), ShouldResemble, "invalid fields: [QMI]\n") @@ -1572,7 +1583,7 @@ func TestPostDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -1610,7 +1621,7 @@ func TestPostDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusCreated) @@ -1649,7 +1660,7 @@ func TestPutDatasetReturnsSuccessfully(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusOK) @@ -1697,7 +1708,7 @@ func TestPutDatasetReturnsSuccessfully(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusOK) @@ -1747,7 +1758,7 @@ func TestPutDatasetReturnsSuccessfully(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusOK) @@ -1782,7 +1793,7 @@ func TestPutDatasetReturnsSuccessfully(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusOK) @@ -1817,7 +1828,7 @@ func TestPutDatasetReturnsSuccessfully(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusOK) @@ -1852,7 +1863,7 @@ func TestPutDatasetReturnsSuccessfully(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusOK) @@ -1887,7 +1898,7 @@ func TestPutDatasetReturnsSuccessfully(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusOK) @@ -1922,7 +1933,7 @@ func TestPutDatasetReturnsSuccessfully(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusOK) @@ -1959,7 +1970,7 @@ func TestPutDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -1994,7 +2005,7 @@ func TestPutDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusInternalServerError) @@ -2029,7 +2040,7 @@ func TestPutDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -2066,7 +2077,7 @@ func TestPutDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -2102,7 +2113,7 @@ func TestPutDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -2138,7 +2149,7 @@ func TestPutDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -2168,7 +2179,7 @@ func TestPutDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusUnauthorized) @@ -2193,7 +2204,7 @@ func TestPutDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusForbidden) @@ -2222,7 +2233,7 @@ func TestPutDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusConflict) @@ -2257,7 +2268,7 @@ func TestPutDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusInternalServerError) @@ -2296,7 +2307,7 @@ func TestDeleteDatasetReturnsSuccessfully(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNoContent) @@ -2332,7 +2343,7 @@ func TestDeleteDatasetReturnsSuccessfully(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNoContent) @@ -2407,7 +2418,7 @@ func TestDeleteDatasetReturnsSuccessfully(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.filesAPIClient = &mockFilesAPIClient api.Router.ServeHTTP(w, r) @@ -2449,7 +2460,7 @@ func TestDeleteDatasetReturnsSuccessfully(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -2483,7 +2494,7 @@ func TestDeleteDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusForbidden) @@ -2519,7 +2530,7 @@ func TestDeleteDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) assertInternalServerErr(w) @@ -2552,7 +2563,7 @@ func TestDeleteDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNoContent) @@ -2585,7 +2596,7 @@ func TestDeleteDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) assertInternalServerErr(w) @@ -2610,7 +2621,7 @@ func TestDeleteDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusUnauthorized) @@ -2636,7 +2647,7 @@ func TestDeleteDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusForbidden) @@ -2692,7 +2703,7 @@ func TestDeleteDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) assertInternalServerErr(w) @@ -2747,7 +2758,7 @@ func TestDeleteDatasetReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.filesAPIClient = &mockFilesAPIClient api.Router.ServeHTTP(w, r) diff --git a/api/dimensions_test.go b/api/dimensions_test.go index d9740614..5b41d0bc 100644 --- a/api/dimensions_test.go +++ b/api/dimensions_test.go @@ -19,7 +19,7 @@ import ( ) func initAPIWithMockedStore(mockedStore *storetest.StorerMock, authorisationMock *authMock.MiddlewareMock) *DatasetAPI { - return GetAPIWithCMDMocks(mockedStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + return GetAPIWithCMDMocks(mockedStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) } func TestGetDimensionsForbidden(t *testing.T) { @@ -38,7 +38,7 @@ func TestGetDimensionsForbidden(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusForbidden) @@ -63,7 +63,7 @@ func TestGetDimensionsUnauthorised(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusUnauthorized) @@ -96,7 +96,7 @@ func TestGetDimensionsReturnsOk(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusOK) diff --git a/api/editions_test.go b/api/editions_test.go index 092706a9..53a40085 100644 --- a/api/editions_test.go +++ b/api/editions_test.go @@ -59,7 +59,7 @@ func TestGetEditionsForbidden(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusForbidden) @@ -83,7 +83,7 @@ func TestGetEditionsUnauthorised(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusUnauthorized) @@ -121,7 +121,7 @@ func TestGetEditionsReturnsOK(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) list, totalCount, err := api.getEditions(w, r, 20, 0) So(w.Code, ShouldEqual, http.StatusOK) @@ -321,7 +321,7 @@ func TestGetEditionsReturnsOK(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) _, totalCount, _ := api.getEditions(w, r, 20, 0) editions, err := utils.MapVersionsToEditionUpdate(publishedLatestVersion, nil) @@ -549,7 +549,7 @@ func TestGetEditionsReturnsOK(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) _, totalCount, _ := api.getEditions(w, r, 20, 0) editions, err := utils.MapVersionsToEditionUpdate(publishedLatestVersion, unpublishedLatestVersion) @@ -586,7 +586,7 @@ func TestGetEditionsReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusInternalServerError) @@ -617,7 +617,7 @@ func TestGetEditionsReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -651,7 +651,7 @@ func TestGetEditionsReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -684,7 +684,7 @@ func TestGetEditionsReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -717,7 +717,7 @@ func TestGetEditionsReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -742,7 +742,7 @@ func TestGetEditionForbidden(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusForbidden) @@ -767,7 +767,7 @@ func TestGetEditionUnauthorised(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusUnauthorized) @@ -800,7 +800,7 @@ func TestGetEditionReturnsOK(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusOK) @@ -830,7 +830,7 @@ func TestGetEditionReturnsOK(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusOK) @@ -860,7 +860,7 @@ func TestGetEditionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusInternalServerError) @@ -889,7 +889,7 @@ func TestGetEditionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -921,7 +921,7 @@ func TestGetEditionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -952,7 +952,7 @@ func TestGetEditionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -983,7 +983,7 @@ func TestGetEditionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) diff --git a/api/metadata_test.go b/api/metadata_test.go index f81aeab4..ca6d0723 100644 --- a/api/metadata_test.go +++ b/api/metadata_test.go @@ -34,7 +34,7 @@ func TestPutMetadataForbidden(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) w := httptest.NewRecorder() @@ -83,7 +83,7 @@ func TestPutMetadataUnauthorised(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) w := httptest.NewRecorder() @@ -164,7 +164,7 @@ func TestPutMetadata(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) edition := version.Edition versionNo := strconv.Itoa(version.Version) @@ -396,7 +396,7 @@ func TestGetMetadataForbidden(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) Convey("Then a 403 response is returned and no expected database calls are made", func() { So(w.Code, ShouldEqual, http.StatusForbidden) @@ -424,7 +424,7 @@ func TestGetMetadataUnauthorised(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) Convey("Then a 401 response is returned and no expected database calls are made", func() { So(w.Code, ShouldEqual, http.StatusUnauthorized) @@ -467,7 +467,7 @@ func TestGetMetadataReturnsOk(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusOK) @@ -532,7 +532,7 @@ func TestGetMetadataReturnsOk(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusOK) @@ -599,7 +599,7 @@ func TestGetMetadataReturnsOk(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusOK) @@ -662,7 +662,7 @@ func TestGetMetadataReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusInternalServerError) @@ -695,7 +695,7 @@ func TestGetMetadataReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -734,7 +734,7 @@ func TestGetMetadataReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -772,7 +772,7 @@ func TestGetMetadataReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusInternalServerError) @@ -810,7 +810,7 @@ func TestGetMetadataReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -843,7 +843,7 @@ func TestGetMetadataReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -882,7 +882,7 @@ func TestGetMetadataReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) assertInternalServerErr(w) @@ -908,7 +908,7 @@ func TestGetMetadataReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -935,7 +935,7 @@ func TestGetMetadataReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -962,7 +962,7 @@ func TestGetMetadataReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -1004,7 +1004,7 @@ func TestGetMetadataReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -1049,7 +1049,7 @@ func TestGetMetadataReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) diff --git a/api/static_versions_test.go b/api/static_versions_test.go index b8d1cd63..d7920585 100644 --- a/api/static_versions_test.go +++ b/api/static_versions_test.go @@ -34,7 +34,7 @@ func TestGetDatasetEditionsForbidden(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) Convey("When getDatasetEditions is called", func() { api.Router.ServeHTTP(w, r) @@ -64,7 +64,7 @@ func TestGetDatasetEditionsUnauthorised(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) Convey("When getDatasetEditions is called", func() { api.Router.ServeHTTP(w, r) @@ -135,7 +135,7 @@ func TestGetDatasetEditions_WithQueryParam_Success(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) Convey("When getDatasetEditions is called", func() { results, totalCount, err := api.getDatasetEditions(w, r, 20, 0) @@ -218,7 +218,7 @@ func TestGetDatasetEditions_WithPublishedParam(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) Convey("When getDatasetEditions is called", func() { results, totalCount, err := api.getDatasetEditions(w, r, 20, 0) @@ -263,7 +263,7 @@ func TestGetDatasetEditions_WithPublishedParam(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) Convey("When getDatasetEditions is called", func() { results, totalCount, err := api.getDatasetEditions(w, r, 20, 0) @@ -289,7 +289,7 @@ func TestGetDatasetEditions_WithPublishedParam(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) Convey("When getDatasetEditions is called", func() { results, totalCount, err := api.getDatasetEditions(w, r, 20, 0) @@ -377,7 +377,7 @@ func TestGetDatasetEditions_WithoutQueryParam_Success(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) Convey("When getDatasetEditions is called", func() { results, totalCount, err := api.getDatasetEditions(w, r, 20, 0) @@ -451,7 +451,7 @@ func TestGetDatasetEditions_InvalidQueryParam_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) Convey("When getDatasetEditions is called", func() { results, totalCount, err := api.getDatasetEditions(w, r, 20, 0) @@ -484,7 +484,7 @@ func TestGetDatasetEditions_GetStaticVersionsByState_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) Convey("When getDatasetEditions is called and no versions are found", func() { r := createRequestWithAuth("GET", "http://localhost:22000/dataset-editions?state=associated", http.NoBody) @@ -537,7 +537,7 @@ func TestGetDatasetEditions_GetDataset_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) Convey("When getDatasetEditions is called and the dataset is not found", func() { r := createRequestWithAuth("GET", "http://localhost:22000/dataset-editions", http.NoBody) @@ -574,7 +574,7 @@ func TestGetDatasetEditions_GetDataset_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) Convey("When getDatasetEditions is called and the datastore fails", func() { r := createRequestWithAuth("GET", "http://localhost:22000/dataset-editions", http.NoBody) @@ -654,7 +654,7 @@ func TestAddDatasetVersionCondensed_Success(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) successResponse, errorResponse := api.addDatasetVersionCondensed(w, r) So(successResponse.Status, ShouldEqual, http.StatusCreated) @@ -733,7 +733,7 @@ func TestAddDatasetVersionCondensed_Success(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) successResponse, errorResponse := api.addDatasetVersionCondensed(w, r) So(successResponse.Status, ShouldEqual, http.StatusCreated) @@ -793,7 +793,7 @@ func TestAddDatasetVersionCondensed_Success(t *testing.T) { } api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, - authorisationMock) + authorisationMock, SearchContentUpdatedProducer{}) success, failure := api.addDatasetVersionCondensed(w, r) @@ -841,7 +841,7 @@ func TestAddDatasetVersionCondensed_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) successResponse, errorResponse := api.addDatasetVersionCondensed(w, r) castErr := errorResponse.Errors[0] @@ -893,7 +893,7 @@ func TestAddDatasetVersionCondensed_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) successResponse, errorResponse := api.addDatasetVersionCondensed(w, r) So(successResponse.Status, ShouldEqual, http.StatusCreated) @@ -932,7 +932,7 @@ func TestAddDatasetVersionCondensed_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) successResponse, errorResponse := api.addDatasetVersionCondensed(w, r) So(errorResponse.Status, ShouldEqual, http.StatusInternalServerError) @@ -1023,7 +1023,7 @@ func TestAddDatasetVersionCondensed_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) successResponse, errorResponse := api.addDatasetVersionCondensed(w, r) So(errorResponse.Status, ShouldEqual, http.StatusNotFound) @@ -1128,7 +1128,7 @@ func TestAddDatasetVersionCondensed_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) successResponse, errorResponse := api.addDatasetVersionCondensed(w, r) @@ -1178,7 +1178,7 @@ func TestAddDatasetVersionCondensed_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) successResponse, errorResponse := api.addDatasetVersionCondensed(w, r) So(errorResponse.Status, ShouldEqual, http.StatusConflict) @@ -1225,7 +1225,7 @@ func TestAddDatasetVersionCondensed_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) successResponse, errorResponse := api.addDatasetVersionCondensed(w, r) So(errorResponse.Status, ShouldEqual, http.StatusBadRequest) @@ -1296,7 +1296,7 @@ func TestAddDatasetVersionCondensed_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) successResponse, errorResponse := api.addDatasetVersionCondensed(w, r) So(errorResponse.Status, ShouldEqual, http.StatusBadRequest) @@ -1335,6 +1335,7 @@ func TestAddDatasetVersionCondensed_Failure(t *testing.T) { }, &mocks.DownloadsGeneratorMock{}, authorisationMock, + SearchContentUpdatedProducer{}, ) success, errResp := api.addDatasetVersionCondensed(w, r) @@ -1374,6 +1375,7 @@ func TestAddDatasetVersionCondensed_Failure(t *testing.T) { }, &mocks.DownloadsGeneratorMock{}, authorisationMock, + SearchContentUpdatedProducer{}, ) success, errResp := api.addDatasetVersionCondensed(w, r) @@ -1523,7 +1525,7 @@ func TestCreateVersion_Success(t *testing.T) { returnedVersionJSON, err := json.Marshal(expectedVersion) So(err, ShouldBeNil) - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) r := createRequestWithAuth("POST", "http://localhost:22000/datasets/123/editions/edition1/versions/1", bytes.NewBuffer(validVersionJSON)) vars := map[string]string{ "dataset_id": "123", @@ -1604,7 +1606,7 @@ func TestCreateVersion_Failure(t *testing.T) { } Convey("When the JSON body provided is invalid", t, func() { - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) r := createRequestWithAuth("POST", "http://localhost:22000/datasets/123/editions/edition1/versions/invalid", http.NoBody) vars := map[string]string{ "dataset_id": "123", @@ -1636,7 +1638,7 @@ func TestCreateVersion_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) r := createRequestWithAuth("POST", "http://localhost:22000/datasets/123/editions/edition1/versions/invalid", bytes.NewBuffer(validVersionJSON)) vars := map[string]string{ "dataset_id": "123", @@ -1671,7 +1673,7 @@ func TestCreateVersion_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) r := createRequestWithAuth("POST", "http://localhost:22000/datasets/123/editions/edition1/versions/1", bytes.NewBuffer(invalidTypeVersionJSON)) vars := map[string]string{ "dataset_id": "123", @@ -1707,7 +1709,7 @@ func TestCreateVersion_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) r := createRequestWithAuth("POST", "http://localhost:22000/datasets/123/editions/edition1/versions/100", bytes.NewBuffer(invalidVersionJSON)) vars := map[string]string{ "dataset_id": "123", @@ -1745,7 +1747,7 @@ func TestCreateVersion_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) r := createRequestWithAuth("POST", "http://localhost:22000/datasets/123/editions/edition1/versions/1", bytes.NewBuffer(validVersionJSON)) vars := map[string]string{ "dataset_id": "123", @@ -1777,7 +1779,7 @@ func TestCreateVersion_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) r := createRequestWithAuth("POST", "http://localhost:22000/datasets/123/editions/edition1/versions/1", bytes.NewBuffer(validVersionJSON)) vars := map[string]string{ "dataset_id": "123", @@ -1812,7 +1814,7 @@ func TestCreateVersion_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) r := createRequestWithAuth("POST", "http://localhost:22000/datasets/123/editions/edition1/versions/1", bytes.NewBuffer(validVersionJSON)) vars := map[string]string{ "dataset_id": "123", @@ -1847,7 +1849,7 @@ func TestCreateVersion_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) r := createRequestWithAuth("POST", "http://localhost:22000/datasets/123/editions/edition1/versions/1", bytes.NewBuffer(validVersionJSON)) vars := map[string]string{ "dataset_id": "123", @@ -1885,7 +1887,7 @@ func TestCreateVersion_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) r := createRequestWithAuth("POST", "http://localhost:22000/datasets/123/editions/edition1/versions/1", bytes.NewBuffer(validVersionJSON)) vars := map[string]string{ "dataset_id": "123", @@ -1923,7 +1925,7 @@ func TestCreateVersion_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) r := createRequestWithAuth("POST", "http://localhost:22000/datasets/123/editions/edition1/versions/1", bytes.NewBuffer(validVersionJSON)) vars := map[string]string{ "dataset_id": "123", @@ -1964,7 +1966,7 @@ func TestCreateVersion_Failure(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) r := createRequestWithAuth("POST", "http://localhost:22000/datasets/123/editions/edition1/versions/1", bytes.NewBuffer(validVersionJSON)) vars := map[string]string{ "dataset_id": "123", @@ -2011,7 +2013,7 @@ func TestCreateVersion_Failure(t *testing.T) { } api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, - authorisationMock) + authorisationMock, SearchContentUpdatedProducer{}) r := createRequestWithAuth( "POST", @@ -2080,7 +2082,7 @@ func TestCreateVersion_Failure(t *testing.T) { } api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, - authorisationMock) + authorisationMock, SearchContentUpdatedProducer{}) success, errResp := api.createVersion(w, r) diff --git a/api/versions.go b/api/versions.go index aeebcd81..eb9641b0 100644 --- a/api/versions.go +++ b/api/versions.go @@ -15,6 +15,7 @@ import ( errs "github.com/ONSdigital/dp-dataset-api/apierrors" "github.com/ONSdigital/dp-dataset-api/models" "github.com/ONSdigital/dp-dataset-api/utils" + kafka "github.com/ONSdigital/dp-kafka/v4" dpresponse "github.com/ONSdigital/dp-net/v3/handlers/response" dphttp "github.com/ONSdigital/dp-net/v3/http" "github.com/ONSdigital/dp-net/v3/links" @@ -867,6 +868,29 @@ func (api *DatasetAPI) putState(w http.ResponseWriter, r *http.Request) { } } + if updatedVersion.State == models.PublishedState { + searchContentUpdatedEvent := map[string]interface{}{ + "dataset_id": updatedVersion.DatasetID, + "uri": updatedVersion.Links.Version.HRef, + "title": updatedVersion.EditionTitle, + "edition": updatedVersion.Edition, + "content_type": updatedVersion.Type, + } + + jsonBytes, err := json.Marshal(searchContentUpdatedEvent) + logData["search_content_updated_event"] = searchContentUpdatedEvent + if err != nil { + log.Error(ctx, "failed to marshal searchContentUpdatedEvent for kafka", err, logData) + handleVersionAPIErr(ctx, err, w, logData) + return + } else { + go func() { + api.searchContentUpdatedProducer.Producer.Output() <- kafka.BytesMessage{Value: jsonBytes, Context: ctx} + }() + log.Info(ctx, "putState endpoint: queued search content update for kafka", logData) + } + } + setJSONContentType(w) w.WriteHeader(http.StatusOK) log.Info(ctx, "putState endpoint: request successful", logData) diff --git a/api/versions_test.go b/api/versions_test.go index 84810c77..b9332c0a 100644 --- a/api/versions_test.go +++ b/api/versions_test.go @@ -65,7 +65,7 @@ func TestGetVersionsReturnsForbidden(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) Convey("Then a 403 response is received and no database calls are made", func() { So(w.Code, ShouldEqual, http.StatusForbidden) @@ -93,7 +93,7 @@ func TestGetVersionsReturnsUnauthorised(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) Convey("Then a 401 response is received and no database calls are made", func() { So(w.Code, ShouldEqual, http.StatusUnauthorized) @@ -139,7 +139,7 @@ func TestGetVersionsReturnsOK(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) list, totalCount, err := api.getVersions(w, r, 20, 0) So(w.Code, ShouldEqual, http.StatusOK) @@ -182,7 +182,7 @@ func TestGetVersionsReturnsOK(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) list, totalCount, err := api.getVersions(w, r, 20, 0) So(w.Code, ShouldEqual, http.StatusOK) @@ -225,7 +225,7 @@ func TestGetVersionsReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) _, _, err := api.getVersions(w, r, 20, 0) So(err, ShouldNotBeNil) @@ -256,7 +256,7 @@ func TestGetVersionsReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) _, _, err := api.getVersions(w, r, 20, 0) So(err, ShouldNotBeNil) @@ -292,7 +292,7 @@ func TestGetVersionsReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) _, _, err := api.getVersions(w, r, 20, 0) So(err, ShouldNotBeNil) @@ -332,7 +332,7 @@ func TestGetVersionsReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) _, _, err := api.getVersions(w, r, 20, 0) So(err, ShouldNotBeNil) @@ -371,7 +371,7 @@ func TestGetVersionsReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) _, _, err := api.getVersions(w, r, 20, 0) So(err, ShouldNotBeNil) @@ -413,7 +413,7 @@ func TestGetVersionsReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusInternalServerError) @@ -441,7 +441,7 @@ func TestGetVersionForbidden(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -473,7 +473,7 @@ func TestGetVersionUnauathorised(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -528,7 +528,7 @@ func TestGetVersionReturnsOK(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) Convey("With an etag", func() { version.ETag = "version-etag" @@ -591,7 +591,7 @@ func TestGetVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) assertInternalServerErr(w) @@ -617,7 +617,7 @@ func TestGetVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -653,7 +653,7 @@ func TestGetVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -692,7 +692,7 @@ func TestGetVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -730,7 +730,7 @@ func TestGetVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -756,7 +756,7 @@ func TestGetVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -782,7 +782,7 @@ func TestGetVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -806,7 +806,7 @@ func TestGetVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -852,7 +852,7 @@ func TestGetVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusInternalServerError) @@ -884,7 +884,7 @@ func TestPutVersionForbidden(t *testing.T) { } Convey("Given a valid request is executed", func() { - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) Convey("Then the request returns forbidden, with none of the expected calls made to the database", func() { @@ -922,7 +922,7 @@ func TestPutVersionUnauthorised(t *testing.T) { } Convey("Given a valid request is executed", func() { - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) Convey("Then the request returns unauthorized, with none of the expected calls made to the database", func() { @@ -1009,7 +1009,7 @@ func TestPutVersionReturnsSuccessfully(t *testing.T) { } Convey("Given a valid request is executed", func() { - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) Convey("Then the request is successful, with the expected calls", func() { @@ -1044,7 +1044,7 @@ func TestPutVersionReturnsSuccessfully(t *testing.T) { return "", nil } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) Convey("Then the request is successful, with the expected calls including the update retry", func() { @@ -1144,7 +1144,7 @@ func TestPutVersionReturnsSuccessfully(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -1201,7 +1201,7 @@ func TestPutVersionReturnsSuccessfully(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) Convey("Then it returns a 409 Conflict status", func() { @@ -1271,7 +1271,7 @@ func TestPutVersionReturnsSuccessfully(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) Convey("Then it returns a 409 Conflict status", func() { @@ -1343,7 +1343,7 @@ func TestPutVersionReturnsSuccessfully(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusOK) @@ -1392,7 +1392,7 @@ func TestPutVersionReturnsSuccessfully(t *testing.T) { UnlockInstanceFunc: func(context.Context, string) {}, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -1519,7 +1519,7 @@ func TestPutVersionReturnsSuccessfully(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) ctx := context.Background() @@ -1663,7 +1663,7 @@ func TestPutVersionReturnsSuccessfully(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusOK) @@ -1923,7 +1923,7 @@ func updateVersionDownloadTest(r *http.Request) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusOK) @@ -2005,7 +2005,7 @@ func TestPutVersionGenerateDownloadsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, mockDownloadGenerator, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, mockDownloadGenerator, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) Convey("then an internal server error response is returned", func() { @@ -2099,7 +2099,7 @@ func TestPutEmptyVersion(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) Convey("then a http status ok is returned", func() { @@ -2165,7 +2165,7 @@ func TestPutEmptyVersion(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) Convey("then a http status ok is returned", func() { @@ -2225,7 +2225,7 @@ func TestPutVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -2267,7 +2267,7 @@ func TestPutVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusInternalServerError) @@ -2312,7 +2312,7 @@ func TestPutVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -2348,7 +2348,7 @@ func TestPutVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -2384,7 +2384,7 @@ func TestPutVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -2441,7 +2441,7 @@ func TestPutVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -2496,7 +2496,7 @@ func TestPutVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -2555,7 +2555,7 @@ func TestPutVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -2599,7 +2599,7 @@ func TestPutVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusUnauthorized) @@ -2635,7 +2635,7 @@ func TestPutVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusForbidden) @@ -2701,7 +2701,7 @@ func TestPutVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) @@ -2838,7 +2838,7 @@ func TestPutVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -2900,7 +2900,7 @@ func TestPutVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mocked, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mocked, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) Convey("Then the API returns 400 with missing-format error", func() { @@ -2948,7 +2948,7 @@ func TestPutVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mocked, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mocked, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) Convey("Then API returns 400 with invalid-format error", func() { @@ -3224,7 +3224,7 @@ func TestDetachVersionForbidden(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -3270,7 +3270,7 @@ func TestDetachVersionUnauthorised(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) Convey("Then the response code is 401 and no expected database calls are made.", t, func() { @@ -3344,7 +3344,7 @@ func TestDetachVersionReturnOK(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -3413,7 +3413,7 @@ func TestDetachVersionReturnOK(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -3464,7 +3464,7 @@ func TestDetachVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -3501,7 +3501,7 @@ func TestDetachVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -3541,7 +3541,7 @@ func TestDetachVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -3584,7 +3584,7 @@ func TestDetachVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -3627,7 +3627,7 @@ func TestDetachVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -3678,7 +3678,7 @@ func TestDetachVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -3732,7 +3732,7 @@ func TestDetachVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -3774,7 +3774,7 @@ func TestDetachVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -3803,7 +3803,7 @@ func TestDetachVersionReturnsError(t *testing.T) { return handlerFunc }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -3833,7 +3833,7 @@ func TestDetachVersionReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -3891,7 +3891,7 @@ func TestDeleteVersionStaticDatasetReturnOK(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -3924,7 +3924,7 @@ func TestDeleteVersionStaticDatasetReturnError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -3971,7 +3971,7 @@ func TestDeleteVersionStaticDatasetReturnError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusNotFound) @@ -4018,7 +4018,7 @@ func TestDeleteVersionStaticDatasetReturnError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -4074,7 +4074,7 @@ func TestDeleteVersionStaticDatasetReturnError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -4116,7 +4116,7 @@ func TestDeleteVersionStaticDatasetReturnError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -4160,7 +4160,7 @@ func TestDeleteVersionStaticDatasetReturnError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -4204,7 +4204,7 @@ func TestPutStateForbidden(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) Convey("Then the response code is 403 and no expected database calls are made", func() { @@ -4238,7 +4238,7 @@ func TestPutStateUnauthorised(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) Convey("Then the response code is 401 and no expected database calls are made", func() { @@ -4401,7 +4401,10 @@ func TestPutStateReturnsOk(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + scuProducerMock := getSearchContentUpdatedMock() + searchContentUpdated := SearchContentUpdatedProducer{Producer: scuProducerMock} + + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, searchContentUpdated) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusOK) @@ -4414,6 +4417,7 @@ func TestPutStateReturnsOk(t *testing.T) { So(mockedDataStore.UpsertVersionStaticCalls(), ShouldHaveLength, 1) So(mockedDataStore.UpsertDatasetCalls(), ShouldHaveLength, 1) So(mockedDataStore.CheckEditionExistsStaticCalls(), ShouldHaveLength, 1) + So(len(scuProducerMock.OutputCalls()), ShouldEqual, 1) }) } @@ -4432,7 +4436,7 @@ func TestPutStateReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.putState(w, r) @@ -4452,7 +4456,7 @@ func TestPutStateReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -4472,7 +4476,7 @@ func TestPutStateReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -4496,7 +4500,7 @@ func TestPutStateReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -4520,7 +4524,7 @@ func TestPutStateReturnsError(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, &mocks.DownloadsGeneratorMock{}, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) @@ -4899,7 +4903,7 @@ func TestPutVersionEditionValidationNonStatic(t *testing.T) { }, } - api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock) + api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, authorisationMock, SearchContentUpdatedProducer{}) api.Router.ServeHTTP(w, r) So(w.Code, ShouldEqual, http.StatusBadRequest) diff --git a/api/webendpoints_test.go b/api/webendpoints_test.go index d9bfd56f..6e3a6975 100644 --- a/api/webendpoints_test.go +++ b/api/webendpoints_test.go @@ -376,5 +376,5 @@ func GetWebAPIWithMocks(ctx context.Context, mockedDataStore store.Storer, mocke cfg.DatasetAPIURL = host cfg.EnablePrivateEndpoints = false - return Setup(ctx, cfg, mux.NewRouter(), store.DataStore{Backend: mockedDataStore}, urlBuilder, mockedMapDownloadGenerators, authorisationMock, enableURLRewriting, &mockStatemachineDatasetAPI, permissionsMock, testIDClient) + return Setup(ctx, cfg, mux.NewRouter(), store.DataStore{Backend: mockedDataStore}, urlBuilder, mockedMapDownloadGenerators, authorisationMock, enableURLRewriting, &mockStatemachineDatasetAPI, permissionsMock, testIDClient, nil) } diff --git a/config/config.go b/config/config.go index e47c5591..13b07e42 100644 --- a/config/config.go +++ b/config/config.go @@ -30,6 +30,7 @@ type Configuration struct { KafkaSecSkipVerify bool `envconfig:"KAFKA_SEC_SKIP_VERIFY"` GenerateDownloadsTopic string `envconfig:"GENERATE_DOWNLOADS_TOPIC"` CantabularExportStartTopic string `envconfig:"CANTABULAR_EXPORT_START"` + SearchContentUpdatedTopic string `envconfig:"SEARCH_CONTENT_UPDATED_TOPIC"` CodeListAPIURL string `envconfig:"CODE_LIST_API_URL"` DatasetAPIURL string `envconfig:"DATASET_API_URL"` FilesAPIURL string `envconfig:"FILES_API_URL"` @@ -89,6 +90,7 @@ func Get() (*Configuration, error) { KafkaProducerMinBrokersHealthy: 2, GenerateDownloadsTopic: "filter-job-submitted", CantabularExportStartTopic: "cantabular-export-start", + SearchContentUpdatedTopic: "search-content-updated", CodeListAPIURL: "http://localhost:22400", DatasetAPIURL: "http://localhost:22000", FilesAPIURL: "http://localhost:26900", diff --git a/config/config_test.go b/config/config_test.go index aa2f181a..c5d4a008 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -32,6 +32,7 @@ func TestSpec(t *testing.T) { So(cfg.KafkaSecSkipVerify, ShouldBeFalse) So(cfg.GenerateDownloadsTopic, ShouldEqual, "filter-job-submitted") So(cfg.CantabularExportStartTopic, ShouldEqual, "cantabular-export-start") + So(cfg.SearchContentUpdatedTopic, ShouldEqual, "search-content-updated") So(cfg.DatasetAPIURL, ShouldEqual, "http://localhost:22000") So(cfg.CodeListAPIURL, ShouldEqual, "http://localhost:22400") So(cfg.DownloadServiceSecretKey, ShouldEqual, "QB0108EZ-825D-412C-9B1D-41EF7747F462") diff --git a/dimension/dimension_test.go b/dimension/dimension_test.go index 79a0294f..080688db 100644 --- a/dimension/dimension_test.go +++ b/dimension/dimension_test.go @@ -2052,5 +2052,5 @@ func getAPIWithCMDMocks(ctx context.Context, mockedDataStore store.Storer, mocke testIdentityClient := clientsidentity.New(cfg.ZebedeeURL) - return api.Setup(ctx, cfg, mux.NewRouter(), store.DataStore{Backend: mockedDataStore}, urlBuilder, downloadGenerators, authorisationMock, enableURLRewriting, &mockStatemachineDatasetAPI, permissionsChecker, testIdentityClient) + return api.Setup(ctx, cfg, mux.NewRouter(), store.DataStore{Backend: mockedDataStore}, urlBuilder, downloadGenerators, authorisationMock, enableURLRewriting, &mockStatemachineDatasetAPI, permissionsChecker, testIdentityClient, nil) } diff --git a/features/static_versions_put.feature b/features/static_versions_put.feature index f8259e4d..b9a84e7e 100644 --- a/features/static_versions_put.feature +++ b/features/static_versions_put.feature @@ -1,7 +1,7 @@ Feature: Static Dataset Versions PUT API - Background: We have static datasets for PUT version testing - Given I have a static dataset with version: + Background: We have static datasets for PUT version testing + Given I have a static dataset with version: """ { "dataset": { @@ -134,8 +134,8 @@ Feature: Static Dataset Versions PUT API "type": "static" } """ - Then the HTTP status code should be "200" - And I should receive the following JSON response: + Then the HTTP status code should be "200" + And I should receive the following JSON response: """ { "dataset_id": "static-dataset-update", @@ -181,7 +181,7 @@ Feature: Static Dataset Versions PUT API "type": "static" } """ - Then the HTTP status code should be "200" + Then the HTTP status code should be "200" Scenario: PUT updates static dataset version distributions Given private endpoints are enabled @@ -208,7 +208,7 @@ Feature: Static Dataset Versions PUT API "type": "static" } """ - Then the HTTP status code should be "200" + Then the HTTP status code should be "200" Scenario: PUT updates static dataset version edition Given private endpoints are enabled @@ -221,7 +221,7 @@ Feature: Static Dataset Versions PUT API "type": "static" } """ - Then the HTTP status code should be "200" + Then the HTTP status code should be "200" Scenario: PUT fails for non-existent version Given private endpoints are enabled @@ -233,7 +233,7 @@ Feature: Static Dataset Versions PUT API "type": "static" } """ - Then the HTTP status code should be "404" + Then the HTTP status code should be "404" Scenario: PUT fails for non-existent dataset Given private endpoints are enabled @@ -245,18 +245,18 @@ Feature: Static Dataset Versions PUT API "type": "static" } """ - Then the HTTP status code should be "404" + Then the HTTP status code should be "404" - Scenario: PUT fails when not authorised - Given private endpoints are enabled - When I PUT "/datasets/static-dataset-update/editions/2025/versions/1" + Scenario: PUT fails when not authorised + Given private endpoints are enabled + When I PUT "/datasets/static-dataset-update/editions/2025/versions/1" """ { "state": "approved", "type": "static" } """ - Then the HTTP status code should be "401" + Then the HTTP status code should be "401" Scenario: PUT state endpoint updates successfully Given private endpoints are enabled @@ -267,7 +267,7 @@ Feature: Static Dataset Versions PUT API "state": "approved" } """ - Then the HTTP status code should be "200" + Then the HTTP status code should be "200" Scenario: PUT state transitions from associated to approved Given private endpoints are enabled @@ -278,10 +278,10 @@ Feature: Static Dataset Versions PUT API "state": "approved" } """ - Then the HTTP status code should be "200" + Then the HTTP status code should be "200" - Scenario: PUT state transitions from approved to published - Given I have a static dataset with version: + Scenario: PUT state transitions from approved to published + Given I have a static dataset with version: """ { "dataset": { @@ -333,7 +333,7 @@ Feature: Static Dataset Versions PUT API "state": "published" } """ - Then the HTTP status code should be "200" + Then the HTTP status code should be "200" Scenario: PUT state fails with invalid state transition from associated to published Given private endpoints are enabled @@ -344,7 +344,7 @@ Feature: Static Dataset Versions PUT API "state": "published" } """ - Then the HTTP status code should be "400" + Then the HTTP status code should be "400" Scenario: PUT state fails with invalid state Given private endpoints are enabled @@ -355,20 +355,20 @@ Feature: Static Dataset Versions PUT API "state": "invalid-state" } """ - Then the HTTP status code should be "400" + Then the HTTP status code should be "400" - Scenario: PUT state fails when not authorised - Given private endpoints are enabled - When I PUT "/datasets/static-dataset-update/editions/2025/versions/1/state" + Scenario: PUT state fails when not authorised + Given private endpoints are enabled + When I PUT "/datasets/static-dataset-update/editions/2025/versions/1/state" """ { "state": "approved" } """ - Then the HTTP status code should be "401" + Then the HTTP status code should be "401" - Scenario: PUT fails when updating edition-id to existing edition for static dataset - Given I have a static dataset with version: + Scenario: PUT fails when updating edition-id to existing edition for static dataset + Given I have a static dataset with version: """ { "dataset": { @@ -400,7 +400,7 @@ Feature: Static Dataset Versions PUT API } } """ - And I have a static dataset with version: + And I have a static dataset with version: """ { "dataset": { @@ -441,8 +441,8 @@ Feature: Static Dataset Versions PUT API "type": "static" } """ - Then the HTTP status code should be "409" - And I should receive the following response: + Then the HTTP status code should be "409" + And I should receive the following response: """ the edition already exists """ @@ -458,7 +458,7 @@ Feature: Static Dataset Versions PUT API "type": "static" } """ - Then the HTTP status code should be "200" + Then the HTTP status code should be "200" Scenario: PUT state handles idempotent transitions correctly Given I have a static dataset with version: @@ -495,6 +495,7 @@ Feature: Static Dataset Versions PUT API """ And private endpoints are enabled And I am an admin user + And I have a real kafka container with topic "search-content-updated" When I PUT "/datasets/static-dataset-published/editions/2025/versions/1/state" """ { @@ -502,6 +503,16 @@ Feature: Static Dataset Versions PUT API } """ Then the HTTP status code should be "200" + And these kafka messages are produced: + """ + { + "content_type": "static", + "dataset_id": "", + "edition": "2025", + "title": "", + "uri": "/datasets/static-dataset-published/editions/2025/versions/1" + } + """ Scenario: PUT succeeds when updating edition ID to unique value within series Given private endpoints are enabled diff --git a/features/steps/steps.go b/features/steps/steps.go index 0419c498..4c5fae59 100644 --- a/features/steps/steps.go +++ b/features/steps/steps.go @@ -58,6 +58,7 @@ func (c *DatasetComponent) RegisterSteps(ctx *godog.ScenarioContext) { ctx.Step(`^the dataset "([^"]*)" should have next equal to current$`, c.theDatasetShouldHaveNextEqualToCurrent) ctx.Step(`^the "([^"]*)" feature flag is "([^"]*)"$`, c.theFeatureFlagIs) ctx.Step(`^I am a publisher user$`, c.publisherJWTToken) + ctx.Step(`^these kafka messages are produced:$`, c.theseKafkaMessagesAreProduced) } func (c *DatasetComponent) theFeatureFlagIs(flagName, status string) error { @@ -277,6 +278,43 @@ func (c *DatasetComponent) theseCantabularGeneratorDownloadsEventsAreProduced(ev return nil } +func (c *DatasetComponent) theseKafkaMessagesAreProduced(kafkaJSON *godog.DocString) error { + var expectedPayload interface{} + if err := json.Unmarshal([]byte(kafkaJSON.Content), &expectedPayload); err != nil { + return fmt.Errorf("failed to unmarshal kafkaJSON: %w", err) + } + expected := []interface{}{expectedPayload} + messages := []interface{}{} + listen := true + + for listen { + select { + case <-time.After(10 * time.Second): + listen = false + case <-c.consumer.Channels().Closer: + return errors.New("closer channel closed") + case msg, ok := <-c.consumer.Channels().Upstream: + if !ok { + return errors.New("upstream channel closed") + } + var gotPayload interface{} + if err := json.Unmarshal(msg.GetData(), &gotPayload); err != nil { + msg.Commit() + msg.Release() + return fmt.Errorf("failed to unmarshal kafka message: %w", err) + } + messages = append(messages, gotPayload) + msg.Commit() + msg.Release() + } + } + + if diff := cmp.Diff(messages, expected); diff != "" { + return fmt.Errorf("-got +expected)\n%s", diff) + } + return nil +} + func (c *DatasetComponent) iHaveTheseEditions(editionsJSON *godog.DocString) error { editions := []models.Edition{} diff --git a/instance/instance_external_test.go b/instance/instance_external_test.go index fc5e8fd2..ed45730d 100644 --- a/instance/instance_external_test.go +++ b/instance/instance_external_test.go @@ -1009,5 +1009,5 @@ func getAPIWithCantabularMocks(ctx context.Context, mockedDataStore store.Storer } testIdentityClient := clientsidentity.New(cfg.ZebedeeURL) - return api.Setup(ctx, cfg, mux.NewRouter(), store.DataStore{Backend: mockedDataStore}, urlBuilder, mockedMapDownloadGenerators, am, enableURLRewriting, &mockStatemachineDatasetAPI, permissionsChecker, testIdentityClient) + return api.Setup(ctx, cfg, mux.NewRouter(), store.DataStore{Backend: mockedDataStore}, urlBuilder, mockedMapDownloadGenerators, am, enableURLRewriting, &mockStatemachineDatasetAPI, permissionsChecker, testIdentityClient, nil) } diff --git a/service/initialise.go b/service/initialise.go index ae20ee07..a41d0f19 100644 --- a/service/initialise.go +++ b/service/initialise.go @@ -18,13 +18,13 @@ import ( // ExternalServiceList holds the initialiser and initialisation state of external services. type ExternalServiceList struct { - GenerateDownloadsProducer bool - AuthorisationMiddleware bool - Graph bool - HealthCheck bool - MongoDB bool - FilesAPIClient bool - Init Initialiser + KafkaProducer bool + AuthorisationMiddleware bool + Graph bool + HealthCheck bool + MongoDB bool + FilesAPIClient bool + Init Initialiser } // NewServiceList creates a new service list with the provided initialiser @@ -59,7 +59,7 @@ func (e *ExternalServiceList) GetProducer(ctx context.Context, cfg *config.Confi if err != nil { return } - e.GenerateDownloadsProducer = true + e.KafkaProducer = true return } diff --git a/service/service.go b/service/service.go index 295b796e..4ea55033 100644 --- a/service/service.go +++ b/service/service.go @@ -50,6 +50,7 @@ type Service struct { mongoDB store.MongoDB generateCMDDownloadsProducer kafka.IProducer generateCantabularDownloadsProducer kafka.IProducer + searchContentUpdatedKafkaProducer kafka.IProducer identityClient *clientsidentity.Client filesAPIClient filesAPISDK.Clienter server HTTPServer @@ -253,6 +254,11 @@ func (svc *Service) Run(ctx context.Context, buildTime, gitCommit, version strin log.Fatal(ctx, "could not obtain generate downloads producer for cantabular", err) return err } + svc.searchContentUpdatedKafkaProducer, err = svc.serviceList.GetProducer(ctx, svc.config, svc.config.SearchContentUpdatedTopic) + if err != nil { + log.Fatal(ctx, "could not obtain search content updated producer", err) + return err + } } downloadGeneratorCantabular := &download.CantabularGenerator{ @@ -265,6 +271,10 @@ func (svc *Service) Run(ctx context.Context, buildTime, gitCommit, version strin Marshaller: schema.GenerateCMDDownloadsEvent, } + searchContentUpdatedProducer := &api.SearchContentUpdatedProducer{ + Producer: adapter.NewProducerAdapter(svc.searchContentUpdatedKafkaProducer), + } + downloadGenerators := map[models.DatasetType]api.DownloadsGenerator{ models.CantabularBlob: downloadGeneratorCantabular, models.CantabularTable: downloadGeneratorCantabular, @@ -338,12 +348,13 @@ func (svc *Service) Run(ctx context.Context, buildTime, gitCommit, version strin if svc.config.EnablePrivateEndpoints { svc.generateCMDDownloadsProducer.LogErrors(ctx) svc.generateCantabularDownloadsProducer.LogErrors(ctx) + svc.searchContentUpdatedKafkaProducer.LogErrors(ctx) } sm := GetStateMachine(ctx, ds) svc.smDS = application.Setup(ds, smDownloadGenerators, sm) - svc.api = api.Setup(ctx, svc.config, r, ds, urlBuilder, downloadGenerators, authorisation, enableURLRewriting, svc.smDS, permissionChecker, svc.identityClient) + svc.api = api.Setup(ctx, svc.config, r, ds, urlBuilder, downloadGenerators, authorisation, enableURLRewriting, svc.smDS, permissionChecker, svc.identityClient, searchContentUpdatedProducer) // Set the files API client on the DatasetAPI after initialisation if svc.config.EnablePrivateEndpoints && svc.filesAPIClient != nil { @@ -487,9 +498,10 @@ func (svc *Service) Close(ctx context.Context) error { } } - // Close GenerateDownloadsProducer (if it exists) - if svc.serviceList.GenerateDownloadsProducer { + // Close KafkaProducer (if it exists) + if svc.serviceList.KafkaProducer { log.Info(shutdownContext, "closing generated downloads kafka producer", log.Data{"producer": "DimensionExtracted"}) + // Only one kafka producer needs to be shutdown as they share the same underlying connections if err := svc.generateCMDDownloadsProducer.Close(shutdownContext); err != nil { log.Warn(shutdownContext, "error while closing generated downloads kafka producer", log.Data{"producer": "DimensionExtracted", "err": err.Error()}) } @@ -552,6 +564,11 @@ func (svc *Service) registerCheckers(ctx context.Context) (err error) { log.Error(ctx, "error adding check for cantabular kafka downloads producer", err) } + if err = svc.healthCheck.AddCheck("Kafka Search Content Updated Producer", svc.searchContentUpdatedKafkaProducer.Checker); err != nil { + hasErrors = true + log.Error(ctx, "error adding check for search content updated kafka producer", err) + } + if err = svc.healthCheck.AddCheck("Files API Client", svc.filesAPIClient.Checker); err != nil { hasErrors = true log.Error(ctx, "error adding check for files api client", err) diff --git a/service/service_test.go b/service/service_test.go index 0379304d..879b57b5 100644 --- a/service/service_test.go +++ b/service/service_test.go @@ -151,7 +151,7 @@ func TestRun(t *testing.T) { So(svcList.MongoDB, ShouldBeFalse) So(svcList.Graph, ShouldBeFalse) So(svcList.FilesAPIClient, ShouldBeFalse) - So(svcList.GenerateDownloadsProducer, ShouldBeFalse) + So(svcList.KafkaProducer, ShouldBeFalse) So(svcList.HealthCheck, ShouldBeFalse) }) }) @@ -171,7 +171,7 @@ func TestRun(t *testing.T) { So(svcList.MongoDB, ShouldBeTrue) So(svcList.Graph, ShouldBeFalse) So(svcList.FilesAPIClient, ShouldBeFalse) - So(svcList.GenerateDownloadsProducer, ShouldBeFalse) + So(svcList.KafkaProducer, ShouldBeFalse) So(svcList.HealthCheck, ShouldBeFalse) }) }) @@ -192,7 +192,7 @@ func TestRun(t *testing.T) { So(svcList.MongoDB, ShouldBeTrue) So(svcList.Graph, ShouldBeTrue) So(svcList.FilesAPIClient, ShouldBeFalse) - So(svcList.GenerateDownloadsProducer, ShouldBeFalse) + So(svcList.KafkaProducer, ShouldBeFalse) So(svcList.HealthCheck, ShouldBeFalse) }) }) @@ -214,7 +214,7 @@ func TestRun(t *testing.T) { So(svcList.MongoDB, ShouldBeTrue) So(svcList.Graph, ShouldBeTrue) So(svcList.FilesAPIClient, ShouldBeTrue) - So(svcList.GenerateDownloadsProducer, ShouldBeFalse) + So(svcList.KafkaProducer, ShouldBeFalse) So(svcList.HealthCheck, ShouldBeFalse) }) }) @@ -238,7 +238,7 @@ func TestRun(t *testing.T) { So(svcList.MongoDB, ShouldBeTrue) So(svcList.Graph, ShouldBeTrue) So(svcList.FilesAPIClient, ShouldBeTrue) - So(svcList.GenerateDownloadsProducer, ShouldBeTrue) + So(svcList.KafkaProducer, ShouldBeTrue) So(svcList.HealthCheck, ShouldBeFalse) }) }) @@ -270,16 +270,17 @@ func TestRun(t *testing.T) { So(err.Error(), ShouldResemble, fmt.Sprintf("unable to register checkers: %s", errAddheckFail.Error())) So(svcList.MongoDB, ShouldBeTrue) So(svcList.Graph, ShouldBeTrue) - So(svcList.GenerateDownloadsProducer, ShouldBeTrue) + So(svcList.KafkaProducer, ShouldBeTrue) So(svcList.FilesAPIClient, ShouldBeTrue) So(svcList.HealthCheck, ShouldBeTrue) - So(len(hcMockAddFail.AddCheckCalls()), ShouldEqual, 6) + So(len(hcMockAddFail.AddCheckCalls()), ShouldEqual, 7) So(hcMockAddFail.AddCheckCalls()[0].Name, ShouldResemble, "Zebedee") So(hcMockAddFail.AddCheckCalls()[1].Name, ShouldResemble, "Kafka Generate Downloads Producer") So(hcMockAddFail.AddCheckCalls()[2].Name, ShouldResemble, "Kafka Generate Cantabular Downloads Producer") - So(hcMockAddFail.AddCheckCalls()[3].Name, ShouldResemble, "Files API Client") - So(hcMockAddFail.AddCheckCalls()[4].Name, ShouldResemble, "Graph DB") - So(hcMockAddFail.AddCheckCalls()[5].Name, ShouldResemble, "Mongo DB") + So(hcMockAddFail.AddCheckCalls()[3].Name, ShouldResemble, "Kafka Search Content Updated Producer") + So(hcMockAddFail.AddCheckCalls()[4].Name, ShouldResemble, "Files API Client") + So(hcMockAddFail.AddCheckCalls()[5].Name, ShouldResemble, "Graph DB") + So(hcMockAddFail.AddCheckCalls()[6].Name, ShouldResemble, "Mongo DB") }) }) @@ -304,18 +305,19 @@ func TestRun(t *testing.T) { So(svcList.MongoDB, ShouldBeTrue) So(svcList.Graph, ShouldBeTrue) So(svcList.FilesAPIClient, ShouldBeTrue) - So(svcList.GenerateDownloadsProducer, ShouldBeTrue) + So(svcList.KafkaProducer, ShouldBeTrue) So(svcList.HealthCheck, ShouldBeTrue) }) Convey("The checkers are registered and the healthcheck and http server started", func() { - So(len(hcMock.AddCheckCalls()), ShouldEqual, 6) + So(len(hcMock.AddCheckCalls()), ShouldEqual, 7) So(hcMock.AddCheckCalls()[0].Name, ShouldResemble, "Zebedee") So(hcMock.AddCheckCalls()[1].Name, ShouldResemble, "Kafka Generate Downloads Producer") So(hcMock.AddCheckCalls()[2].Name, ShouldResemble, "Kafka Generate Cantabular Downloads Producer") - So(hcMock.AddCheckCalls()[3].Name, ShouldResemble, "Files API Client") - So(hcMock.AddCheckCalls()[4].Name, ShouldResemble, "Graph DB") - So(hcMock.AddCheckCalls()[5].Name, ShouldResemble, "Mongo DB") + So(hcMock.AddCheckCalls()[3].Name, ShouldResemble, "Kafka Search Content Updated Producer") + So(hcMock.AddCheckCalls()[4].Name, ShouldResemble, "Files API Client") + So(hcMock.AddCheckCalls()[5].Name, ShouldResemble, "Graph DB") + So(hcMock.AddCheckCalls()[6].Name, ShouldResemble, "Mongo DB") So(len(initMock.DoGetHTTPServerCalls()), ShouldEqual, 1) So(initMock.DoGetHTTPServerCalls()[0].BindAddr, ShouldEqual, ":22000") So(len(hcMock.StartCalls()), ShouldEqual, 1) @@ -344,7 +346,7 @@ func TestRun(t *testing.T) { So(svcList.MongoDB, ShouldBeTrue) So(svcList.Graph, ShouldBeFalse) So(svcList.FilesAPIClient, ShouldBeFalse) - So(svcList.GenerateDownloadsProducer, ShouldBeFalse) + So(svcList.KafkaProducer, ShouldBeFalse) So(svcList.HealthCheck, ShouldBeTrue) }) @@ -460,12 +462,12 @@ func TestClose(t *testing.T) { }) fullSvcList := &service.ExternalServiceList{ - GenerateDownloadsProducer: true, - Graph: true, - HealthCheck: true, - MongoDB: true, - FilesAPIClient: true, - Init: nil, + KafkaProducer: true, + Graph: true, + HealthCheck: true, + MongoDB: true, + FilesAPIClient: true, + Init: nil, } Convey("Closing the service results in all the initialised dependencies being closed in the expected order", func() {