Skip to content

Commit

Permalink
fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-urbani committed Jun 20, 2023
1 parent 32786ea commit d01607e
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 64 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ audit: ## run nancy auditor

.PHONY: lint
lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.3
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2
golangci-lint run ./...

.PHONY: build
Expand Down
7 changes: 3 additions & 4 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ type CantabularMetadataExtractorAPI struct {
}

// Setup function sets up the api and returns an api
func Setup(ctx context.Context,
func Setup(_ context.Context,
r *mux.Router,
config *config.Config,
cfg *config.Config,
c CantMetaAPI,
auth authorisation.Middleware) *CantabularMetadataExtractorAPI {

api := &CantabularMetadataExtractorAPI{
Router: r,
CantMetaAPI: c,
Cfg: config,
Cfg: cfg,
auth: auth,
}

Expand Down
4 changes: 2 additions & 2 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ func TestSetup(t *testing.T) {
t.Fail()
}

api := api.Setup(ctx, r, cfg, c, authorisationMiddleware)
apiSetup := api.Setup(ctx, r, cfg, c, authorisationMiddleware)

Convey("When created the following routes should have been added", func() {
So(hasRoute(api.Router, "/cantabular-metadata/dataset/{datasetID}/lang/{lang}", "GET"), ShouldBeTrue)
So(hasRoute(apiSetup.Router, "/cantabular-metadata/dataset/{datasetID}/lang/{lang}", "GET"), ShouldBeTrue)
})
})
}
Expand Down
18 changes: 8 additions & 10 deletions api/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ func (api *CantabularMetadataExtractorAPI) getMetadataHandler(w http.ResponseWri
return
}

json, err := json.Marshal(m)
jsonMarshall, err := json.Marshal(m)
if err != nil {
log.Error(ctx, err.Error(), err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

_, err = w.Write(json)
_, err = w.Write(jsonMarshall)
if err != nil {
log.Error(ctx, err.Error(), err)
}
}

func (api *CantabularMetadataExtractorAPI) GetMetadata(ctx context.Context, datasetID string, lang string) (*cantabular.MetadataQueryResult, error) {
func (api *CantabularMetadataExtractorAPI) GetMetadata(ctx context.Context, datasetID, lang string) (*cantabular.MetadataQueryResult, error) {
mt, dimensions, err := api.GetMetadataTable(ctx, cantabular.MetadataTableQueryRequest{
Variables: []string{datasetID},
Lang: lang,
Expand Down Expand Up @@ -83,20 +83,18 @@ func (api *CantabularMetadataExtractorAPI) GetMetadata(ctx context.Context, data
return &cantabular.MetadataQueryResult{TableQueryResult: mt, DatasetQueryResult: md}, nil
}

func (api *CantabularMetadataExtractorAPI) GetMetadataTable(ctx context.Context, req cantabular.MetadataTableQueryRequest) (*cantabular.MetadataTableQuery, []string, error) {
var dims []string
func (api *CantabularMetadataExtractorAPI) GetMetadataTable(_ context.Context, req cantabular.MetadataTableQueryRequest) (*cantabular.MetadataTableQuery, []string, error) {
var dims = []string{}
mt, err := api.CantMetaAPI.MetadataTableQuery(context.Background(), req)
if err != nil {
return mt, dims, err
}

if len(mt.Service.Tables) == 0 {

return mt, dims, fmt.Errorf("%s : %w", "mt.Service.Tables", errUnexpectedResp)
}

if len(mt.Service.Tables[0].Vars) == 0 {

return mt, dims, fmt.Errorf("%s : %w", "mt.Service.Tables.Vars", errUnexpectedResp)
}

Expand Down Expand Up @@ -125,9 +123,9 @@ func OverrideMetadataTable(dims []string, mt *cantabular.MetadataTableQuery) err
}

substituted = 0
for i, v := range mt.Service.Tables {
for j, c := range v.Vars {
if inSlice(string(c), validGeo) {
for i := range mt.Service.Tables {
for j := range mt.Service.Tables[i].Vars {
if inSlice(string(mt.Service.Tables[i].Vars[j]), validGeo) {
mt.Service.Tables[i].Vars[j] = graphql.String(geoCodeOverride)
substituted++
}
Expand Down
2 changes: 0 additions & 2 deletions api/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func TestGetMetadataTable(t *testing.T) {
So(dims, ShouldResemble, expected)
})
})

}

func TestOverrideMetadataTable(t *testing.T) {
Expand All @@ -59,7 +58,6 @@ func TestOverrideMetadataTable(t *testing.T) {
})
})
})

}

func getMT() (cantabular.MetadataTableQuery, error) {
Expand Down
2 changes: 0 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ func TestConfig(t *testing.T) {
Convey("Then cfg should be nil", func() {
So(cfg, ShouldBeNil)
})

Convey("When the config values are retrieved", func() {

Convey("Then there should be no error returned, and values are as expected", func() {
configuration, err = Get() // This Get() is only called once, when inside this function
So(err, ShouldBeNil)
Expand Down
28 changes: 12 additions & 16 deletions devstack/makerecp/createrecipe/createrecipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ type CreateRecipe struct {
ONSDataSetID string
Dimensions []string
Host string
ExtApiHost string
ExtAPIHost string
ValidIDs []string
UUID string
}

func New(id, host, extApiHost string) *CreateRecipe {
var validIDs []string
func New(id, host, extAPIHost string) *CreateRecipe {
var validIDs = []string{}
for k := range GetMap() {
validIDs = append(validIDs, k)
}
sort.Strings(validIDs)
return &CreateRecipe{
ONSDataSetID: id,
Host: host,
ExtApiHost: extApiHost,
ExtAPIHost: extAPIHost,
Dimensions: GetMap()[id],
ValidIDs: validIDs,
UUID: uuidV4(),
Expand All @@ -107,7 +107,6 @@ func (cr *CreateRecipe) GetMetaData() (TableFrag, error) {
}

func (cr *CreateRecipe) GetCodeLists() (cls CodeLists) {

for _, v := range cr.Dimensions {
cl := CodeList{
Href: fmt.Sprintf("http://localhost:22400/code-lists/%s", v),
Expand All @@ -131,7 +130,6 @@ func (cr *CreateRecipe) CheckID() bool {
}

func (cr *CreateRecipe) OKDimsInDS() bool {

query := `variables={}&query={
dataset(name:"UR") {
variables(names:["%s"]) {
Expand All @@ -148,7 +146,7 @@ dataset(name:"UR") {

payload := url.PathEscape(fmt.Sprintf(query, strings.Join(cr.Dimensions, "\",\"")))

resp, err := http.Get(fmt.Sprintf("%s/graphql?%s", cr.ExtApiHost, payload))
resp, err := http.Get(fmt.Sprintf("%s/graphql?%s", cr.ExtAPIHost, payload))
if err != nil {
log.Print(err)
}
Expand All @@ -159,7 +157,6 @@ dataset(name:"UR") {
}

return !strings.Contains(string(body), "does not exist")

}

// GetMap returns our definitions as the Golden Source of Truth (maybe)
Expand All @@ -176,9 +173,9 @@ func GetMap() map[string][]string {
"TS015": {"oa", "year_arrival_uk"},
"TS016": {"oa", "residence_length_6b"},
"TS021": {"oa", "ethnic_group_tb_20b"},
//"TS024": {"ltla", "main_language_detailed"},
// "TS024": {"ltla", "main_language_detailed"},
"TS027": {"oa", "national_identity_all"},
//"TS028": {"oa", "national_identity_detailed"},
// "TS028": {"oa", "national_identity_detailed"},
"TS029": {"oa", "english_proficiency"},
"TS030": {"oa", "religion_tb"},
"TS032": {"oa", "welsh_skills_all"},
Expand All @@ -187,16 +184,16 @@ func GetMap() map[string][]string {
"TS035": {"oa", "welsh_skills_read"},
"TS036": {"oa", "welsh_skills_understand"},
"TS037": {"oa", "health_in_general"},
//"TS038": {"oa", "disability"},
// "TS038": {"oa", "disability"},
// "TS039": {"oa", "is_carer"},
"TS056": {"oa", "alternative_address_indicator"},
"TS058": {"oa", "workplace_travel_10a"},
//"TS059": {"oa", "hours_per_week_worked"},
//"TS060": {"msoa", "industry_current_88a"},
// "TS059": {"oa", "hours_per_week_worked"},
// "TS060": {"msoa", "industry_current_88a"},
"TS061": {"oa", "transport_to_workplace_12a"},
"TS062": {"oa", "ns_sec_10a"},
//"TS063": {"oa", "occupation_current_10a"},
//"TS064": {"msoa", "occupation_current_105a"},
// "TS063": {"oa", "occupation_current_10a"},
// "TS064": {"msoa", "occupation_current_105a"},
"TS065": {"oa", "has_ever_worked"},
"TS066": {"oa", "economic_activity_status_12a"},
"TS067": {"oa", "highest_qualification"},
Expand Down Expand Up @@ -226,7 +223,6 @@ func IsGeo(s string) bool {
}

return isGeo[s]

}
func SplitVars(totalVars []string) (geoVar string, vars []string) {
for _, v := range totalVars {
Expand Down
8 changes: 1 addition & 7 deletions devstack/makerecp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
)

func main() {

log.SetFlags(log.LstdFlags | log.Lshortfile)

var id, host, extapihost, checkdims, alias, format string
Expand All @@ -32,7 +31,6 @@ func main() {
flag.Parse()

if checkall {

for id := range createrecipe.GetMap() {
fmt.Printf("Testing id=%s ", id)
cr := createrecipe.New(id, host, extapihost)
Expand Down Expand Up @@ -64,11 +62,9 @@ func main() {
}

fmt.Print("OK\n")

}

os.Exit(0)

}

cr := createrecipe.New(id, host, extapihost)
Expand All @@ -83,9 +79,8 @@ func main() {
cr.Dimensions = strings.Split(checkdims, ",")
if !cr.OKDimsInDS() {
log.Fatalf("dims '%#v' not fully present in '%s' dataset", cr.Dimensions, "UR") // XXX
} else {
fmt.Println("dims OK")
}
fmt.Println("dims OK")
os.Exit(0)
}

Expand Down Expand Up @@ -149,5 +144,4 @@ func main() {
log.Fatal(err)
}
fmt.Println(string(u))

}
10 changes: 6 additions & 4 deletions features/steps/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package steps
import (
"context"
"net/http"
"time"

"github.com/ONSdigital/dp-authorisation/v2/authorisation"
"github.com/ONSdigital/dp-cantabular-metadata-extractor-api/config"
Expand All @@ -26,9 +27,10 @@ type Component struct {
}

func NewComponent() (*Component, error) {

c := &Component{
HTTPServer: &http.Server{},
HTTPServer: &http.Server{
ReadHeaderTimeout: time.Duration(5) * time.Second,
},
errorChan: make(chan error),
ServiceRunning: false,
}
Expand Down Expand Up @@ -78,15 +80,15 @@ func (c *Component) InitialiseService() (http.Handler, error) {
return c.HTTPServer.Handler, nil
}

func (f *Component) DoGetAuthorisationMiddleware(ctx context.Context, cfg *authorisation.Config) (authorisation.Middleware, error) {
func (c *Component) DoGetAuthorisationMiddleware(ctx context.Context, cfg *authorisation.Config) (authorisation.Middleware, error) {
middleware, err := authorisation.NewMiddlewareFromConfig(ctx, cfg, cfg.JWTVerificationPublicKeys)
if err != nil {
return nil, err
}
return middleware, nil
}

func (c *Component) DoGetHealthcheckOk(cfg *config.Config, buildTime string, gitCommit string, version string) (service.HealthChecker, error) {
func (c *Component) DoGetHealthcheckOk(_ *config.Config, _, _, _ string) (service.HealthChecker, error) {
return &mock.HealthCheckerMock{
AddCheckFunc: func(name string, checker healthcheck.Checker) error { return nil },
StartFunc: func(ctx context.Context) {},
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func main() {
ctx := context.Background()

if err := run(ctx); err != nil {
log.Fatal(ctx, "fatal runtime error", err)
log.Error(ctx, "fatal runtime error", err)
os.Exit(1)
}
}
Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (f *ComponentTest) InitializeScenario(godogCtx *godog.ScenarioContext) {
component.RegisterSteps(godogCtx)
}

func (f *ComponentTest) InitializeTestSuite(ctx *godog.TestSuiteContext) {
func (f *ComponentTest) InitializeTestSuite(_ *godog.TestSuiteContext) {

}

Expand Down
1 change: 0 additions & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type Service struct {

// Run the service
func Run(ctx context.Context, cfg *config.Config, serviceList *ExternalServiceList, buildTime, gitCommit, version string, svcErrors chan error) (*Service, error) {

log.Info(ctx, "running service")

log.Info(ctx, "using service configuration", log.Data{"config": cfg})
Expand Down
Loading

0 comments on commit d01607e

Please sign in to comment.