Skip to content

Commit

Permalink
Reactivate paralleltest
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronsky committed Apr 19, 2021
1 parent 1359f88 commit 9956f38
Show file tree
Hide file tree
Showing 38 changed files with 366 additions and 23 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ linters:
- interfacer
- lll
- maligned
- paralleltest
- scopelint
- testpackage
- thelper
Expand Down
30 changes: 21 additions & 9 deletions cmd/cider/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,51 @@ import (
)

func TestVersion(t *testing.T) {
for name, tt := range map[string]struct {
t.Parallel()

testCases := []struct {
name string
version, commit, date, builtBy string
out string
}{
"all empty": {
out: "",
{
name: "all empty",
out: "",
},
"complete": {
{
name: "complete",
version: "1.2.3",
date: "12/12/12",
commit: "aaaa",
builtBy: "me",
out: "1.2.3\ncommit: aaaa\nbuilt at: 12/12/12\nbuilt by: me",
},
"only version": {
{
name: "only version",
version: "1.2.3",
out: "1.2.3",
},
"version and date": {
{
name: "version and date",
version: "1.2.3",
date: "12/12/12",
out: "1.2.3\nbuilt at: 12/12/12",
},
"version, date, built by": {
{
name: "version, date, built by",
version: "1.2.3",
date: "12/12/12",
builtBy: "me",
out: "1.2.3\nbuilt at: 12/12/12\nbuilt by: me",
},
} {
}

for _, tt := range testCases {
tt := tt

t.Run(name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

assert.Equal(t, tt.out+licenseDisclaimer, buildVersion(tt.version, tt.commit, tt.date, tt.builtBy))
})
}
Expand Down
2 changes: 2 additions & 0 deletions internal/clicommand/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
)

func TestCheckCmd(t *testing.T) {
t.Parallel()

var cmd = newCheckCmd()

var path = filepath.Join(t.TempDir(), "foo.yaml")
Expand Down
2 changes: 2 additions & 0 deletions internal/clicommand/completions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
)

func TestCompletionsCmd(t *testing.T) {
t.Parallel()

cmd := newCompletionsCmd()

cmd.cmd.SetArgs([]string{})
Expand Down
6 changes: 6 additions & 0 deletions internal/clicommand/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
)

func TestConfig_Happy_CustomPath(t *testing.T) {
t.Parallel()

var path = filepath.Join(t.TempDir(), "foo.yaml")

var proj config.Project
Expand All @@ -44,6 +46,8 @@ func TestConfig_Happy_CustomPath(t *testing.T) {
}

func TestConfig_Happy_DefaultPath(t *testing.T) {
t.Parallel()

var folder = t.TempDir()

var path = filepath.Join(folder, "cider.yaml")
Expand All @@ -60,6 +64,8 @@ func TestConfig_Happy_DefaultPath(t *testing.T) {
}

func TestConfig_Err_DoesntExist(t *testing.T) {
t.Parallel()

cfg, err := loadConfig("", t.TempDir())
assert.Error(t, err)
assert.Empty(t, cfg)
Expand Down
2 changes: 2 additions & 0 deletions internal/clicommand/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
var errTestError = errors.New("TEST")

func TestErrors(t *testing.T) {
t.Parallel()

err := wrapError(errTestError, "TEST")
assert.Error(t, err)
assert.Equal(t, "TEST", err.Error())
Expand Down
2 changes: 2 additions & 0 deletions internal/clicommand/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
)

func TestInitCmd(t *testing.T) {
t.Parallel()

var folder = t.TempDir()

var cmd = newInitCmd().cmd
Expand Down
26 changes: 18 additions & 8 deletions internal/clicommand/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,22 @@ import (
"errors"
"fmt"
"os"
"sync"

"github.com/apex/log"
"github.com/apex/log/handlers/cli"
"github.com/fatih/color"
"github.com/spf13/cobra"
)

// nolint: gochecknoglobals
// It's strange these need to be global.
var (
loggerMu sync.Mutex
)

// Execute is the primary function to initiate the command line interface for Cider.
func Execute(version string, exit func(int), args []string) {
if os.Getenv("CI") != "" {
color.NoColor = false
}

log.SetHandler(cli.Default)

// nolint: forbidigo
fmt.Println()
// nolint: forbidigo
Expand Down Expand Up @@ -68,7 +69,7 @@ func NewRoot(version string, exit func(int)) *Root {
SilenceUsage: true,
SilenceErrors: true,
DisableAutoGenTag: true,
PersistentPreRun: root.setDebug,
PersistentPreRun: root.customizeLogger,
}

cmd.PersistentFlags().BoolVar(&root.debug, "debug", false, "Enable debug mode")
Expand Down Expand Up @@ -110,7 +111,16 @@ func (cmd *Root) Execute(args []string) {
}
}

func (cmd *Root) setDebug(c *cobra.Command, args []string) {
func (cmd *Root) customizeLogger(c *cobra.Command, args []string) {
loggerMu.Lock()
defer loggerMu.Unlock()

if os.Getenv("CI") != "" {
color.NoColor = false
}

log.SetHandler(cli.Default)

if cmd.debug {
log.SetLevel(log.DebugLevel)
log.Debug("debug logs enabled")
Expand Down
4 changes: 4 additions & 0 deletions internal/clicommand/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
)

func TestRootCmd(t *testing.T) {
t.Parallel()

exit := func(code int) {
assert.Equal(t, 0, code)
}
Expand All @@ -37,6 +39,8 @@ func TestRootCmd(t *testing.T) {
}

func TestRootCmd_Error(t *testing.T) {
t.Parallel()

exit := func(code int) {
assert.NotEqual(t, 0, code)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/client/assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
// Test UploadRoutingCoverage

func TestUploadRoutingCoverage_Happy(t *testing.T) {
t.Parallel()

asset := newTestAsset(t, "TEST")
ctx, client := newTestContext(
response{
Expand Down
34 changes: 34 additions & 0 deletions internal/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
// Test GetApp

func TestGetApp_Happy(t *testing.T) {
t.Parallel()

expectedBundleID := "com.app.bundleid"
ctx, client := newTestContext(response{
Response: asc.AppsResponse{
Expand All @@ -54,6 +56,8 @@ func TestGetApp_Happy(t *testing.T) {
}

func TestGetApp_Err(t *testing.T) {
t.Parallel()

ctx, client := newTestContext(response{
StatusCode: http.StatusNotFound,
RawResponse: `{}`,
Expand All @@ -66,6 +70,8 @@ func TestGetApp_Err(t *testing.T) {
}

func TestGetApp_ErrNoApps(t *testing.T) {
t.Parallel()

ctx, client := newTestContext(response{
RawResponse: `{"data":[]}`,
})
Expand All @@ -79,6 +85,8 @@ func TestGetApp_ErrNoApps(t *testing.T) {
// Test GetAppInfo

func TestGetAppInfo_Happy(t *testing.T) {
t.Parallel()

expectedState := asc.AppStoreVersionStatePrepareForSubmission
app := asc.App{}
ctx, client := newTestContext(response{
Expand Down Expand Up @@ -106,6 +114,8 @@ func TestGetAppInfo_Happy(t *testing.T) {
}

func TestGetAppInfo_Err(t *testing.T) {
t.Parallel()

app := asc.App{}
ctx, client := newTestContext(response{
StatusCode: http.StatusNotFound,
Expand All @@ -120,6 +130,8 @@ func TestGetAppInfo_Err(t *testing.T) {
}

func TestGetAppInfo_ErrNoData(t *testing.T) {
t.Parallel()

app := asc.App{}
ctx, client := newTestContext(response{
RawResponse: `{}`,
Expand All @@ -139,6 +151,8 @@ const (
)

func TestGetBuild_Happy(t *testing.T) {
t.Parallel()

expectedProcessingState := validProcessingState
app := asc.App{
Attributes: &asc.AppAttributes{
Expand Down Expand Up @@ -167,6 +181,8 @@ func TestGetBuild_Happy(t *testing.T) {
}

func TestGetBuild_HappyOverrideBuild(t *testing.T) {
t.Parallel()

expectedProcessingState := validProcessingState
app := asc.App{
Attributes: &asc.AppAttributes{
Expand Down Expand Up @@ -196,6 +212,8 @@ func TestGetBuild_HappyOverrideBuild(t *testing.T) {
}

func TestGetBuild_ErrNoVersion(t *testing.T) {
t.Parallel()

app := asc.App{
Attributes: &asc.AppAttributes{
BundleID: asc.String("com.app.bundleid"),
Expand All @@ -214,6 +232,8 @@ func TestGetBuild_ErrNoVersion(t *testing.T) {
}

func TestGetBuild_Err(t *testing.T) {
t.Parallel()

app := asc.App{
Attributes: &asc.AppAttributes{
BundleID: asc.String("com.app.bundleid"),
Expand All @@ -234,6 +254,8 @@ func TestGetBuild_Err(t *testing.T) {
}

func TestGetBuild_ErrNoBuilds(t *testing.T) {
t.Parallel()

app := asc.App{
Attributes: &asc.AppAttributes{
BundleID: asc.String("com.app.bundleid"),
Expand All @@ -253,6 +275,8 @@ func TestGetBuild_ErrNoBuilds(t *testing.T) {
}

func TestGetBuild_ErrNoAttributes(t *testing.T) {
t.Parallel()

app := asc.App{
Attributes: &asc.AppAttributes{
BundleID: asc.String("com.app.bundleid"),
Expand All @@ -272,6 +296,8 @@ func TestGetBuild_ErrNoAttributes(t *testing.T) {
}

func TestGetBuild_ErrNoProcessingState(t *testing.T) {
t.Parallel()

app := asc.App{
Attributes: &asc.AppAttributes{
BundleID: asc.String("com.app.bundleid"),
Expand All @@ -291,6 +317,8 @@ func TestGetBuild_ErrNoProcessingState(t *testing.T) {
}

func TestGetBuild_ErrInvalidProcessingState(t *testing.T) {
t.Parallel()

app := asc.App{
Attributes: &asc.AppAttributes{
BundleID: asc.String("com.app.bundleid"),
Expand All @@ -312,6 +340,8 @@ func TestGetBuild_ErrInvalidProcessingState(t *testing.T) {
// Test ReleaseForAppIsInitial

func TestReleaseForAppIsInitial_HappyInitial(t *testing.T) {
t.Parallel()

app := asc.App{}
ctx, client := newTestContext(response{
Response: asc.AppStoreVersionsResponse{
Expand All @@ -329,6 +359,8 @@ func TestReleaseForAppIsInitial_HappyInitial(t *testing.T) {
}

func TestReleaseForAppIsInitial_Err(t *testing.T) {
t.Parallel()

app := asc.App{}
ctx, client := newTestContext(response{
StatusCode: http.StatusNotFound,
Expand All @@ -343,6 +375,8 @@ func TestReleaseForAppIsInitial_Err(t *testing.T) {
}

func TestReleaseForAppIsInitial_HappyNotInitial(t *testing.T) {
t.Parallel()

app := asc.App{}
ctx, client := newTestContext(response{
Response: asc.AppStoreVersionsResponse{
Expand Down
4 changes: 4 additions & 0 deletions internal/client/clienttest/clienttest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
)

func TestClient(t *testing.T) {
t.Parallel()

ctx := context.New(config.Project{})
c := clienttest.Client{}

Expand Down Expand Up @@ -107,6 +109,8 @@ func TestClient(t *testing.T) {
}

func TestCredentials(t *testing.T) {
t.Parallel()

c := clienttest.Credentials{}
assert.NotNil(t, c.Client())
}
Loading

0 comments on commit 9956f38

Please sign in to comment.