Skip to content

Commit

Permalink
Linting fixes (#92)
Browse files Browse the repository at this point in the history
* Change name of integration tests to e2e

* linting - Static checks

* linting - golangci-lint

* linting - gosec

* linting - update dependencies

* Add report card fixes

* Bump version
  • Loading branch information
PossibleLlama authored Jun 17, 2021
1 parent af91d9e commit a8139ef
Show file tree
Hide file tree
Showing 24 changed files with 501 additions and 95 deletions.
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ BIN_NAME=worklog
test:
go clean -testcache ./...
make test-unit
make test-integration
make test-e2e

test-repeat:
go clean -testcache ./...
make test-unit ARGS="-count 50"
make test-integration
make test-e2e

test-unit:
@echo "Running unit tests"
go test $(ARGS) ./cmd ./helpers ./model ./repository ./service
@echo "Unit tests passed"

test-integration:
@echo "Running integration tests"
test-e2e:
@echo "Running end to end tests"
cp -a $(HOME)/.worklog/* $(HOME)/.worklog-backup/
make build DIR="./integration"
go test ./integration
rm ./integration/$(BIN_NAME)
make build DIR="./e2e"
go test ./e2e
rm ./e2e/$(BIN_NAME)
rm -f $(HOME)/.worklog/*
cp -a $(HOME)/.worklog-backup/* $(HOME)/.worklog/
rm -f $(HOME)/.worklog-backup/*
@echo "Integration tests passed"
@echo "e2e tests passed"

format:
@echo "Running format checks"
Expand Down
4 changes: 3 additions & 1 deletion cmd/configure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func TestConfigArgs(t *testing.T) {
t.Run(testItem.name, func(t *testing.T) {
setProvidedConfigureValues(helpers.RandAlphabeticString(shortLength), helpers.RandAlphabeticString(shortLength), shortLength)

configArgs()
if err := configArgs(); err != nil {
assert.Failf(t, err.Error(), "Returned error from configArgs")
}

assert.Equal(t, configDefaultAuthor, configProvidedAuthor)
assert.Equal(t, configDefaultDuration, configProvidedDuration)
Expand Down
5 changes: 4 additions & 1 deletion cmd/create.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"os"
"strings"
"time"

Expand Down Expand Up @@ -119,5 +120,7 @@ func init() {
"tags",
"",
"Comma separated list of tags this work relates to")
createCmd.MarkFlagRequired("title")
if err := createCmd.MarkFlagRequired("title"); err != nil {
os.Exit(1)
}
}
2 changes: 2 additions & 0 deletions cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var editCmd = &cobra.Command{
RunE: EditRun,
}

// EditArgs public method to validate arguments
func EditArgs(cmd *cobra.Command, args []string) error {
return editArgs(args)
}
Expand Down Expand Up @@ -62,6 +63,7 @@ func editArgs(args []string) error {
return nil
}

// EditRun public method to run edit
func EditRun(cmd *cobra.Command, args []string) error {
return editRun(args)
}
Expand Down
17 changes: 9 additions & 8 deletions cmd/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func printRun(ids ...string) error {
When: time.Time{},
CreatedAt: time.Time{}}

worklogs := make([]*model.Work, 0)
var worklogs []*model.Work
var code int
var err error

Expand All @@ -87,6 +87,7 @@ func printRun(ids ...string) error {
return err
}

var printErr error
if code == http.StatusNotFound && !printOutputJSON {
fmt.Printf("No work found between %s and %s with the given filter",
printStartDate, printEndDate.Add(time.Second*-1))
Expand All @@ -96,24 +97,24 @@ func printRun(ids ...string) error {
fmt.Println()
} else if printOutputPretty {
if printAllFields {
model.WriteAllWorkToText(os.Stdout, worklogs)
printErr = model.WriteAllWorkToText(os.Stdout, worklogs)
} else {
model.WriteAllWorkToPrettyText(os.Stdout, worklogs)
printErr = model.WriteAllWorkToPrettyText(os.Stdout, worklogs)
}
} else if printOutputYAML {
if printAllFields {
model.WriteAllWorkToYAML(os.Stdout, worklogs)
printErr = model.WriteAllWorkToYAML(os.Stdout, worklogs)
} else {
model.WriteAllWorkToPrettyYAML(os.Stdout, worklogs)
printErr = model.WriteAllWorkToPrettyYAML(os.Stdout, worklogs)
}
} else {
if printAllFields {
model.WriteAllWorkToJSON(os.Stdout, worklogs)
printErr = model.WriteAllWorkToJSON(os.Stdout, worklogs)
} else {
model.WriteAllWorkToPrettyJSON(os.Stdout, worklogs)
printErr = model.WriteAllWorkToPrettyJSON(os.Stdout, worklogs)
}
}
return nil
return printErr
}

func init() {
Expand Down
2 changes: 1 addition & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ its way in.

A PR should:

* Add unit or integration tests for fixed or changed functionality.
* Add unit or e2e tests for fixed or changed functionality.
* Include documentation.
* Be accompanied by a completed Pull Request template.
* Bump the version.
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ have done each day.

## Supported versions

- v0.5.10
- v0.5.11

## Installation

Expand Down
2 changes: 1 addition & 1 deletion integration/configure_test.go → e2e/configure_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integration
package e2e

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion integration/create_test.go → e2e/create_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integration
package e2e

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion integration/helpers_test.go → e2e/helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integration
package e2e

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion integration/print_test.go → e2e/print_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integration
package e2e

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion integration/root_test.go → e2e/root_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integration
package e2e

import (
"fmt"
Expand Down
8 changes: 7 additions & 1 deletion errors/command.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package errors

// ConfigureArgsMinimum error value when not enough args
const ConfigureArgsMinimum = "overrideDefaults requires at least one argument"

// EditID error value when requires an ID
const EditID = "edit requires a single ID of an existing worklog"

const PrintID = "No ids provided"
// PrintID error value when requires an ID
const PrintID = "no ids provided"

// PrintArgsMinimum error value when not enough args
const PrintArgsMinimum = "one flag is required"

// Format error value when wrong format
const Format = "format is not valid"
37 changes: 23 additions & 14 deletions errors/repository.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package errors

const Unexpected = "An unexpected error occurred"

const (
RepoCreateDirectory = "Unable to create directory"
RepoCreateFile = "unable to create file"
RepoConfigFileCreate = "unable to create configuration file"
RepoConfigFileSave = "unable to save config"
RepoSaveFile = "unable to save worklog"
)

const (
RepoGetFiles = "unable to get all files"
RepoGetFilesRead = "error reading file"
)
// Unexpected error value when unexpected error happens
const Unexpected = "an unexpected error occurred"

// RepoCreateDirectory error value when creating directory
const RepoCreateDirectory = "unable to create directory"

// RepoCreateFile error value when creating file
const RepoCreateFile = "unable to create file"

// RepoConfigFileCreate error value when creating config file
const RepoConfigFileCreate = "unable to create configuration file"

// RepoConfigFileSave error value when saving config to file
const RepoConfigFileSave = "unable to save config"

// RepoSaveFile error value when saving file
const RepoSaveFile = "unable to save worklog"

// RepoGetFiles error value when getting file
const RepoGetFiles = "unable to get all files"

//RepoGetFilesRead error value when parsing file
const RepoGetFilesRead = "error reading file"
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.15
require (
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
github.com/mitchellh/go-homedir v1.1.0
github.com/spf13/cobra v1.1.1
github.com/spf13/viper v1.7.1
github.com/spf13/cobra v1.1.3
github.com/spf13/viper v1.8.0
github.com/stretchr/testify v1.7.0
gopkg.in/yaml.v2 v2.3.0
gopkg.in/yaml.v2 v2.4.0
)
Loading

0 comments on commit a8139ef

Please sign in to comment.