diff --git a/Makefile b/Makefile index b9992859..296297c7 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,8 @@ GIT_COMMIT=$(shell git rev-parse HEAD) VERSION ?= $(shell git tag --points-at HEAD | grep ^v | head -n 1) LDFLAGS=-ldflags "-X main.BuildTime=$(BUILD_TIME) -X main.GitCommit=$(GIT_COMMIT) -X main.Version=$(VERSION)" +export GRAPH_DRIVER_TYPE?=neo4j +export GRAPH_ADDR?=bolt://localhost:7687 export ENABLE_PRIVATE_ENDPOINTS?=true .PHONY: all @@ -24,7 +26,7 @@ build: .PHONY: debug debug: - GRAPH_DRIVER_TYPE="neo4j" GRAPH_ADDR="bolt://localhost:7687" HUMAN_LOG=1 go run -race $(LDFLAGS) main.go + HUMAN_LOG=1 go run -race $(LDFLAGS) main.go .PHONY: acceptance-publishing acceptance-publishing: build diff --git a/go.mod b/go.mod index 9cb79ff9..1eded4fa 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,13 @@ module github.com/ONSdigital/dp-dataset-api go 1.13 require ( - github.com/ONSdigital/dp-api-clients-go v1.28.0 + github.com/ONSdigital/dp-api-clients-go v1.30.0 github.com/ONSdigital/dp-authorisation v0.1.0 - github.com/ONSdigital/dp-graph/v2 v2.1.3 + github.com/ONSdigital/dp-graph/v2 v2.3.0 github.com/ONSdigital/dp-healthcheck v1.0.5 github.com/ONSdigital/dp-kafka v1.1.7 github.com/ONSdigital/dp-mongodb v1.4.0 - github.com/ONSdigital/dp-net v1.0.8 + github.com/ONSdigital/dp-net v1.0.9 github.com/ONSdigital/go-ns v0.0.0-20200205115900-a11716f93bad github.com/ONSdigital/log.go v1.0.1 github.com/frankban/quicktest v1.9.0 // indirect diff --git a/go.sum b/go.sum index d56a4063..6cb9dea6 100644 --- a/go.sum +++ b/go.sum @@ -2,15 +2,15 @@ github.com/ONSdigital/dp-api-clients-go v1.1.0/go.mod h1:9lqor0I7caCnRWr04gU/r7x github.com/ONSdigital/dp-api-clients-go v1.9.0/go.mod h1:SM0b/NXDWndJ9EulmAGdfDY4DxPxK+pNsP8eZlIWiqM= github.com/ONSdigital/dp-api-clients-go v1.28.0 h1:ExIUlHC6uBdBlFwt/gAI0ApSzpyigy0NWJFK3XCwSVc= github.com/ONSdigital/dp-api-clients-go v1.28.0/go.mod h1:iyJy6uRL4B6OYOJA0XMr5UHt6+Q8XmN9uwmURO+9Oj4= +github.com/ONSdigital/dp-api-clients-go v1.30.0 h1:TA3LHTccG4GHlUqDHGSrJRZEq15Wd1q1thE4Yxdv8H8= +github.com/ONSdigital/dp-api-clients-go v1.30.0/go.mod h1:iyJy6uRL4B6OYOJA0XMr5UHt6+Q8XmN9uwmURO+9Oj4= github.com/ONSdigital/dp-authorisation v0.1.0 h1:HzYwJdvk7ZAeB56KMAH6MP5+5uZuuJnEyGq6CViDoCg= github.com/ONSdigital/dp-authorisation v0.1.0/go.mod h1:rT81tcvWto5/cUWUFd0Q6gTqBoRfQmD6Qp0sq7FyiMg= github.com/ONSdigital/dp-frontend-models v1.1.0/go.mod h1:TT96P7Mi69N3Tc/jFNdbjiwG4GAaMjP26HLotFQ6BPw= -github.com/ONSdigital/dp-graph/v2 v2.1.3 h1:7BJsRE9FDf7tFtJvI5v7RX94q4BAbiJFDWpxQCNfM18= -github.com/ONSdigital/dp-graph/v2 v2.1.3/go.mod h1:6C59rOY0qBKblczkQrJZZKa8ZLR3yKkyunSCeIUavtU= +github.com/ONSdigital/dp-graph/v2 v2.3.0 h1:xK9qImVbh86l04aAUeurjB7d8mwn27eacP+5gpvPLO8= +github.com/ONSdigital/dp-graph/v2 v2.3.0/go.mod h1:K4LIhFcyxB8g7nUG5I5I8x6QVf89x82dCEFBbE0mmaQ= github.com/ONSdigital/dp-healthcheck v0.0.0-20200131122546-9db6d3f0494e/go.mod h1:zighxZ/0m5u7zo0eAr8XFlA+Dz2ic7A1vna6YXvhCjQ= github.com/ONSdigital/dp-healthcheck v1.0.0/go.mod h1:zighxZ/0m5u7zo0eAr8XFlA+Dz2ic7A1vna6YXvhCjQ= -github.com/ONSdigital/dp-healthcheck v1.0.2 h1:N8SzpYzdixVgJS9NMzTBA2RZ2bi3Am1wE5F8ROEpTYw= -github.com/ONSdigital/dp-healthcheck v1.0.2/go.mod h1:zighxZ/0m5u7zo0eAr8XFlA+Dz2ic7A1vna6YXvhCjQ= github.com/ONSdigital/dp-healthcheck v1.0.5 h1:DXnohGIqXaLLeYGdaGOhgkZjAbWMNoLAjQ3EgZeMT3M= github.com/ONSdigital/dp-healthcheck v1.0.5/go.mod h1:2wbVAUHMl9+4tWhUlxYUuA1dnf2+NrwzC+So5f5BMLk= github.com/ONSdigital/dp-kafka v1.1.7 h1:/XjDYHZDxA0r4JR5Ua/99z8ocVN6OUU/VyPTeWh95Qc= @@ -23,10 +23,9 @@ github.com/ONSdigital/dp-net v1.0.5-0.20200805082802-e518bc287596/go.mod h1:wDVh github.com/ONSdigital/dp-net v1.0.5-0.20200805145012-9227a11caddb/go.mod h1:MrSZwDUvp8u1VJEqa+36Gwq4E7/DdceW+BDCvGes6Cs= github.com/ONSdigital/dp-net v1.0.5-0.20200805150805-cac050646ab5/go.mod h1:de3LB9tedE0tObBwa12dUOt5rvTW4qQkF5rXtt4b6CE= github.com/ONSdigital/dp-net v1.0.7/go.mod h1:1QFzx32FwPKD2lgZI6MtcsUXritsBdJihlzIWDrQ/gc= -github.com/ONSdigital/dp-net v1.0.8 h1:fcOw+PBZWgp14ryz61daMvkqFKIK7lp7AceRbaBLa24= -github.com/ONSdigital/dp-net v1.0.8/go.mod h1:2lvIKOlD4T3BjWQwjHhBUO2UNWDk82u/+mHRn0R3C9A= +github.com/ONSdigital/dp-net v1.0.9 h1:jjQzUkCPNEvqdOWTuK+F65HE46dH72Owtfcv9yKq8kc= +github.com/ONSdigital/dp-net v1.0.9/go.mod h1:2lvIKOlD4T3BjWQwjHhBUO2UNWDk82u/+mHRn0R3C9A= github.com/ONSdigital/dp-rchttp v0.0.0-20190919143000-bb5699e6fd59/go.mod h1:KkW68U3FPuivW4ogi9L8CPKNj9ZxGko4qcUY7KoAAkQ= -github.com/ONSdigital/dp-rchttp v0.0.0-20200114090501-463a529590e8 h1:MWIHCr/ud5ur9elhfvKtSjMJInqf3iUY8F4J27qGQPA= github.com/ONSdigital/dp-rchttp v0.0.0-20200114090501-463a529590e8/go.mod h1:821jZtK0oBsV8hjIkNr8vhAWuv0FxJBPJuAHa2B70Gk= github.com/ONSdigital/dp-rchttp v1.0.0 h1:K/1/gDtfMZCX1Mbmq80nZxzDirzneqA1c89ea26FqP4= github.com/ONSdigital/dp-rchttp v1.0.0/go.mod h1:821jZtK0oBsV8hjIkNr8vhAWuv0FxJBPJuAHa2B70Gk= @@ -40,7 +39,6 @@ github.com/ONSdigital/graphson v0.0.0-20190718134034-c13ceacd109d/go.mod h1:zQ+8 github.com/ONSdigital/gremgo-neptune v1.0.0 h1:l0Pizt2goXK5oCFeqs2sOkosZbF4sva0RpcR150VvNE= github.com/ONSdigital/gremgo-neptune v1.0.0/go.mod h1:GZz/N6xjNY+EN0x4FmfBDrM73R+Pr3aI5iCwYbY1oYQ= github.com/ONSdigital/log.go v0.0.0-20191127134126-2a610b254f20/go.mod h1:BD7D8FWP1fzwUWsrCopEG72jl9cchCaVNIGSz6YvL+Y= -github.com/ONSdigital/log.go v1.0.0 h1:hZQTuitFv4nSrpzMhpGvafUC5/8xMVnLI0CWe1rAJNc= github.com/ONSdigital/log.go v1.0.0/go.mod h1:UnGu9Q14gNC+kz0DOkdnLYGoqugCvnokHBRBxFRpVoQ= github.com/ONSdigital/log.go v1.0.1-0.20200805084515-ee61165ea36a/go.mod h1:dDnQATFXCBOknvj6ZQuKfmDhbOWf3e8mtV+dPEfWJqs= github.com/ONSdigital/log.go v1.0.1-0.20200805145532-1f25087a0744/go.mod h1:y4E9MYC+cV9VfjRD0UBGj8PA7H3wABqQi87/ejrDhYc= @@ -69,7 +67,6 @@ github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= -github.com/frankban/quicktest v1.4.1 h1:Wv2VwvNn73pAdFIVUQRXYDFp31lXKbqblIXo/Q5GPSg= github.com/frankban/quicktest v1.4.1/go.mod h1:36zfPVQyHxymz4cH7wlDmVwDrJuljRB60qkgn7rorfQ= github.com/frankban/quicktest v1.9.0 h1:jfEA+Psfr/pHsRJYPpHiNu7PGJnGctNxvTaM3K1EyXk= github.com/frankban/quicktest v1.9.0/go.mod h1:ui7WezCLWMWxVWr1GETZY3smRy0G4KWq9vcPtJmFl7Y= @@ -84,30 +81,24 @@ github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4 github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= -github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= -github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc= github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= -github.com/gorilla/schema v1.1.0 h1:CamqUDOFUBqzrvxuz2vEwo8+SUdwsluFh7IlzJh30LY= github.com/gorilla/schema v1.1.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU= -github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE= github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE= github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= @@ -123,13 +114,10 @@ github.com/justinas/alice v1.2.0 h1:+MHSA/vccVCF4Uq37S42jwlkvI2Xzl7zTPCN5BnZNVo= github.com/justinas/alice v1.2.0/go.mod h1:fN5HRH/reO/zrUflLfTN43t3vXvKzvZIENsNEe7i7qA= github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= -github.com/klauspost/compress v1.8.2 h1:Bx0qjetmNjdFXASH02NSAREKpiaDwkO1DRZ3dV2KCcs= github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.9.5 h1:U+CaK85mrNNb4k8BNOfgJtJ/gr6kswUCFj6miSzVC6M= github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= -github.com/klauspost/cpuid v1.2.3 h1:CCtW0xUnWGVINKvE/WWOYKdsPV6mawAtvQuSl8guwQs= github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= @@ -139,7 +127,6 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM= github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= @@ -154,7 +141,6 @@ github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0 github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.9.0 h1:R1uwffexN6Pr340GtYRIdZmAiN4J+iw6WG4wog1DUXg= github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA= -github.com/pierrec/lz4 v2.2.6+incompatible h1:6aCX4/YZ9v8q69hTyiR7dNLnTA3fgtKHVVW5BCd5Znw= github.com/pierrec/lz4 v2.2.6+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pierrec/lz4 v2.4.1+incompatible h1:mFe7ttWaflA46Mhqh+jUfjp2qTbPYxLB2/OyBppH9dg= github.com/pierrec/lz4 v2.4.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= @@ -172,33 +158,26 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1 github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= -github.com/square/mongo-lock v0.0.0-20191001051310-282c90e422d0 h1:Ae3eHg4QrqbpLdF/Y6jeREKvgqlgrftOglYY4RHdv9s= github.com/square/mongo-lock v0.0.0-20191001051310-282c90e422d0/go.mod h1:wR5++/O5fpa0UtI+9T8gKIi5jjl10va/EIEMRySqic4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/unrolled/render v1.0.2/go.mod h1:gN9T0NhL4Bfbwu8ann7Ry/TGHYfosul+J0obPf6NBdM= -github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c h1:u40Z8hqBAAQyv+vATcGgV0YCnDjqSL7/q/JyPhhJSPk= github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= -github.com/xdg/stringprep v1.0.0 h1:d9X0esnoa3dFsV0FG35rAT0RIhYFlPq7MiP+DW89La0= github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5 h1:bselrhR0Or1vomJZC8ZIjWtbDmn9OYFLX5Ik9alpJpE= golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8= golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -206,25 +185,22 @@ golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e h1:N7DeIrjYszNmSW409R3frPPwglRwMkXSBzwVbkOjLLA= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262 h1:qsl9y/CJx34tuA7QCPNp86JNJe4spst6Ff8MjvPUdPg= golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/avro.v0 v0.0.0-20171217001914-a730b5802183 h1:PGIdqvwfpMUyUP+QAlAnKTSWQ671SmYjoou2/5j7HXk= gopkg.in/avro.v0 v0.0.0-20171217001914-a730b5802183/go.mod h1:FvqrFXt+jCsyQibeRv4xxEJBL5iG2DDW5aeJwzDiq4A= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/models/dataset.go b/models/dataset.go index f8bd1e5c..76091cd4 100644 --- a/models/dataset.go +++ b/models/dataset.go @@ -6,7 +6,9 @@ import ( "fmt" "io" "io/ioutil" + "net/url" "strconv" + "strings" "time" errs "github.com/ONSdigital/dp-dataset-api/apierrors" @@ -398,6 +400,27 @@ func (ed *EditionUpdate) PublishLinks(ctx context.Context, host string, versionL return nil } +func ValidateDataset(ctx context.Context, dataset *Dataset) error { + var invalidFields []string + if dataset.URI != "" { + dataset.URI = strings.TrimSpace(dataset.URI) + datasetURI, err := url.Parse(dataset.URI) + if err != nil { + invalidFields = append(invalidFields, "URI") + log.Event(ctx, "error parsing URI", log.ERROR, log.Error(err)) + } else { + if !strings.Contains(datasetURI.Path, "/datasets") || !strings.Contains(datasetURI.Path, dataset.ID) { + fmt.Println("hello") + invalidFields = append(invalidFields, "URI") + } + } + } + if invalidFields != nil { + return fmt.Errorf("invalid fields: %v", invalidFields) + } + return nil +} + // ValidateVersion checks the content of the version structure func ValidateVersion(version *Version) error { diff --git a/models/dataset_test.go b/models/dataset_test.go index a9350d19..1430322f 100644 --- a/models/dataset_test.go +++ b/models/dataset_test.go @@ -13,6 +13,13 @@ import ( . "github.com/smartystreets/goconvey/convey" ) +func createDataset() Dataset { + return Dataset{ + ID: "123", + URI: "http://localhost:22000/datasets/123", + } +} + var testContext = context.Background() func TestCreateDataset(t *testing.T) { @@ -135,6 +142,63 @@ func TestCreateVersion(t *testing.T) { }) } +func TestValidateDataset(t *testing.T) { + t.Parallel() + + Convey("Unsuccessful validation (false) returned", t, func() { + + Convey("when dataset.URI is unable to be parsed into url format", func() { + dataset := createDataset() + dataset.URI = ":foo" + fmt.Println(dataset.URI) + validationErr := ValidateDataset(testContext, &dataset) + So(validationErr, ShouldNotBeNil) + So(validationErr.Error(), ShouldResemble, errors.New("invalid fields: [URI]").Error()) + }) + + Convey("when dataset.URI does not contain 'datasets' path", func() { + dataset := createDataset() + dataset.URI = "/123" + validationErr := ValidateDataset(testContext, &dataset) + So(validationErr, ShouldNotBeNil) + So(validationErr.Error(), ShouldResemble, errors.New("invalid fields: [URI]").Error()) + }) + + Convey("when dataset.URI does not contain 'id' path", func() { + dataset := createDataset() + dataset.URI = "http://localhost:22000/datasets" + validationErr := ValidateDataset(testContext, &dataset) + So(validationErr, ShouldNotBeNil) + So(validationErr.Error(), ShouldResemble, errors.New("invalid fields: [URI]").Error()) + }) + + }) + + Convey("Successful validation (true) returned", t, func() { + + Convey("when dataset.URI contains its path in appropriate url format ", func() { + dataset := createDataset() + dataset.ID = "123" + dataset.URI = "http://localhost:22000/datasets/123/breadcrumbs" + validationErr := ValidateDataset(testContext, &dataset) + So(validationErr, ShouldBeNil) + }) + }) + + Convey("Successful validation (true) returned", t, func() { + + Convey("when dataset.URI contains whitespace it should not return an error ", func() { + dataset := createDataset() + dataset.ID = "123" + dataset.URI = " http://localhost:22000/datasets/123/breadcrumbs " + validationErr := ValidateDataset(testContext, &dataset) + So(validationErr, ShouldBeNil) + So(dataset.URI, ShouldEqual, "http://localhost:22000/datasets/123/breadcrumbs") + }) + }) + +} + func TestValidateVersion(t *testing.T) { t.Parallel() Convey("Successfully return without any errors", t, func() { diff --git a/mongo/dataset_store.go b/mongo/dataset_store.go index 23366bdc..034b0100 100644 --- a/mongo/dataset_store.go +++ b/mongo/dataset_store.go @@ -441,6 +441,11 @@ func createDatasetUpdateQuery(ctx context.Context, id string, dataset *models.Da updates["next.uri"] = dataset.URI } + if err := models.ValidateDataset(ctx, dataset); err != nil { + log.Event(ctx, "failed validation check to create dataset", log.ERROR, log.Error(err)) + return nil + } + log.Event(ctx, "built update query for dataset resource", log.INFO, log.Data{"dataset_id": id, "dataset": dataset, "updates": updates}) return updates diff --git a/mongo/dataset_test.go b/mongo/dataset_test.go index 17d5cd20..8338787f 100644 --- a/mongo/dataset_test.go +++ b/mongo/dataset_test.go @@ -197,7 +197,7 @@ func TestDatasetUpdateQuery(t *testing.T) { "next.release_frequency": "yearly", "next.theme": "construction", "next.title": "CPI", - "next.uri": "http://ons.gov.uk/dataset/123/landing-page", + "next.uri": "http://ons.gov.uk/datasets/123/landing-page", } dataset := &models.Dataset{ @@ -225,7 +225,7 @@ func TestDatasetUpdateQuery(t *testing.T) { ReleaseFrequency: "yearly", Theme: "construction", Title: "CPI", - URI: "http://ons.gov.uk/dataset/123/landing-page", + URI: "http://ons.gov.uk/datasets/123/landing-page", } selector := createDatasetUpdateQuery(testContext, "123", dataset, models.CreatedState) diff --git a/service/initialise.go b/service/initialise.go index 02eea363..968a2c4c 100644 --- a/service/initialise.go +++ b/service/initialise.go @@ -60,13 +60,13 @@ func (e *ExternalServiceList) GetProducer(ctx context.Context, cfg *config.Confi } // GetGraphDB returns a graphDB (only if observation and private endpoint are enabled) -func (e *ExternalServiceList) GetGraphDB(ctx context.Context) (store.GraphDB, error) { - graphDB, err := e.Init.DoGetGraphDB(ctx) +func (e *ExternalServiceList) GetGraphDB(ctx context.Context) (store.GraphDB, Closer, error) { + graphDB, graphDBErrorConsumer, err := e.Init.DoGetGraphDB(ctx) if err != nil { - return nil, err + return nil, nil, err } e.Graph = true - return graphDB, nil + return graphDB, graphDBErrorConsumer, nil } // GetMongoDB returns a mongodb health client and dataset mongo object @@ -104,8 +104,15 @@ func (e *Init) DoGetKafkaProducer(ctx context.Context, cfg *config.Configuration } // DoGetGraphDB creates a new GraphDB -func (e *Init) DoGetGraphDB(ctx context.Context) (store.GraphDB, error) { - return graph.New(ctx, graph.Subsets{Observation: true, Instance: true}) +func (e *Init) DoGetGraphDB(ctx context.Context) (store.GraphDB, Closer, error) { + graphDB, err := graph.New(ctx, graph.Subsets{Observation: true, Instance: true}) + if err != nil { + return nil, nil, err + } + + graphDBErrorConsumer := graph.NewLoggingErrorConsumer(ctx, graphDB.ErrorChan()) + + return graphDB, graphDBErrorConsumer, nil } // DoGetMongoDB returns a MongoDB diff --git a/service/interfaces.go b/service/interfaces.go index 2f083117..4b26657c 100644 --- a/service/interfaces.go +++ b/service/interfaces.go @@ -13,13 +13,14 @@ import ( //go:generate moq -out mock/initialiser.go -pkg mock . Initialiser //go:generate moq -out mock/server.go -pkg mock . HTTPServer //go:generate moq -out mock/healthcheck.go -pkg mock . HealthChecker +//go:generate moq -out mock/closer.go -pkg mock . Closer // Initialiser defines the methods to initialise external services type Initialiser interface { DoGetHTTPServer(bindAddr string, router http.Handler) HTTPServer DoGetHealthCheck(cfg *config.Configuration, buildTime, gitCommit, version string) (HealthChecker, error) DoGetKafkaProducer(ctx context.Context, cfg *config.Configuration) (kafka.IProducer, error) - DoGetGraphDB(ctx context.Context) (store.GraphDB, error) + DoGetGraphDB(ctx context.Context) (store.GraphDB, Closer, error) DoGetMongoDB(ctx context.Context, cfg *config.Configuration) (store.MongoDB, error) } @@ -36,3 +37,8 @@ type HealthChecker interface { Stop() AddCheck(name string, checker healthcheck.Checker) (err error) } + +// Closer defines the required methods for a closable resource +type Closer interface { + Close(ctx context.Context) error +} diff --git a/service/mock/closer.go b/service/mock/closer.go new file mode 100644 index 00000000..5d4d2c94 --- /dev/null +++ b/service/mock/closer.go @@ -0,0 +1,73 @@ +// Code generated by moq; DO NOT EDIT. +// github.com/matryer/moq + +package mock + +import ( + "context" + "sync" +) + +var ( + lockCloserMockClose sync.RWMutex +) + +// CloserMock is a mock implementation of service.Closer. +// +// func TestSomethingThatUsesCloser(t *testing.T) { +// +// // make and configure a mocked service.Closer +// mockedCloser := &CloserMock{ +// CloseFunc: func(ctx context.Context) error { +// panic("mock out the Close method") +// }, +// } +// +// // use mockedCloser in code that requires service.Closer +// // and then make assertions. +// +// } +type CloserMock struct { + // CloseFunc mocks the Close method. + CloseFunc func(ctx context.Context) error + + // calls tracks calls to the methods. + calls struct { + // Close holds details about calls to the Close method. + Close []struct { + // Ctx is the ctx argument value. + Ctx context.Context + } + } +} + +// Close calls CloseFunc. +func (mock *CloserMock) Close(ctx context.Context) error { + if mock.CloseFunc == nil { + panic("CloserMock.CloseFunc: method is nil but Closer.Close was just called") + } + callInfo := struct { + Ctx context.Context + }{ + Ctx: ctx, + } + lockCloserMockClose.Lock() + mock.calls.Close = append(mock.calls.Close, callInfo) + lockCloserMockClose.Unlock() + return mock.CloseFunc(ctx) +} + +// CloseCalls gets all the calls that were made to Close. +// Check the length with: +// len(mockedCloser.CloseCalls()) +func (mock *CloserMock) CloseCalls() []struct { + Ctx context.Context +} { + var calls []struct { + Ctx context.Context + } + lockCloserMockClose.RLock() + calls = mock.calls.Close + lockCloserMockClose.RUnlock() + return calls +} diff --git a/service/mock/initialiser.go b/service/mock/initialiser.go index 42396962..a049b5a4 100644 --- a/service/mock/initialiser.go +++ b/service/mock/initialiser.go @@ -21,7 +21,7 @@ var ( lockInitialiserMockDoGetMongoDB sync.RWMutex ) -// Ensure, that InitialiserMock does implement service.Initialiser. +// Ensure, that InitialiserMock does implement Initialiser. // If this is not the case, regenerate this file with moq. var _ service.Initialiser = &InitialiserMock{} @@ -31,7 +31,7 @@ var _ service.Initialiser = &InitialiserMock{} // // // make and configure a mocked service.Initialiser // mockedInitialiser := &InitialiserMock{ -// DoGetGraphDBFunc: func(ctx context.Context) (store.GraphDB, error) { +// DoGetGraphDBFunc: func(ctx context.Context) (store.GraphDB, service.Closer, error) { // panic("mock out the DoGetGraphDB method") // }, // DoGetHTTPServerFunc: func(bindAddr string, router http.Handler) service.HTTPServer { @@ -54,7 +54,7 @@ var _ service.Initialiser = &InitialiserMock{} // } type InitialiserMock struct { // DoGetGraphDBFunc mocks the DoGetGraphDB method. - DoGetGraphDBFunc func(ctx context.Context) (store.GraphDB, error) + DoGetGraphDBFunc func(ctx context.Context) (store.GraphDB, service.Closer, error) // DoGetHTTPServerFunc mocks the DoGetHTTPServer method. DoGetHTTPServerFunc func(bindAddr string, router http.Handler) service.HTTPServer @@ -111,7 +111,7 @@ type InitialiserMock struct { } // DoGetGraphDB calls DoGetGraphDBFunc. -func (mock *InitialiserMock) DoGetGraphDB(ctx context.Context) (store.GraphDB, error) { +func (mock *InitialiserMock) DoGetGraphDB(ctx context.Context) (store.GraphDB, service.Closer, error) { if mock.DoGetGraphDBFunc == nil { panic("InitialiserMock.DoGetGraphDBFunc: method is nil but Initialiser.DoGetGraphDB was just called") } diff --git a/service/service.go b/service/service.go index 3b7eacab..ea11c1cf 100644 --- a/service/service.go +++ b/service/service.go @@ -36,6 +36,7 @@ type Service struct { config *config.Configuration serviceList *ExternalServiceList graphDB store.GraphDB + graphDBErrorConsumer Closer mongoDB store.MongoDB generateDownloadsProducer kafka.IProducer identityClient *clientsidentity.Client @@ -78,6 +79,11 @@ func (svc *Service) SetGraphDB(graphDB store.GraphDB) { svc.graphDB = graphDB } +// SetGraphDBErrorConsumer sets the graphDB error consumer for a service +func (svc *Service) SetGraphDBErrorConsumer(graphDBErrorConsumer Closer) { + svc.graphDBErrorConsumer = graphDBErrorConsumer +} + // Run the service func (svc *Service) Run(ctx context.Context, buildTime, gitCommit, version string, svcErrors chan error) (err error) { @@ -95,7 +101,7 @@ func (svc *Service) Run(ctx context.Context, buildTime, gitCommit, version strin "EnablePrivateEndpoints": svc.config.EnablePrivateEndpoints, }) } else { - svc.graphDB, err = svc.serviceList.GetGraphDB(ctx) + svc.graphDB, svc.graphDBErrorConsumer, err = svc.serviceList.GetGraphDB(ctx) if err != nil { log.Event(ctx, "failed to initialise graph driver", log.FATAL, log.Error(err)) return err @@ -260,6 +266,11 @@ func (svc *Service) Close(ctx context.Context) error { log.Event(shutdownContext, "failed to close graph db", log.ERROR, log.Error(err)) hasShutdownError = true } + + if err := svc.graphDBErrorConsumer.Close(shutdownContext); err != nil { + log.Event(shutdownContext, "failed to close graph db error consumer", log.ERROR, log.Error(err)) + hasShutdownError = true + } } }() diff --git a/service/service_test.go b/service/service_test.go index b7216cf8..1ae34c0a 100644 --- a/service/service_test.go +++ b/service/service_test.go @@ -47,8 +47,8 @@ var funcDoGetMongoDBErr = func(ctx context.Context, cfg *config.Configuration) ( return nil, errMongo } -var funcDoGetGraphDBErr = func(ctx context.Context) (store.GraphDB, error) { - return nil, errGraph +var funcDoGetGraphDBErr = func(ctx context.Context) (store.GraphDB, service.Closer, error) { + return nil, nil, errGraph } var funcDoGetKafkaProducerErr = func(ctx context.Context, cfg *config.Configuration) (kafka.IProducer, error) { @@ -99,8 +99,11 @@ func TestRun(t *testing.T) { return &storeMock.MongoDBMock{}, nil } - funcDoGetGraphDBOk := func(ctx context.Context) (store.GraphDB, error) { - return &storeMock.GraphDBMock{}, nil + funcDoGetGraphDBOk := func(ctx context.Context) (store.GraphDB, service.Closer, error) { + var funcClose = func(ctx context.Context) error { + return nil + } + return &storeMock.GraphDBMock{}, &serviceMock.CloserMock{CloseFunc: funcClose}, nil } funcDoGetKafkaProducerOk := func(ctx context.Context, cfg *config.Configuration) (kafka.IProducer, error) { @@ -370,6 +373,10 @@ func TestClose(t *testing.T) { CloseFunc: funcClose, } + graphErrorConsumerMock := &serviceMock.CloserMock{ + CloseFunc: funcClose, + } + // Kafka producer will fail if healthcheck or http server are not stopped kafkaProducerMock := &kafkatest.IProducerMock{ ChannelsFunc: func() *kafka.ProducerChannels { @@ -405,12 +412,14 @@ func TestClose(t *testing.T) { svc.SetDownloadsProducer(kafkaProducerMock) svc.SetMongoDB(mongoMock) svc.SetGraphDB(graphMock) + svc.SetGraphDBErrorConsumer(graphErrorConsumerMock) err = svc.Close(context.Background()) So(err, ShouldBeNil) So(len(hcMock.StopCalls()), ShouldEqual, 1) So(len(serverMock.ShutdownCalls()), ShouldEqual, 1) So(len(mongoMock.CloseCalls()), ShouldEqual, 1) So(len(graphMock.CloseCalls()), ShouldEqual, 1) + So(len(graphErrorConsumerMock.CloseCalls()), ShouldEqual, 1) So(len(kafkaProducerMock.CloseCalls()), ShouldEqual, 1) }) @@ -428,6 +437,7 @@ func TestClose(t *testing.T) { svc.SetDownloadsProducer(kafkaProducerMock) svc.SetMongoDB(mongoMock) svc.SetGraphDB(graphMock) + svc.SetGraphDBErrorConsumer(graphErrorConsumerMock) err = svc.Close(context.Background()) So(err, ShouldNotBeNil) So(err.Error(), ShouldResemble, "failed to shutdown gracefully") @@ -435,8 +445,8 @@ func TestClose(t *testing.T) { So(len(failingserverMock.ShutdownCalls()), ShouldEqual, 1) So(len(mongoMock.CloseCalls()), ShouldEqual, 1) So(len(graphMock.CloseCalls()), ShouldEqual, 1) + So(len(graphErrorConsumerMock.CloseCalls()), ShouldEqual, 1) So(len(kafkaProducerMock.CloseCalls()), ShouldEqual, 1) - }) }) }