Skip to content

Commit

Permalink
unit tests: fix linter error (gci)
Browse files Browse the repository at this point in the history
Signed-off-by: matewolf <[email protected]>
  • Loading branch information
matewolf committed Aug 28, 2023
1 parent 8ae3621 commit 803aa87
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 49 deletions.
4 changes: 3 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ package cmd
import (
"context"
"fmt"
"github.com/uwu-tools/gh-jira-issue-sync/internal/utils/issue"
"time"

"github.com/uwu-tools/gh-jira-issue-sync/internal/utils/issue"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"sigs.k8s.io/release-utils/log"
Expand All @@ -31,6 +32,7 @@ import (
"github.com/uwu-tools/gh-jira-issue-sync/internal/github"
"github.com/uwu-tools/gh-jira-issue-sync/internal/jira"
"github.com/uwu-tools/gh-jira-issue-sync/internal/options"
"github.com/uwu-tools/gh-jira-issue-sync/internal/utils/issue"
)

var opts = &options.Options{}
Expand Down
Binary file added gh-jira-issue-sync
Binary file not shown.
3 changes: 1 addition & 2 deletions internal/clock/clockmock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import (
"time"
)

type clockMock struct {
}
type clockMock struct{}

func NewClockMock() Clock {
return &clockMock{}
Expand Down
3 changes: 1 addition & 2 deletions internal/clock/realclock.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package clock

import "time"

type realClock struct {
}
type realClock struct{}

func NewRealClock() Clock {
return &realClock{}
Expand Down
8 changes: 6 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/uwu-tools/gh-jira-issue-sync/internal/filesystem"
"io"
"net/url"
"os"
Expand All @@ -30,6 +29,10 @@ import (
"syscall"
"time"

"github.com/uwu-tools/gh-jira-issue-sync/internal/filesystem"

"github.com/uwu-tools/gh-jira-issue-sync/internal/filesystem"

"github.com/dghubble/oauth1"
"github.com/fsnotify/fsnotify"
log "github.com/sirupsen/logrus"
Expand All @@ -38,6 +41,7 @@ import (
jira "github.com/uwu-tools/go-jira/v2/cloud"
"golang.org/x/term"

"github.com/uwu-tools/gh-jira-issue-sync/internal/filesystem"
"github.com/uwu-tools/gh-jira-issue-sync/internal/github"
"github.com/uwu-tools/gh-jira-issue-sync/internal/options"
)
Expand Down Expand Up @@ -466,7 +470,7 @@ func (c *config) getFieldIDs(client *jira.Client) (*fields, error) {
}

func (c *config) parseFieldIDs(jFieldsPtr *[]jira.Field) (*fields, error) {
var fieldIDs = new(fields)
fieldIDs := new(fields)

jFields := *jFieldsPtr
for i := range jFields {
Expand Down
15 changes: 9 additions & 6 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ package config

import (
"errors"
"strings"
"testing"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
jira "github.com/uwu-tools/go-jira/v2/cloud"

"github.com/uwu-tools/gh-jira-issue-sync/internal/filesystem"
"github.com/uwu-tools/gh-jira-issue-sync/internal/options"
jira "github.com/uwu-tools/go-jira/v2/cloud"
"strings"
"testing"
)

var errMock = errors.New("mock error")

var rCmd *cobra.Command
var config2 *config
var (
rCmd *cobra.Command
config2 *config
)

func setup(t *testing.T) {
t.Helper()
Expand Down Expand Up @@ -50,7 +54,6 @@ func setupParseField(t *testing.T) {
}

func TestGetConfigPath(t *testing.T) {

tests := []struct { //nolint:govet
name string
cmdArgs []string
Expand Down
3 changes: 2 additions & 1 deletion internal/config/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package config

import (
"context"
"time"

"github.com/dghubble/oauth1"
jira "github.com/uwu-tools/go-jira/v2/cloud"
"time"
)

type IConfig interface {
Expand Down
3 changes: 2 additions & 1 deletion internal/config/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package config

import (
"context"
"time"

"github.com/dghubble/oauth1"
"github.com/stretchr/testify/mock"
jira "github.com/uwu-tools/go-jira/v2/cloud"
"time"
)

type ConfigMock struct {
Expand Down
3 changes: 1 addition & 2 deletions internal/filesystem/fakefileinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
"time"
)

type FakeFileInfo struct {
}
type FakeFileInfo struct{}

func (f *FakeFileInfo) Name() string {
return "filename.ext"
Expand Down
5 changes: 4 additions & 1 deletion internal/filesystem/mockfs.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package filesystem

import (
"github.com/stretchr/testify/mock"
"os"

Check failure on line 4 in internal/filesystem/mockfs.go

View workflow job for this annotation

GitHub Actions / build

other declaration of os

Check failure on line 4 in internal/filesystem/mockfs.go

View workflow job for this annotation

GitHub Actions / verify

other declaration of os

Check failure on line 4 in internal/filesystem/mockfs.go

View workflow job for this annotation

GitHub Actions / test

other declaration of os

"os"

Check failure on line 6 in internal/filesystem/mockfs.go

View workflow job for this annotation

GitHub Actions / build

os redeclared in this block

Check failure on line 6 in internal/filesystem/mockfs.go

View workflow job for this annotation

GitHub Actions / build

imported and not used: "os"

Check failure on line 6 in internal/filesystem/mockfs.go

View workflow job for this annotation

GitHub Actions / verify

os redeclared in this block

Check failure on line 6 in internal/filesystem/mockfs.go

View workflow job for this annotation

GitHub Actions / verify

imported and not used: "os"

Check failure on line 6 in internal/filesystem/mockfs.go

View workflow job for this annotation

GitHub Actions / test

os redeclared in this block

Check failure on line 6 in internal/filesystem/mockfs.go

View workflow job for this annotation

GitHub Actions / test

imported and not used: "os"

"github.com/stretchr/testify/mock"
)

type MockFs struct {
Expand Down
3 changes: 1 addition & 2 deletions internal/filesystem/osfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
"os"
)

type OsFs struct {
}
type OsFs struct{}

func (fs *OsFs) Stat(name string) (os.FileInfo, error) {
fileInfo, err := os.Stat(name)
Expand Down
5 changes: 4 additions & 1 deletion internal/github/interface.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package github

import (
gogh "github.com/google/go-github/v53/github"
"time"

Check failure on line 4 in internal/github/interface.go

View workflow job for this annotation

GitHub Actions / build

other declaration of time

Check failure on line 4 in internal/github/interface.go

View workflow job for this annotation

GitHub Actions / verify

other declaration of time

Check failure on line 4 in internal/github/interface.go

View workflow job for this annotation

GitHub Actions / verify

other declaration of time

Check failure on line 4 in internal/github/interface.go

View workflow job for this annotation

GitHub Actions / test

other declaration of time

"time"

Check failure on line 6 in internal/github/interface.go

View workflow job for this annotation

GitHub Actions / build

time redeclared in this block

Check failure on line 6 in internal/github/interface.go

View workflow job for this annotation

GitHub Actions / build

imported and not used: "time"

Check failure on line 6 in internal/github/interface.go

View workflow job for this annotation

GitHub Actions / verify

time redeclared in this block

Check failure on line 6 in internal/github/interface.go

View workflow job for this annotation

GitHub Actions / verify

imported and not used: "time"

Check failure on line 6 in internal/github/interface.go

View workflow job for this annotation

GitHub Actions / verify

time redeclared in this block

Check failure on line 6 in internal/github/interface.go

View workflow job for this annotation

GitHub Actions / verify

imported and not used: "time"

Check failure on line 6 in internal/github/interface.go

View workflow job for this annotation

GitHub Actions / test

time redeclared in this block

Check failure on line 6 in internal/github/interface.go

View workflow job for this annotation

GitHub Actions / test

imported and not used: "time"

gogh "github.com/google/go-github/v53/github"
)

// Client is a wrapper around the GitHub API Client library we
Expand Down
3 changes: 2 additions & 1 deletion internal/github/mock.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package github

import (
"time"

gogh "github.com/google/go-github/v53/github"
"github.com/stretchr/testify/mock"
"time"
)

type GhClientMock struct {
Expand Down
3 changes: 2 additions & 1 deletion internal/jira/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package jira

import (
gogh "github.com/google/go-github/v53/github"
"github.com/uwu-tools/gh-jira-issue-sync/internal/github"
jira "github.com/uwu-tools/go-jira/v2/cloud"

"github.com/uwu-tools/gh-jira-issue-sync/internal/github"

Check failure on line 7 in internal/jira/interface.go

View workflow job for this annotation

GitHub Actions / verify

could not import github.com/uwu-tools/gh-jira-issue-sync/internal/github (-: # github.com/uwu-tools/gh-jira-issue-sync/internal/github
)

// Client is a wrapper around the Jira API clients library we
Expand Down
3 changes: 2 additions & 1 deletion internal/jira/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package jira
import (
gogh "github.com/google/go-github/v53/github"
"github.com/stretchr/testify/mock"
"github.com/uwu-tools/gh-jira-issue-sync/internal/github"
jira "github.com/uwu-tools/go-jira/v2/cloud"

"github.com/uwu-tools/gh-jira-issue-sync/internal/github"
)

type JiraClientMock struct {
Expand Down
19 changes: 12 additions & 7 deletions internal/utils/comment/comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,30 @@ package comment

import (
"errors"
"testing"
"time"

gogh "github.com/google/go-github/v53/github"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
gojira "github.com/uwu-tools/go-jira/v2/cloud"

"github.com/uwu-tools/gh-jira-issue-sync/internal/config"
"github.com/uwu-tools/gh-jira-issue-sync/internal/github"
"github.com/uwu-tools/gh-jira-issue-sync/internal/jira"
"github.com/uwu-tools/gh-jira-issue-sync/pkg"
gojira "github.com/uwu-tools/go-jira/v2/cloud"
"testing"
"time"
)

//nolint:lll
const testComment = `Comment [(ID 484163403)|https://github.com] from GitHub user [bilbo-baggins|https://github.com/bilbo-baggins] (Bilbo Baggins) at 16:27 PM, April 17 2019:
Bla blibidy bloo bla`

var jiraClient *jira.JiraClientMock
var cfg *config.ConfigMock
var ghClient *github.GhClientMock
var (
jiraClient *jira.JiraClientMock
cfg *config.ConfigMock
ghClient *github.GhClientMock
)

var ghComment1 = gogh.IssueComment{
ID: pkg.NewInt64(1),
Expand Down Expand Up @@ -152,7 +156,8 @@ func TestCompare(t *testing.T) {
&ghComment2,
&jiraComment2,
},
}},
},
},
},
}

Expand Down
3 changes: 2 additions & 1 deletion internal/utils/comment/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package comment
import (
gogh "github.com/google/go-github/v53/github"
"github.com/stretchr/testify/mock"
gojira "github.com/uwu-tools/go-jira/v2/cloud"

"github.com/uwu-tools/gh-jira-issue-sync/internal/config"
"github.com/uwu-tools/gh-jira-issue-sync/internal/github"
"github.com/uwu-tools/gh-jira-issue-sync/internal/jira"
gojira "github.com/uwu-tools/go-jira/v2/cloud"
)

type CommentFnMock struct {
Expand Down
7 changes: 4 additions & 3 deletions internal/utils/issue/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ package issue

import (
"fmt"
"strings"

gogh "github.com/google/go-github/v53/github"
log "github.com/sirupsen/logrus"
"github.com/trivago/tgo/tcontainer"
"github.com/uwu-tools/gh-jira-issue-sync/internal/clock"
"github.com/uwu-tools/gh-jira-issue-sync/internal/utils/comment"
gojira "github.com/uwu-tools/go-jira/v2/cloud"
"strings"

"github.com/uwu-tools/gh-jira-issue-sync/internal/clock"
"github.com/uwu-tools/gh-jira-issue-sync/internal/config"
"github.com/uwu-tools/gh-jira-issue-sync/internal/github"
"github.com/uwu-tools/gh-jira-issue-sync/internal/jira"
"github.com/uwu-tools/gh-jira-issue-sync/internal/utils/comment"
)

// dateFormat is the format used for the sync time field.
Expand Down
32 changes: 19 additions & 13 deletions internal/utils/issue/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,42 @@ package issue

import (
"errors"
"os"
"testing"

gogh "github.com/google/go-github/v53/github"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/trivago/tgo/tcontainer"
gojira "github.com/uwu-tools/go-jira/v2/cloud"

clockMock "github.com/uwu-tools/gh-jira-issue-sync/internal/clock"
"github.com/uwu-tools/gh-jira-issue-sync/internal/config"
ghmock "github.com/uwu-tools/gh-jira-issue-sync/internal/github"
jmock "github.com/uwu-tools/gh-jira-issue-sync/internal/jira"
commentMock "github.com/uwu-tools/gh-jira-issue-sync/internal/utils/comment"
"github.com/uwu-tools/gh-jira-issue-sync/pkg"
gojira "github.com/uwu-tools/go-jira/v2/cloud"
"os"
"testing"
)

const testGitHubIdFieldName = "customfield_1000"
const testGitHubNumberFieldName = "customfield_2000"
const testGitHubStatusFieldName = "customfield_3000"
const testGitHubReporterFieldName = "customfield_4000"
const testGitHubLabelsFieldName = "customfield_5000"
const testGitHubLastSyncFieldName = "customfield_6000"
const (
testGitHubIdFieldName = "customfield_1000"
testGitHubNumberFieldName = "customfield_2000"
testGitHubStatusFieldName = "customfield_3000"
testGitHubReporterFieldName = "customfield_4000"
testGitHubLabelsFieldName = "customfield_5000"
testGitHubLastSyncFieldName = "customfield_6000"
)

var errMock = errors.New("mock error")

var project gojira.Project

var jClient *jmock.JiraClientMock
var ghClient *ghmock.GhClientMock
var cfg *config.ConfigMock
var commentFnMock *commentMock.CommentFnMock
var (
jClient *jmock.JiraClientMock
ghClient *ghmock.GhClientMock
cfg *config.ConfigMock
commentFnMock *commentMock.CommentFnMock
)

var ghIssue1 = gogh.Issue{
ID: pkg.NewInt64(1),
Expand Down
3 changes: 2 additions & 1 deletion internal/utils/issue/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package issue
import (
gogh "github.com/google/go-github/v53/github"
"github.com/stretchr/testify/mock"
gojira "github.com/uwu-tools/go-jira/v2/cloud"

"github.com/uwu-tools/gh-jira-issue-sync/internal/config"
"github.com/uwu-tools/gh-jira-issue-sync/internal/github"
"github.com/uwu-tools/gh-jira-issue-sync/internal/jira"
gojira "github.com/uwu-tools/go-jira/v2/cloud"
)

type IssueFnMock struct {
Expand Down

0 comments on commit 803aa87

Please sign in to comment.