From 515292c5d2c9d82575adc34e44f072a687367c7d Mon Sep 17 00:00:00 2001 From: Richard Bull Date: Tue, 4 Feb 2025 18:15:58 +0000 Subject: [PATCH 1/4] SAN-219 Update HandleHealthCheckFinanceSystem to use new IssuerGatewayHealthcheckFinanceSystem - CheckScheduledMaintenance --- .dockerignore | 2 +- go.sum | 35 ++++++ handlers/healthcheck_finance.go | 101 ++--------------- issuer_gateway/api/healthcheck_finance.go | 9 ++ .../api/healthcheck_finance_impl.go | 102 ++++++++++++++++++ 5 files changed, 153 insertions(+), 96 deletions(-) create mode 100644 issuer_gateway/api/healthcheck_finance.go create mode 100644 issuer_gateway/api/healthcheck_finance_impl.go diff --git a/.dockerignore b/.dockerignore index 0d27d46..dcb84bd 100644 --- a/.dockerignore +++ b/.dockerignore @@ -7,6 +7,7 @@ !e5 !handlers !interceptors +!issuer_gateway !middleware !mocks !models @@ -18,4 +19,3 @@ !go.mod !go.sum !main.go -!issuer_gateway diff --git a/go.sum b/go.sum index a70e140..35f20e5 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,7 @@ +cloud.google.com/go v0.34.0 h1:eOI3/cP2VTU6uZLDYAoic+eyzzB9YyGmJ7eIjl8rOPg= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go/compute v1.7.0 h1:v/k9Eueb8aAJ0vZuxKMrgm6kPhCLZU9HxFU+AFDs9Uk= +cloud.google.com/go/compute v1.7.0/go.mod h1:435lt8av5oL9P3fv1OEzSbSUe+ybHXGMPQHHZWZxy9U= github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798 h1:2T/jmrHeTezcCM58lvEQXs0UpQJCo5SoGAcg+mbSTIg= github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= github.com/Shopify/sarama v1.23.1 h1:XxJBCZEoWJtoWjf/xRbmGUpAmTZGnuuF0ON0EvxxBrs= @@ -27,6 +30,7 @@ github.com/companieshouse/go-session-handler v0.1.5/go.mod h1:2lBRj2gEzuXNdgxHqH github.com/companieshouse/gofigure v0.1.0/go.mod h1:W7NZ4kQdDXqvqK1f7EKTc+pnnqpF1b7RcqRa17yAy2Q= github.com/companieshouse/gofigure v0.1.4 h1:BN7Dqn0xvNHwC+KHOUHigwP7ajkfHORos3hKRtEACUU= github.com/companieshouse/gofigure v0.1.4/go.mod h1:lBAsI13q21rMce+pO7x4xUYAXzO0MchuDsZUbCs0Yng= +github.com/companieshouse/htmlform v0.1.0 h1:oozdJabOBTFNgx1j4J4ojCD/3CTqcA7DEoiDKLZnLPY= github.com/companieshouse/htmlform v0.1.0/go.mod h1:fWScPVYjGyeBhYwppGaGRDtCQ5hMd3t3Q+0I6HaUZT4= github.com/companieshouse/penalty-payment-api-core v1.0.8 h1:ShdZro7HsFe8SoRRpJezAMH6OEM/AifNrWtFM5T54Ek= github.com/companieshouse/penalty-payment-api-core v1.0.8/go.mod h1:g0AHck3Ez+m3aqOdZBMLq+6GeNUwZCC+IuAXYzj6FnI= @@ -43,9 +47,11 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 h1:YEetp8 github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= +github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 h1:clC1lXBpe2kTj2VHdaIu9ajZQe4kcEY9j0NsnDDBZ3o= github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM= github.com/elodina/go-avro v0.0.0-20160406082632-0c8185d9a3ba h1:QkK2L3uvEaZJ40iFZbiMKz/yQF/MI2uaNO2iyV/ve6w= github.com/elodina/go-avro v0.0.0-20160406082632-0c8185d9a3ba/go.mod h1:3A7SOsr8WBIpkWUsqzMpR3tIQbanKqxZcis2GSl12Nk= +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU= @@ -53,6 +59,7 @@ github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho= github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= +github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= @@ -71,20 +78,27 @@ github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 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/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +github.com/gorilla/pat v1.0.1 h1:OeSoj6sffw4/majibAY2BAUsXjNP7fEE+w30KickaL4= github.com/gorilla/pat v1.0.1/go.mod h1:YeAe0gNeiNT5hoiZRI4yiOky6jVdNvfO2N6Kav/HmxY= +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/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= +github.com/gorilla/sessions v1.2.0 h1:S7P+1Hm5V/AT9cjEcUD5uDaQSX0OE577aCXgoaKpYbQ= github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/ian-kent/envconf v0.0.0-20141026121121-c19809918c02 h1:dU8zq210pt1b71X8xh9GOxC7uBHNtQ9BYC+Lb6SA/mA= github.com/ian-kent/envconf v0.0.0-20141026121121-c19809918c02/go.mod h1:1m5fo3aKG2moYtGHC4I2nFkXmG97+vCeaEIWC+mXTSI= +github.com/ian-kent/gofigure v0.0.0-20170502192241-c9dc3a1359af h1:oxo0HMosJCLANWHuCqK4Q5osVtEhNE+eAttHsz9lbV8= github.com/ian-kent/gofigure v0.0.0-20170502192241-c9dc3a1359af/go.mod h1:dDnv8KaO0exx5ZUA/gvkuUvj8aX7njir7sOwoAk8MKo= github.com/jarcoal/httpmock v1.0.4 h1:jp+dy/+nonJE4g4xbVtl9QdrUNbn6/3hDT5R4nDIZnA= github.com/jarcoal/httpmock v1.0.4/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik= @@ -96,12 +110,14 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV github.com/justinas/alice v0.0.0-20171023064455-03f45bd4b7da/go.mod h1:oLH0CmIaxCGXD67VKGR5AacGXZSMznlmeqM8RzPrcY8= 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/justinas/nosurf v0.0.0-20190416172904-05988550ea18 h1:ci3v0mUqcCewO25ntt7hprt2ZMNA0AWI6s6qV0rSpc0= github.com/justinas/nosurf v0.0.0-20190416172904-05988550ea18/go.mod h1:Aucr5I5chr4OCuuVB4LTuHVrKHBuyRSo7vM2hqrcb7E= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY= github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU= 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/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -129,12 +145,14 @@ github.com/pierrec/lz4 v0.0.0-20190327172049-315a67e90e41 h1:GeinFsrjWz97fAxVUEd github.com/pierrec/lz4 v0.0.0-20190327172049-315a67e90e41/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/profile v1.2.1 h1:F++O52m40owAmADcojzM+9gyjmMOY/T4oYJkgFDH8RE= github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= +github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da h1:p3Vo3i64TCLY7gIfzeQaUJ+kppEO5WQG3cL8iE8tGHU= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs= @@ -153,10 +171,13 @@ github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMT github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/unrolled/render v1.0.1 h1:VDDnQQVfBMsOsp3VaCJszSO0nkBIVEYoPWeRThk9spY= github.com/unrolled/render v1.0.1/go.mod h1:gN9T0NhL4Bfbwu8ann7Ry/TGHYfosul+J0obPf6NBdM= github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI= github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= +github.com/wvanbergen/kafka v0.0.0-20171203153745-e2edea948ddf h1:TOV5PC6fIWwFOFra9xJfRXZcL2pLhMI8oNuDugNxg9Q= github.com/wvanbergen/kafka v0.0.0-20171203153745-e2edea948ddf/go.mod h1:nxx7XRXbR9ykhnC8lXqQyJS0rfvJGxKyKw/sT1YOttg= +github.com/wvanbergen/kazoo-go v0.0.0-20180202103751-f72d8611297a h1:ILoU84rj4AQ3q6cjQvtb9jBjx4xzR/Riq/zYhmDQiOk= github.com/wvanbergen/kazoo-go v0.0.0-20180202103751-f72d8611297a/go.mod h1:vQQATAGxVK20DC1rRubTJbZDDhhpA4QfU02pMdPxGO4= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= @@ -166,11 +187,14 @@ github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23n github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM= github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs= github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= +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= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqToslyjUt3VOPF4J7aK/3MPcK7xp3PDk= github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4= +github.com/yuin/goldmark v1.3.5 h1:dPmz1Snjq0kmkz159iL7S6WzdahUTHnHB5M56WFVifs= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.mongodb.org/mongo-driver v1.8.0/go.mod h1:0sQWfOeY63QTntERDJJ/0SuKK0T1uVSgKCuAROlKEPY= go.mongodb.org/mongo-driver v1.10.2 h1:4Wk3cnqOrQCn0P92L3/mmurMxzdvWWs5J9jinAVKD+k= @@ -184,6 +208,8 @@ golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -222,6 +248,8 @@ golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q= +golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -237,9 +265,12 @@ golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= @@ -248,7 +279,9 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io= google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +gopkg.in/bluesuncorp/validator.v5 v5.10.3 h1:clgxLhQVQIE5krWHyYuqJralvQ9SkkTh3AdZGeQL2D4= gopkg.in/bluesuncorp/validator.v5 v5.10.3/go.mod h1:ScQmud/GM3iSR85jRE+8BI8E8oFv5oj4qyd5Xaw7hgE= +gopkg.in/bsm/sarama-cluster.v2 v2.1.15 h1:iELfaYDWd+x3wz4j/Z48fTx3idGITVePYf5Fzr/d1XU= gopkg.in/bsm/sarama-cluster.v2 v2.1.15/go.mod h1:PH+cn1N1hKueFCL+6Kz/HLj3ARW4Oop7WH3u0Ivp14w= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= @@ -280,5 +313,7 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +rsc.io/quote/v3 v3.1.0 h1:9JKUTTIUgS6kzR9mK1YuGKv6Nl+DijDNIc0ghT58FaY= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= +rsc.io/sampler v1.3.0 h1:7uVkIFmeBqHfdjD+gZwtXXI+RODJ2Wc4O7MPEh/QiW4= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/handlers/healthcheck_finance.go b/handlers/healthcheck_finance.go index 8aaca45..f1773e4 100644 --- a/handlers/healthcheck_finance.go +++ b/handlers/healthcheck_finance.go @@ -3,36 +3,23 @@ package handlers import ( "fmt" "net/http" - "strconv" - "time" "github.com/companieshouse/chs.go/log" "github.com/companieshouse/penalty-payment-api-core/models" - "github.com/companieshouse/penalty-payment-api/config" + "github.com/companieshouse/penalty-payment-api/issuer_gateway/api" "github.com/companieshouse/penalty-payment-api/utils" ) // HandleHealthCheckFinanceSystem checks whether the e5 system is available to take requests func HandleHealthCheckFinanceSystem(w http.ResponseWriter, r *http.Request) { - cfg, err := config.Get() - if err != nil { - log.ErrorR(r, fmt.Errorf("error returning config: [%v]", err)) - m := models.NewMessageResponse("failed to get maintenance times from config") - utils.WriteJSONWithStatus(w, r, m, http.StatusInternalServerError) - return - } - - currentTime := time.Now() - var systemUnavailable bool - var systemAvailableTime time.Time - // Check for weekly downtime - systemAvailableTime, systemUnavailable = checkWeeklyDownTime(cfg, - currentTime, systemAvailableTime, systemUnavailable) + ig := api.IssuerGatewayHealthcheckFinanceSystem{} + systemAvailableTime, systemUnavailable, parseError := ig.CheckScheduledMaintenance() - // Check for planned maintenance - systemAvailableTime, systemUnavailable, parseError := checkPlannedMaintenance(w, r, cfg, currentTime, systemAvailableTime, systemUnavailable) if parseError { + log.ErrorR(r, fmt.Errorf("parseError from CheckScheduledMaintenance: [%v]", parseError)) + m := models.NewMessageResponse("failed to check scheduled maintenance") + utils.WriteJSONWithStatus(w, r, m, http.StatusInternalServerError) return } @@ -46,79 +33,3 @@ func HandleHealthCheckFinanceSystem(w http.ResponseWriter, r *http.Request) { m := models.NewMessageResponse("HEALTHY") utils.WriteJSON(w, r, m) } - -func checkPlannedMaintenance(w http.ResponseWriter, - r *http.Request, - cfg *config.Config, - currentTime time.Time, - systemAvailableTime time.Time, - systemUnavailable bool) (time.Time, bool, bool) { - if isPlannedMaintenanceCheckRequired(cfg) { - timeDateLayout := "02 Jan 06 15:04 MST" - maintenanceStart, err := time.Parse(timeDateLayout, cfg.PlannedMaintenanceStart) - if err != nil { - log.ErrorR(r, fmt.Errorf("error parsing Maintenance Start time: [%v]", err)) - w.WriteHeader(http.StatusInternalServerError) - return time.Time{}, false, true - } - maintenanceEnd, err := time.Parse(timeDateLayout, cfg.PlannedMaintenanceEnd) - if err != nil { - log.ErrorR(r, fmt.Errorf("error parsing Maintenance End time: [%v]", err)) - w.WriteHeader(http.StatusInternalServerError) - return time.Time{}, false, true - } - - if maintenanceEnd.After(currentTime) && maintenanceStart.Before(currentTime) && maintenanceEnd.After(systemAvailableTime) { - systemAvailableTime = maintenanceEnd - systemUnavailable = true - } - } - return systemAvailableTime, systemUnavailable, false -} - -func checkWeeklyDownTime(cfg *config.Config, - currentTime time.Time, - systemAvailableTime time.Time, - systemUnavailable bool) (time.Time, bool) { - if isWeeklyMaintenanceTimeCheckRequired(cfg) { - // If the weekday is maintenance day - if currentTime.Weekday() == cfg.WeeklyMaintenanceDay { - - weeklyMaintenanceStartTime := returnWeeklyMaintenanceTime(cfg.WeeklyMaintenanceStartTime[:2], cfg.WeeklyMaintenanceStartTime[2:]) - - weeklyMaintenanceEndTime := returnWeeklyMaintenanceTime(cfg.WeeklyMaintenanceEndTime[:2], cfg.WeeklyMaintenanceEndTime[2:]) - - // Check if time is within maintenance time - if isWithinMaintenanceTime(weeklyMaintenanceEndTime, currentTime, weeklyMaintenanceStartTime) { - systemAvailableTime = weeklyMaintenanceEndTime - systemUnavailable = true - } - } - } - return systemAvailableTime, systemUnavailable -} - -func isPlannedMaintenanceCheckRequired(cfg *config.Config) bool { - return cfg.PlannedMaintenanceStart != "" && cfg.PlannedMaintenanceEnd != "" -} - -func isWithinMaintenanceTime(weeklyMaintenanceEndTime time.Time, currentTime time.Time, weeklyMaintenanceStartTime time.Time) bool { - return weeklyMaintenanceEndTime.After(currentTime) && weeklyMaintenanceStartTime.Before(currentTime) -} - -func isWeeklyMaintenanceTimeCheckRequired(cfg *config.Config) bool { - return cfg.WeeklyMaintenanceStartTime != "" && cfg.WeeklyMaintenanceEndTime != "" -} - -// returnWeeklyMaintenanceTime returns a time.Time format for the current date with the hour and minute set to the arguments passed -func returnWeeklyMaintenanceTime(hour, minute string) time.Time { - currentTime := time.Now() - - intHour, _ := strconv.Atoi(hour) - timeDifferenceInHours := time.Duration(intHour - currentTime.Hour()) - - intMinute, _ := strconv.Atoi(minute) - timeDifferenceInMinutes := time.Duration(intMinute - currentTime.Minute()) - - return currentTime.Add(time.Hour*timeDifferenceInHours + time.Minute*timeDifferenceInMinutes).Round(time.Second) -} diff --git a/issuer_gateway/api/healthcheck_finance.go b/issuer_gateway/api/healthcheck_finance.go new file mode 100644 index 0000000..5796575 --- /dev/null +++ b/issuer_gateway/api/healthcheck_finance.go @@ -0,0 +1,9 @@ +package api + +import ( + "time" +) + +type HealthcheckFinanceSystem interface { + CheckScheduledMaintenance() (time.Time, bool, bool) +} diff --git a/issuer_gateway/api/healthcheck_finance_impl.go b/issuer_gateway/api/healthcheck_finance_impl.go new file mode 100644 index 0000000..041da1a --- /dev/null +++ b/issuer_gateway/api/healthcheck_finance_impl.go @@ -0,0 +1,102 @@ +package api + +import ( + "fmt" + "strconv" + "time" + + "github.com/companieshouse/chs.go/log" + "github.com/companieshouse/penalty-payment-api/config" +) + +var getConfig = func() (*config.Config, error) { + return config.Get() +} + +type IssuerGatewayHealthcheckFinanceSystem struct { +} + +func (ig *IssuerGatewayHealthcheckFinanceSystem) CheckScheduledMaintenance() (time.Time, bool, bool) { + + cfg, err := getConfig() + if err != nil { + err = fmt.Errorf("error getting config for planned maintenance: [%v]", err) + return time.Time{}, false, true + } + + currentTime := time.Now() + var systemUnavailable bool + var systemAvailableTime time.Time + + systemAvailableTime, systemUnavailable = checkWeeklyDownTime(cfg, + currentTime, systemAvailableTime, systemUnavailable) + + if isPlannedMaintenanceCheckRequired(cfg) { + timeDateLayout := "02 Jan 06 15:04 MST" + maintenanceStart, err := time.Parse(timeDateLayout, cfg.PlannedMaintenanceStart) + if err != nil { + log.Error(fmt.Errorf("error parsing Maintenance Start time: [%v]", err)) + return time.Time{}, false, true + } + maintenanceEnd, err := time.Parse(timeDateLayout, cfg.PlannedMaintenanceEnd) + if err != nil { + log.Error(fmt.Errorf("error parsing Maintenance End time: [%v]", err)) + return time.Time{}, false, true + } + + if maintenanceEnd.After(currentTime) && maintenanceStart.Before(currentTime) && maintenanceEnd.After(systemAvailableTime) { + systemAvailableTime = maintenanceEnd + systemUnavailable = true + } + } + return systemAvailableTime, systemUnavailable, false +} + +func checkWeeklyDownTime(cfg *config.Config, + currentTime time.Time, + systemAvailableTime time.Time, + systemUnavailable bool) (time.Time, bool) { + if isWeeklyMaintenanceTimeCheckRequired(cfg) { + // If the weekday is maintenance day + if currentTime.Weekday() == cfg.WeeklyMaintenanceDay { + + weeklyMaintenanceStartTime := returnWeeklyMaintenanceTime(currentTime, cfg.WeeklyMaintenanceStartTime[:2], cfg.WeeklyMaintenanceStartTime[2:]) + + weeklyMaintenanceEndTime := returnWeeklyMaintenanceTime(currentTime, cfg.WeeklyMaintenanceEndTime[:2], cfg.WeeklyMaintenanceEndTime[2:]) + + // Check if time is within maintenance time + if isWithinMaintenanceTime(weeklyMaintenanceEndTime, currentTime, weeklyMaintenanceStartTime) { + systemAvailableTime = weeklyMaintenanceEndTime + systemUnavailable = true + } + } + } + return systemAvailableTime, systemUnavailable +} + +func isWeeklyMaintenanceTimeCheckRequired(cfg *config.Config) bool { + return cfg.WeeklyMaintenanceStartTime != "" && cfg.WeeklyMaintenanceEndTime != "" +} + +// returnWeeklyMaintenanceTime returns a time.Time format for the current date with the hour and minute set to the arguments passed +func returnWeeklyMaintenanceTime(currentTime time.Time, hour, minute string) time.Time { + + intHour, _ := strconv.Atoi(hour) + timeDifferenceInHours := time.Duration(intHour - currentTime.Hour()) + + intMinute, _ := strconv.Atoi(minute) + timeDifferenceInMinutes := time.Duration(intMinute - currentTime.Minute()) + + secondDuration := time.Duration(0 - currentTime.Second()) + nanosecondDuration := time.Duration(0 - currentTime.Nanosecond()) + + return currentTime.Add(time.Hour*timeDifferenceInHours + time.Minute*timeDifferenceInMinutes + time.Second*secondDuration + time.Nanosecond*nanosecondDuration).Round(0) +} + +func isWithinMaintenanceTime(weeklyMaintenanceEndTime time.Time, currentTime time.Time, weeklyMaintenanceStartTime time.Time) bool { + return weeklyMaintenanceEndTime.After(currentTime) && weeklyMaintenanceStartTime.Before(currentTime) +} + +func isPlannedMaintenanceCheckRequired(cfg *config.Config) bool { + return cfg.PlannedMaintenanceStart != "" && cfg.PlannedMaintenanceEnd != "" +} From 9d9057800d1753a555c1d2ae37c63a73b8368783 Mon Sep 17 00:00:00 2001 From: Richard Bull Date: Thu, 6 Feb 2025 15:48:08 +0000 Subject: [PATCH 2/4] SAN-219 Update CheckScheduledMaintenance / Add unit tests * Add Named Function Returns to improve readability * Update returnWeeklyMaintenanceTime to strip seconds, milliseconds and monotonic clock * Update swagger GET /healthcheck/finance-system - 503 Service Unavailable response example --- issuer_gateway/api/healthcheck_finance.go | 2 +- .../api/healthcheck_finance_impl.go | 14 +- .../api/healthcheck_finance_impl_test.go | 447 ++++++++++++++++++ spec/schema.json | 6 +- 4 files changed, 456 insertions(+), 13 deletions(-) create mode 100644 issuer_gateway/api/healthcheck_finance_impl_test.go diff --git a/issuer_gateway/api/healthcheck_finance.go b/issuer_gateway/api/healthcheck_finance.go index 5796575..d0347fa 100644 --- a/issuer_gateway/api/healthcheck_finance.go +++ b/issuer_gateway/api/healthcheck_finance.go @@ -5,5 +5,5 @@ import ( ) type HealthcheckFinanceSystem interface { - CheckScheduledMaintenance() (time.Time, bool, bool) + CheckScheduledMaintenance() (systemAvailableTime time.Time, systemUnavailable bool, parseError bool) } diff --git a/issuer_gateway/api/healthcheck_finance_impl.go b/issuer_gateway/api/healthcheck_finance_impl.go index 041da1a..aaaaf38 100644 --- a/issuer_gateway/api/healthcheck_finance_impl.go +++ b/issuer_gateway/api/healthcheck_finance_impl.go @@ -16,7 +16,7 @@ var getConfig = func() (*config.Config, error) { type IssuerGatewayHealthcheckFinanceSystem struct { } -func (ig *IssuerGatewayHealthcheckFinanceSystem) CheckScheduledMaintenance() (time.Time, bool, bool) { +func (ig *IssuerGatewayHealthcheckFinanceSystem) CheckScheduledMaintenance() (systemAvailableTime time.Time, systemUnavailable bool, parseError bool) { cfg, err := getConfig() if err != nil { @@ -25,14 +25,11 @@ func (ig *IssuerGatewayHealthcheckFinanceSystem) CheckScheduledMaintenance() (ti } currentTime := time.Now() - var systemUnavailable bool - var systemAvailableTime time.Time - systemAvailableTime, systemUnavailable = checkWeeklyDownTime(cfg, - currentTime, systemAvailableTime, systemUnavailable) + systemAvailableTime, systemUnavailable = checkWeeklyDownTime(cfg, currentTime) if isPlannedMaintenanceCheckRequired(cfg) { - timeDateLayout := "02 Jan 06 15:04 MST" + timeDateLayout := time.RFC822 maintenanceStart, err := time.Parse(timeDateLayout, cfg.PlannedMaintenanceStart) if err != nil { log.Error(fmt.Errorf("error parsing Maintenance Start time: [%v]", err)) @@ -52,10 +49,7 @@ func (ig *IssuerGatewayHealthcheckFinanceSystem) CheckScheduledMaintenance() (ti return systemAvailableTime, systemUnavailable, false } -func checkWeeklyDownTime(cfg *config.Config, - currentTime time.Time, - systemAvailableTime time.Time, - systemUnavailable bool) (time.Time, bool) { +func checkWeeklyDownTime(cfg *config.Config, currentTime time.Time) (systemAvailableTime time.Time, systemUnavailable bool) { if isWeeklyMaintenanceTimeCheckRequired(cfg) { // If the weekday is maintenance day if currentTime.Weekday() == cfg.WeeklyMaintenanceDay { diff --git a/issuer_gateway/api/healthcheck_finance_impl_test.go b/issuer_gateway/api/healthcheck_finance_impl_test.go new file mode 100644 index 0000000..9aa8f8d --- /dev/null +++ b/issuer_gateway/api/healthcheck_finance_impl_test.go @@ -0,0 +1,447 @@ +package api + +import ( + "fmt" + "testing" + "time" + + "github.com/companieshouse/penalty-payment-api/config" + . "github.com/smartystreets/goconvey/convey" +) + +func TestUnitIssuerGatewayHealthcheckFinanceSystem_CheckScheduledMaintenance(t *testing.T) { + cfg, _ := config.Get() + currentTime := time.Now() + + Convey("No maintenance config", t, func() { + // Given + + // When + ig := &IssuerGatewayHealthcheckFinanceSystem{} + gotSystemAvailableTime, gotSystemUnavailable, gotParseError := ig.CheckScheduledMaintenance() + + // Then + So(gotSystemAvailableTime, ShouldEqual, time.Time{}) + So(gotSystemUnavailable, ShouldBeFalse) + So(gotParseError, ShouldBeFalse) + }) + + Convey("Current time is before weekly maintenance times", t, func() { + // Given + startHour := currentTime.Hour() - 2 + endHour := startHour + 1 + cfg.WeeklyMaintenanceStartTime = fmt.Sprintf("%d00", startHour) + cfg.WeeklyMaintenanceEndTime = fmt.Sprintf("%d00", endHour) + cfg.WeeklyMaintenanceDay = currentTime.Weekday() + + // When + ig := &IssuerGatewayHealthcheckFinanceSystem{} + gotSystemAvailableTime, gotSystemUnavailable, gotParseError := ig.CheckScheduledMaintenance() + + // Then + So(gotSystemAvailableTime, ShouldEqual, time.Time{}) + So(gotSystemUnavailable, ShouldBeFalse) + So(gotParseError, ShouldBeFalse) + }) + + Convey("Current time is during weekly maintenance times", t, func() { + // Given + endHour := currentTime.Hour() + 1 + cfg.WeeklyMaintenanceStartTime = fmt.Sprintf("%d00", currentTime.Hour()) + cfg.WeeklyMaintenanceEndTime = fmt.Sprintf("%d00", endHour) + cfg.WeeklyMaintenanceDay = currentTime.Weekday() + + // When + ig := &IssuerGatewayHealthcheckFinanceSystem{} + gotSystemAvailableTime, gotSystemUnavailable, gotParseError := ig.CheckScheduledMaintenance() + + // Then + So(gotSystemAvailableTime, ShouldEqual, time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), endHour, 0, 0, 0, currentTime.Location())) + So(gotSystemUnavailable, ShouldBeTrue) + So(gotParseError, ShouldBeFalse) + }) + + Convey("Current time is after weekly maintenance times", t, func() { + // Given + startHour := currentTime.Hour() + 1 + endHour := currentTime.Hour() + 2 + cfg.WeeklyMaintenanceStartTime = fmt.Sprintf("%d00", startHour) + cfg.WeeklyMaintenanceEndTime = fmt.Sprintf("%d00", endHour) + cfg.WeeklyMaintenanceDay = currentTime.Weekday() + + // When + ig := &IssuerGatewayHealthcheckFinanceSystem{} + gotSystemAvailableTime, gotSystemUnavailable, gotParseError := ig.CheckScheduledMaintenance() + + // Then + So(gotSystemAvailableTime, ShouldEqual, time.Time{}) + So(gotSystemUnavailable, ShouldBeFalse) + So(gotParseError, ShouldBeFalse) + }) + + Convey("Planned maintenance times in wrong format", t, func() { + // Given + cfg.WeeklyMaintenanceStartTime = "1900" + cfg.WeeklyMaintenanceEndTime = "1930" + cfg.WeeklyMaintenanceDay = time.Sunday + startTime := currentTime.Add(time.Hour * -4).Truncate(time.Minute).Round(0) + cfg.PlannedMaintenanceStart = startTime.Format(time.RFC3339) + endTime := currentTime.Add(time.Hour * -3).Truncate(time.Minute).Round(0) + cfg.PlannedMaintenanceEnd = endTime.Format(time.RFC3339) + + // When + ig := &IssuerGatewayHealthcheckFinanceSystem{} + gotSystemAvailableTime, gotSystemUnavailable, gotParseError := ig.CheckScheduledMaintenance() + + // Then + So(gotSystemAvailableTime, ShouldEqual, time.Time{}) + So(gotSystemUnavailable, ShouldBeFalse) + So(gotParseError, ShouldBeTrue) + }) + + Convey("Current time is before planned maintenance times", t, func() { + // Given + cfg.WeeklyMaintenanceStartTime = "1900" + cfg.WeeklyMaintenanceEndTime = "1930" + cfg.WeeklyMaintenanceDay = time.Sunday + startTime := currentTime.Add(time.Hour * 3).Truncate(time.Minute).Round(0) + cfg.PlannedMaintenanceStart = startTime.Format(time.RFC822) + endTime := currentTime.Add(time.Hour * 4).Truncate(time.Minute).Round(0) + cfg.PlannedMaintenanceEnd = endTime.Format(time.RFC822) + + // When + ig := &IssuerGatewayHealthcheckFinanceSystem{} + gotSystemAvailableTime, gotSystemUnavailable, gotParseError := ig.CheckScheduledMaintenance() + + // Then + So(gotSystemAvailableTime, ShouldEqual, time.Time{}) + So(gotSystemUnavailable, ShouldBeFalse) + So(gotParseError, ShouldBeFalse) + }) + + Convey("Current time is during planned maintenance times", t, func() { + // Given + cfg.WeeklyMaintenanceStartTime = "1900" + cfg.WeeklyMaintenanceEndTime = "1930" + cfg.WeeklyMaintenanceDay = time.Sunday + startTime := currentTime.Add(time.Minute * -30).Truncate(time.Minute).Round(0) + cfg.PlannedMaintenanceStart = startTime.Format(time.RFC822) + endTime := currentTime.Add(time.Minute * 30).Truncate(time.Minute).Round(0) + cfg.PlannedMaintenanceEnd = endTime.Format(time.RFC822) + + // When + ig := &IssuerGatewayHealthcheckFinanceSystem{} + gotSystemAvailableTime, gotSystemUnavailable, gotParseError := ig.CheckScheduledMaintenance() + + // Then + So(gotSystemAvailableTime, ShouldEqual, endTime) + So(gotSystemUnavailable, ShouldBeTrue) + So(gotParseError, ShouldBeFalse) + }) + + Convey("Current time is after planned maintenance times", t, func() { + // Given + cfg.WeeklyMaintenanceStartTime = "1900" + cfg.WeeklyMaintenanceEndTime = "1930" + cfg.WeeklyMaintenanceDay = time.Sunday + startTime := currentTime.Add(time.Hour * -4).Truncate(time.Minute).Round(0) + cfg.PlannedMaintenanceStart = startTime.Format(time.RFC822) + endTime := currentTime.Add(time.Hour * -3).Truncate(time.Minute).Round(0) + cfg.PlannedMaintenanceEnd = endTime.Format(time.RFC822) + + // When + ig := &IssuerGatewayHealthcheckFinanceSystem{} + gotSystemAvailableTime, gotSystemUnavailable, gotParseError := ig.CheckScheduledMaintenance() + + // Then + So(gotSystemAvailableTime, ShouldEqual, time.Time{}) + So(gotSystemUnavailable, ShouldBeFalse) + So(gotParseError, ShouldBeFalse) + }) + + Convey("Current time is during scheduled maintenance times, planned ends later", t, func() { + // Given + weeklyEndHour := currentTime.Hour() + 1 + cfg.WeeklyMaintenanceStartTime = fmt.Sprintf("%d00", currentTime.Hour()) + cfg.WeeklyMaintenanceEndTime = fmt.Sprintf("%d00", weeklyEndHour) + cfg.WeeklyMaintenanceDay = currentTime.Weekday() + plannedStartTime := currentTime.Add(time.Minute * -1).Truncate(time.Minute).Round(0) + cfg.PlannedMaintenanceStart = plannedStartTime.Format(time.RFC822) + plannedEndTime := currentTime.Add(time.Hour * 2).Truncate(time.Minute).Round(0) + cfg.PlannedMaintenanceEnd = plannedEndTime.Format(time.RFC822) + + // When + ig := &IssuerGatewayHealthcheckFinanceSystem{} + gotSystemAvailableTime, gotSystemUnavailable, gotParseError := ig.CheckScheduledMaintenance() + + // Then + So(gotSystemAvailableTime, ShouldEqual, plannedEndTime) + So(gotSystemUnavailable, ShouldBeTrue) + So(gotParseError, ShouldBeFalse) + }) + + Convey("Current time is during scheduled maintenance times, planned ends earlier", t, func() { + // Given + weeklyEndHour := currentTime.Hour() + 2 + cfg.WeeklyMaintenanceStartTime = fmt.Sprintf("%d00", currentTime.Hour()) + cfg.WeeklyMaintenanceEndTime = fmt.Sprintf("%d00", weeklyEndHour) + cfg.WeeklyMaintenanceDay = currentTime.Weekday() + plannedStartTime := currentTime.Add(time.Hour * -1).Truncate(time.Minute).Round(0) + cfg.PlannedMaintenanceStart = plannedStartTime.Format(time.RFC822) + plannedEndTime := currentTime.Add(time.Hour * 1).Truncate(time.Minute).Round(0) + cfg.PlannedMaintenanceEnd = plannedEndTime.Format(time.RFC822) + + // When + ig := &IssuerGatewayHealthcheckFinanceSystem{} + gotSystemAvailableTime, gotSystemUnavailable, gotParseError := ig.CheckScheduledMaintenance() + + // Then + So(gotSystemAvailableTime, ShouldEqual, time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), weeklyEndHour, 0, 0, 0, currentTime.Location())) + So(gotSystemUnavailable, ShouldBeTrue) + So(gotParseError, ShouldBeFalse) + }) +} + +func TestUnit_checkWeeklyDownTime(t *testing.T) { + Convey("Check weekly down time", t, func() { + type args struct { + cfg *config.Config + currentTime time.Time + } + now := time.Now() + + testCases := []struct { + name string + args args + wantSystemAvailableTime time.Time + wantSystemUnavailable bool + }{ + { + name: "No config", + args: args{ + cfg: &config.Config{}, + currentTime: time.Time{}, + }, + wantSystemAvailableTime: time.Time{}, + wantSystemUnavailable: false, + }, + { + name: "Current time is before weekly maintenance times", + args: args{ + cfg: &config.Config{ + WeeklyMaintenanceStartTime: "1900", + WeeklyMaintenanceEndTime: "1930", + WeeklyMaintenanceDay: now.Weekday(), + }, + currentTime: time.Date(now.Year(), now.Month(), now.Day(), 18, 50, 0, 0, now.Location()), + }, + wantSystemAvailableTime: time.Time{}, + wantSystemUnavailable: false, + }, + { + name: "Current time is during weekly maintenance times", + args: args{ + cfg: &config.Config{ + WeeklyMaintenanceStartTime: "1900", + WeeklyMaintenanceEndTime: "1930", + WeeklyMaintenanceDay: now.Weekday(), + }, + currentTime: time.Date(now.Year(), now.Month(), now.Day(), 19, 5, 0, 0, now.Location()), + }, + wantSystemAvailableTime: time.Date(now.Year(), now.Month(), now.Day(), 19, 30, 0, 0, now.Location()), + wantSystemUnavailable: true, + }, + { + name: "Current time is after weekly maintenance times", + args: args{ + cfg: &config.Config{ + WeeklyMaintenanceStartTime: "1900", + WeeklyMaintenanceEndTime: "1930", + WeeklyMaintenanceDay: now.Weekday(), + }, + currentTime: time.Date(now.Year(), now.Month(), now.Day(), 19, 40, 0, 0, now.Location()), + }, + wantSystemAvailableTime: time.Time{}, + wantSystemUnavailable: false, + }, + } + for _, tc := range testCases { + Convey(tc.name, func() { + gotSystemAvailableTime, gotSystemUnavailable := checkWeeklyDownTime(tc.args.cfg, tc.args.currentTime) + + So(gotSystemAvailableTime, ShouldEqual, tc.wantSystemAvailableTime) + So(gotSystemUnavailable, ShouldEqual, tc.wantSystemUnavailable) + }) + } + }) +} + +func TestUnit_isPlannedMaintenanceCheckRequired(t *testing.T) { + Convey("Is planned maintenance check required", t, func() { + type args struct { + cfg *config.Config + } + testCases := []struct { + name string + args args + want bool + }{ + { + name: "No config", + args: args{ + cfg: &config.Config{}, + }, + want: false, + }, + { + name: "Config with PlannedMaintenanceStart and PlannedMaintenanceEnd", + args: args{ + cfg: &config.Config{ + PlannedMaintenanceStart: "6 Feb 25 17:00 GMT", + PlannedMaintenanceEnd: "6 Feb 25 18:00 GMT", + }, + }, + want: true, + }, + } + for _, tc := range testCases { + Convey(tc.name, func() { + got := isPlannedMaintenanceCheckRequired(tc.args.cfg) + + So(got, ShouldEqual, tc.want) + }) + } + }) +} + +func TestUnit_isWeeklyMaintenanceTimeCheckRequired(t *testing.T) { + Convey("Is weekly maintenance time check required", t, func() { + type args struct { + cfg *config.Config + } + testCases := []struct { + name string + args args + want bool + }{ + { + name: "Weekly maintenance time check not required", + args: args{ + cfg: &config.Config{}, + }, + want: false, + }, + { + name: "Weekly maintenance time check required", + args: args{ + cfg: &config.Config{ + WeeklyMaintenanceStartTime: "1900", + WeeklyMaintenanceEndTime: "1930", + WeeklyMaintenanceDay: 0, + }, + }, + want: true, + }, + } + for _, tc := range testCases { + Convey(tc.name, func() { + got := isWeeklyMaintenanceTimeCheckRequired(tc.args.cfg) + + So(got, ShouldEqual, tc.want) + }) + } + }) +} + +func TestUnit_isWithinMaintenanceTime(t *testing.T) { + Convey("Is within maintenance time", t, func() { + type args struct { + weeklyMaintenanceEndTime time.Time + currentTime time.Time + weeklyMaintenanceStartTime time.Time + } + testCases := []struct { + name string + args args + want bool + }{ + { + name: "Current time is before weekly maintenance times", + args: args{ + weeklyMaintenanceEndTime: time.Date(2025, 2, 9, 19, 30, 0, 0, time.UTC), + currentTime: time.Date(2025, 2, 6, 19, 5, 0, 0, time.UTC), + weeklyMaintenanceStartTime: time.Date(2025, 2, 9, 19, 0, 0, 0, time.UTC), + }, + want: false, + }, + { + name: "Current time is during weekly maintenance times", + args: args{ + weeklyMaintenanceEndTime: time.Date(2025, 2, 9, 19, 30, 0, 0, time.UTC), + currentTime: time.Date(2025, 2, 9, 19, 5, 0, 0, time.UTC), + weeklyMaintenanceStartTime: time.Date(2025, 2, 9, 19, 0, 0, 0, time.UTC), + }, + want: true, + }, + { + name: "Current time is after weekly maintenance times", + args: args{ + weeklyMaintenanceEndTime: time.Date(2025, 2, 9, 19, 30, 0, 0, time.UTC), + currentTime: time.Date(2025, 2, 10, 19, 5, 0, 0, time.UTC), + weeklyMaintenanceStartTime: time.Date(2025, 2, 9, 19, 0, 0, 0, time.UTC), + }, + want: false, + }, + } + for _, tc := range testCases { + Convey(tc.name, func() { + got := isWithinMaintenanceTime(tc.args.weeklyMaintenanceEndTime, tc.args.currentTime, tc.args.weeklyMaintenanceStartTime) + + So(got, ShouldEqual, tc.want) + }) + } + }) +} + +func TestUnit_returnWeeklyMaintenanceTime(t *testing.T) { + Convey("Return weekly maintenance time", t, func() { + type args struct { + currentTime time.Time + hour string + minute string + } + now := time.Now() + + testCases := []struct { + name string + args args + want time.Time + }{ + { + name: "Success WEEKLY_MAINTENANCE_START_TIME=1900", + args: args{ + currentTime: now, + hour: "19", + minute: "00", + }, + want: time.Date(now.Year(), now.Month(), now.Day(), 19, 0, 0, 0, now.Location()), + }, + { + name: "Success WEEKLY_MAINTENANCE_END_TIME=1930", + args: args{ + currentTime: now, + hour: "19", + minute: "30", + }, + want: time.Date(now.Year(), now.Month(), now.Day(), 19, 30, 0, 0, now.Location()), + }, + } + for _, tc := range testCases { + Convey(tc.name, func() { + got := returnWeeklyMaintenanceTime(tc.args.currentTime, tc.args.hour, tc.args.minute) + + So(got, ShouldEqual, tc.want) + }) + } + }) +} diff --git a/spec/schema.json b/spec/schema.json index 24dbd71..9bbfaae 100644 --- a/spec/schema.json +++ b/spec/schema.json @@ -256,10 +256,12 @@ "type": "object", "properties": { "message": { - "type": "string" + "type": "string", + "example": "UNHEALTHY - PLANNED MAINTENANCE" }, "maintenance_end_time": { - "type": "string" + "type": "string", + "format": "date-time" } } }, From 3455187c4733d9c4435d35729e34153bd4bde8d5 Mon Sep 17 00:00:00 2001 From: Richard Bull Date: Thu, 6 Feb 2025 17:10:59 +0000 Subject: [PATCH 3/4] SAN-219 Fix build error: getConfig redeclared in this block --- issuer_gateway/api/healthcheck_finance_impl.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/issuer_gateway/api/healthcheck_finance_impl.go b/issuer_gateway/api/healthcheck_finance_impl.go index aaaaf38..0c1d00e 100644 --- a/issuer_gateway/api/healthcheck_finance_impl.go +++ b/issuer_gateway/api/healthcheck_finance_impl.go @@ -9,16 +9,11 @@ import ( "github.com/companieshouse/penalty-payment-api/config" ) -var getConfig = func() (*config.Config, error) { - return config.Get() -} - type IssuerGatewayHealthcheckFinanceSystem struct { } func (ig *IssuerGatewayHealthcheckFinanceSystem) CheckScheduledMaintenance() (systemAvailableTime time.Time, systemUnavailable bool, parseError bool) { - - cfg, err := getConfig() + cfg, err := config.Get() if err != nil { err = fmt.Errorf("error getting config for planned maintenance: [%v]", err) return time.Time{}, false, true From ef528dc493ae34ea5ed580ec0e4885a6d1c88e25 Mon Sep 17 00:00:00 2001 From: Richard Bull Date: Fri, 7 Feb 2025 11:39:53 +0000 Subject: [PATCH 4/4] SAN-219 Update following acallaghan-ch comment - remove the HealthcheckFinanceSystem interface * https://github.com/companieshouse/penalty-payment-api/pull/46#discussion_r1946207055 --- handlers/healthcheck_finance.go | 3 +- issuer_gateway/api/healthcheck_finance.go | 83 ++++++++++++++++- .../api/healthcheck_finance_impl.go | 91 ------------------- ...pl_test.go => healthcheck_finance_test.go} | 32 +++---- 4 files changed, 93 insertions(+), 116 deletions(-) delete mode 100644 issuer_gateway/api/healthcheck_finance_impl.go rename issuer_gateway/api/{healthcheck_finance_impl_test.go => healthcheck_finance_test.go} (93%) diff --git a/handlers/healthcheck_finance.go b/handlers/healthcheck_finance.go index f1773e4..c22dc81 100644 --- a/handlers/healthcheck_finance.go +++ b/handlers/healthcheck_finance.go @@ -13,8 +13,7 @@ import ( // HandleHealthCheckFinanceSystem checks whether the e5 system is available to take requests func HandleHealthCheckFinanceSystem(w http.ResponseWriter, r *http.Request) { - ig := api.IssuerGatewayHealthcheckFinanceSystem{} - systemAvailableTime, systemUnavailable, parseError := ig.CheckScheduledMaintenance() + systemAvailableTime, systemUnavailable, parseError := api.CheckScheduledMaintenance() if parseError { log.ErrorR(r, fmt.Errorf("parseError from CheckScheduledMaintenance: [%v]", parseError)) diff --git a/issuer_gateway/api/healthcheck_finance.go b/issuer_gateway/api/healthcheck_finance.go index d0347fa..8c35029 100644 --- a/issuer_gateway/api/healthcheck_finance.go +++ b/issuer_gateway/api/healthcheck_finance.go @@ -1,9 +1,88 @@ package api import ( + "fmt" + "strconv" "time" + + "github.com/companieshouse/chs.go/log" + "github.com/companieshouse/penalty-payment-api/config" ) -type HealthcheckFinanceSystem interface { - CheckScheduledMaintenance() (systemAvailableTime time.Time, systemUnavailable bool, parseError bool) +func CheckScheduledMaintenance() (systemAvailableTime time.Time, systemUnavailable bool, parseError bool) { + cfg, err := config.Get() + if err != nil { + err = fmt.Errorf("error getting config for planned maintenance: [%v]", err) + return time.Time{}, false, true + } + + currentTime := time.Now() + + systemAvailableTime, systemUnavailable = checkWeeklyDownTime(cfg, currentTime) + + if isPlannedMaintenanceCheckRequired(cfg) { + timeDateLayout := time.RFC822 + maintenanceStart, err := time.Parse(timeDateLayout, cfg.PlannedMaintenanceStart) + if err != nil { + log.Error(fmt.Errorf("error parsing Maintenance Start time: [%v]", err)) + return time.Time{}, false, true + } + maintenanceEnd, err := time.Parse(timeDateLayout, cfg.PlannedMaintenanceEnd) + if err != nil { + log.Error(fmt.Errorf("error parsing Maintenance End time: [%v]", err)) + return time.Time{}, false, true + } + + if maintenanceEnd.After(currentTime) && maintenanceStart.Before(currentTime) && maintenanceEnd.After(systemAvailableTime) { + systemAvailableTime = maintenanceEnd + systemUnavailable = true + } + } + return systemAvailableTime, systemUnavailable, false +} + +func checkWeeklyDownTime(cfg *config.Config, currentTime time.Time) (systemAvailableTime time.Time, systemUnavailable bool) { + if isWeeklyMaintenanceTimeCheckRequired(cfg) { + // If the weekday is maintenance day + if currentTime.Weekday() == cfg.WeeklyMaintenanceDay { + + weeklyMaintenanceStartTime := returnWeeklyMaintenanceTime(currentTime, cfg.WeeklyMaintenanceStartTime[:2], cfg.WeeklyMaintenanceStartTime[2:]) + + weeklyMaintenanceEndTime := returnWeeklyMaintenanceTime(currentTime, cfg.WeeklyMaintenanceEndTime[:2], cfg.WeeklyMaintenanceEndTime[2:]) + + // Check if time is within maintenance time + if isWithinMaintenanceTime(weeklyMaintenanceEndTime, currentTime, weeklyMaintenanceStartTime) { + systemAvailableTime = weeklyMaintenanceEndTime + systemUnavailable = true + } + } + } + return systemAvailableTime, systemUnavailable +} + +func isWeeklyMaintenanceTimeCheckRequired(cfg *config.Config) bool { + return cfg.WeeklyMaintenanceStartTime != "" && cfg.WeeklyMaintenanceEndTime != "" +} + +// returnWeeklyMaintenanceTime returns a time.Time format for the current date with the hour and minute set to the arguments passed +func returnWeeklyMaintenanceTime(currentTime time.Time, hour, minute string) time.Time { + + intHour, _ := strconv.Atoi(hour) + timeDifferenceInHours := time.Duration(intHour - currentTime.Hour()) + + intMinute, _ := strconv.Atoi(minute) + timeDifferenceInMinutes := time.Duration(intMinute - currentTime.Minute()) + + secondDuration := time.Duration(0 - currentTime.Second()) + nanosecondDuration := time.Duration(0 - currentTime.Nanosecond()) + + return currentTime.Add(time.Hour*timeDifferenceInHours + time.Minute*timeDifferenceInMinutes + time.Second*secondDuration + time.Nanosecond*nanosecondDuration).Round(0) +} + +func isWithinMaintenanceTime(weeklyMaintenanceEndTime time.Time, currentTime time.Time, weeklyMaintenanceStartTime time.Time) bool { + return weeklyMaintenanceEndTime.After(currentTime) && weeklyMaintenanceStartTime.Before(currentTime) +} + +func isPlannedMaintenanceCheckRequired(cfg *config.Config) bool { + return cfg.PlannedMaintenanceStart != "" && cfg.PlannedMaintenanceEnd != "" } diff --git a/issuer_gateway/api/healthcheck_finance_impl.go b/issuer_gateway/api/healthcheck_finance_impl.go deleted file mode 100644 index 0c1d00e..0000000 --- a/issuer_gateway/api/healthcheck_finance_impl.go +++ /dev/null @@ -1,91 +0,0 @@ -package api - -import ( - "fmt" - "strconv" - "time" - - "github.com/companieshouse/chs.go/log" - "github.com/companieshouse/penalty-payment-api/config" -) - -type IssuerGatewayHealthcheckFinanceSystem struct { -} - -func (ig *IssuerGatewayHealthcheckFinanceSystem) CheckScheduledMaintenance() (systemAvailableTime time.Time, systemUnavailable bool, parseError bool) { - cfg, err := config.Get() - if err != nil { - err = fmt.Errorf("error getting config for planned maintenance: [%v]", err) - return time.Time{}, false, true - } - - currentTime := time.Now() - - systemAvailableTime, systemUnavailable = checkWeeklyDownTime(cfg, currentTime) - - if isPlannedMaintenanceCheckRequired(cfg) { - timeDateLayout := time.RFC822 - maintenanceStart, err := time.Parse(timeDateLayout, cfg.PlannedMaintenanceStart) - if err != nil { - log.Error(fmt.Errorf("error parsing Maintenance Start time: [%v]", err)) - return time.Time{}, false, true - } - maintenanceEnd, err := time.Parse(timeDateLayout, cfg.PlannedMaintenanceEnd) - if err != nil { - log.Error(fmt.Errorf("error parsing Maintenance End time: [%v]", err)) - return time.Time{}, false, true - } - - if maintenanceEnd.After(currentTime) && maintenanceStart.Before(currentTime) && maintenanceEnd.After(systemAvailableTime) { - systemAvailableTime = maintenanceEnd - systemUnavailable = true - } - } - return systemAvailableTime, systemUnavailable, false -} - -func checkWeeklyDownTime(cfg *config.Config, currentTime time.Time) (systemAvailableTime time.Time, systemUnavailable bool) { - if isWeeklyMaintenanceTimeCheckRequired(cfg) { - // If the weekday is maintenance day - if currentTime.Weekday() == cfg.WeeklyMaintenanceDay { - - weeklyMaintenanceStartTime := returnWeeklyMaintenanceTime(currentTime, cfg.WeeklyMaintenanceStartTime[:2], cfg.WeeklyMaintenanceStartTime[2:]) - - weeklyMaintenanceEndTime := returnWeeklyMaintenanceTime(currentTime, cfg.WeeklyMaintenanceEndTime[:2], cfg.WeeklyMaintenanceEndTime[2:]) - - // Check if time is within maintenance time - if isWithinMaintenanceTime(weeklyMaintenanceEndTime, currentTime, weeklyMaintenanceStartTime) { - systemAvailableTime = weeklyMaintenanceEndTime - systemUnavailable = true - } - } - } - return systemAvailableTime, systemUnavailable -} - -func isWeeklyMaintenanceTimeCheckRequired(cfg *config.Config) bool { - return cfg.WeeklyMaintenanceStartTime != "" && cfg.WeeklyMaintenanceEndTime != "" -} - -// returnWeeklyMaintenanceTime returns a time.Time format for the current date with the hour and minute set to the arguments passed -func returnWeeklyMaintenanceTime(currentTime time.Time, hour, minute string) time.Time { - - intHour, _ := strconv.Atoi(hour) - timeDifferenceInHours := time.Duration(intHour - currentTime.Hour()) - - intMinute, _ := strconv.Atoi(minute) - timeDifferenceInMinutes := time.Duration(intMinute - currentTime.Minute()) - - secondDuration := time.Duration(0 - currentTime.Second()) - nanosecondDuration := time.Duration(0 - currentTime.Nanosecond()) - - return currentTime.Add(time.Hour*timeDifferenceInHours + time.Minute*timeDifferenceInMinutes + time.Second*secondDuration + time.Nanosecond*nanosecondDuration).Round(0) -} - -func isWithinMaintenanceTime(weeklyMaintenanceEndTime time.Time, currentTime time.Time, weeklyMaintenanceStartTime time.Time) bool { - return weeklyMaintenanceEndTime.After(currentTime) && weeklyMaintenanceStartTime.Before(currentTime) -} - -func isPlannedMaintenanceCheckRequired(cfg *config.Config) bool { - return cfg.PlannedMaintenanceStart != "" && cfg.PlannedMaintenanceEnd != "" -} diff --git a/issuer_gateway/api/healthcheck_finance_impl_test.go b/issuer_gateway/api/healthcheck_finance_test.go similarity index 93% rename from issuer_gateway/api/healthcheck_finance_impl_test.go rename to issuer_gateway/api/healthcheck_finance_test.go index 9aa8f8d..a1b892f 100644 --- a/issuer_gateway/api/healthcheck_finance_impl_test.go +++ b/issuer_gateway/api/healthcheck_finance_test.go @@ -9,7 +9,7 @@ import ( . "github.com/smartystreets/goconvey/convey" ) -func TestUnitIssuerGatewayHealthcheckFinanceSystem_CheckScheduledMaintenance(t *testing.T) { +func TestUnitCheckScheduledMaintenance(t *testing.T) { cfg, _ := config.Get() currentTime := time.Now() @@ -17,8 +17,7 @@ func TestUnitIssuerGatewayHealthcheckFinanceSystem_CheckScheduledMaintenance(t * // Given // When - ig := &IssuerGatewayHealthcheckFinanceSystem{} - gotSystemAvailableTime, gotSystemUnavailable, gotParseError := ig.CheckScheduledMaintenance() + gotSystemAvailableTime, gotSystemUnavailable, gotParseError := CheckScheduledMaintenance() // Then So(gotSystemAvailableTime, ShouldEqual, time.Time{}) @@ -35,8 +34,7 @@ func TestUnitIssuerGatewayHealthcheckFinanceSystem_CheckScheduledMaintenance(t * cfg.WeeklyMaintenanceDay = currentTime.Weekday() // When - ig := &IssuerGatewayHealthcheckFinanceSystem{} - gotSystemAvailableTime, gotSystemUnavailable, gotParseError := ig.CheckScheduledMaintenance() + gotSystemAvailableTime, gotSystemUnavailable, gotParseError := CheckScheduledMaintenance() // Then So(gotSystemAvailableTime, ShouldEqual, time.Time{}) @@ -52,8 +50,7 @@ func TestUnitIssuerGatewayHealthcheckFinanceSystem_CheckScheduledMaintenance(t * cfg.WeeklyMaintenanceDay = currentTime.Weekday() // When - ig := &IssuerGatewayHealthcheckFinanceSystem{} - gotSystemAvailableTime, gotSystemUnavailable, gotParseError := ig.CheckScheduledMaintenance() + gotSystemAvailableTime, gotSystemUnavailable, gotParseError := CheckScheduledMaintenance() // Then So(gotSystemAvailableTime, ShouldEqual, time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), endHour, 0, 0, 0, currentTime.Location())) @@ -70,8 +67,7 @@ func TestUnitIssuerGatewayHealthcheckFinanceSystem_CheckScheduledMaintenance(t * cfg.WeeklyMaintenanceDay = currentTime.Weekday() // When - ig := &IssuerGatewayHealthcheckFinanceSystem{} - gotSystemAvailableTime, gotSystemUnavailable, gotParseError := ig.CheckScheduledMaintenance() + gotSystemAvailableTime, gotSystemUnavailable, gotParseError := CheckScheduledMaintenance() // Then So(gotSystemAvailableTime, ShouldEqual, time.Time{}) @@ -90,8 +86,7 @@ func TestUnitIssuerGatewayHealthcheckFinanceSystem_CheckScheduledMaintenance(t * cfg.PlannedMaintenanceEnd = endTime.Format(time.RFC3339) // When - ig := &IssuerGatewayHealthcheckFinanceSystem{} - gotSystemAvailableTime, gotSystemUnavailable, gotParseError := ig.CheckScheduledMaintenance() + gotSystemAvailableTime, gotSystemUnavailable, gotParseError := CheckScheduledMaintenance() // Then So(gotSystemAvailableTime, ShouldEqual, time.Time{}) @@ -110,8 +105,7 @@ func TestUnitIssuerGatewayHealthcheckFinanceSystem_CheckScheduledMaintenance(t * cfg.PlannedMaintenanceEnd = endTime.Format(time.RFC822) // When - ig := &IssuerGatewayHealthcheckFinanceSystem{} - gotSystemAvailableTime, gotSystemUnavailable, gotParseError := ig.CheckScheduledMaintenance() + gotSystemAvailableTime, gotSystemUnavailable, gotParseError := CheckScheduledMaintenance() // Then So(gotSystemAvailableTime, ShouldEqual, time.Time{}) @@ -130,8 +124,7 @@ func TestUnitIssuerGatewayHealthcheckFinanceSystem_CheckScheduledMaintenance(t * cfg.PlannedMaintenanceEnd = endTime.Format(time.RFC822) // When - ig := &IssuerGatewayHealthcheckFinanceSystem{} - gotSystemAvailableTime, gotSystemUnavailable, gotParseError := ig.CheckScheduledMaintenance() + gotSystemAvailableTime, gotSystemUnavailable, gotParseError := CheckScheduledMaintenance() // Then So(gotSystemAvailableTime, ShouldEqual, endTime) @@ -150,8 +143,7 @@ func TestUnitIssuerGatewayHealthcheckFinanceSystem_CheckScheduledMaintenance(t * cfg.PlannedMaintenanceEnd = endTime.Format(time.RFC822) // When - ig := &IssuerGatewayHealthcheckFinanceSystem{} - gotSystemAvailableTime, gotSystemUnavailable, gotParseError := ig.CheckScheduledMaintenance() + gotSystemAvailableTime, gotSystemUnavailable, gotParseError := CheckScheduledMaintenance() // Then So(gotSystemAvailableTime, ShouldEqual, time.Time{}) @@ -171,8 +163,7 @@ func TestUnitIssuerGatewayHealthcheckFinanceSystem_CheckScheduledMaintenance(t * cfg.PlannedMaintenanceEnd = plannedEndTime.Format(time.RFC822) // When - ig := &IssuerGatewayHealthcheckFinanceSystem{} - gotSystemAvailableTime, gotSystemUnavailable, gotParseError := ig.CheckScheduledMaintenance() + gotSystemAvailableTime, gotSystemUnavailable, gotParseError := CheckScheduledMaintenance() // Then So(gotSystemAvailableTime, ShouldEqual, plannedEndTime) @@ -192,8 +183,7 @@ func TestUnitIssuerGatewayHealthcheckFinanceSystem_CheckScheduledMaintenance(t * cfg.PlannedMaintenanceEnd = plannedEndTime.Format(time.RFC822) // When - ig := &IssuerGatewayHealthcheckFinanceSystem{} - gotSystemAvailableTime, gotSystemUnavailable, gotParseError := ig.CheckScheduledMaintenance() + gotSystemAvailableTime, gotSystemUnavailable, gotParseError := CheckScheduledMaintenance() // Then So(gotSystemAvailableTime, ShouldEqual, time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), weeklyEndHour, 0, 0, 0, currentTime.Location()))