Skip to content

Commit

Permalink
test: test improvements
Browse files Browse the repository at this point in the history
- move fixtures to a test package
- move the command tester function to a test package
- add some missing build tags
  • Loading branch information
gssbzn committed Dec 15, 2020
1 parent 8ce0828 commit 8b726bd
Show file tree
Hide file tree
Showing 172 changed files with 597 additions and 382 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ issues:
- path: e2e # Don't check for cyclomatic complexity on e2e file.
linters:
- gocyclo
- path: internal/fixture # Don't check for magic numbers on fixtures.
- path: internal/test/fixture # Don't check for magic numbers on fixtures.
linters:
- gomnd
51 changes: 25 additions & 26 deletions e2e/cloud_manager/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/mongodb/mongocli/e2e"
"github.com/mongodb/mongocli/internal/convert"
"github.com/openlyinc/pointy"
"go.mongodb.org/atlas/mongodbatlas"
"go.mongodb.org/ops-manager/opsmngr"
)
Expand Down Expand Up @@ -95,7 +96,6 @@ func generateRSConfig(filename, hostname, clusterName, version, fcVersion string
}
defer feedFile.Close()

var one float64 = 1
downloadArchive := &convert.ClusterConfig{
RSConfig: convert.RSConfig{
FCVersion: fcVersion,
Expand All @@ -107,8 +107,8 @@ func generateRSConfig(filename, hostname, clusterName, version, fcVersion string
Hostname: hostname,
LogPath: fmt.Sprintf("/data/%s/27000/mongodb.log", clusterName),
Port: 27000,
Priority: &one,
Votes: &one,
Priority: pointy.Float64(1),
Votes: pointy.Float64(1),
WiredTiger: &map[string]interface{}{
"collectionConfig": map[string]interface{}{},
"engineConfig": map[string]interface{}{
Expand All @@ -122,8 +122,8 @@ func generateRSConfig(filename, hostname, clusterName, version, fcVersion string
Hostname: hostname,
LogPath: fmt.Sprintf("/data/%s/27001/mongodb.log", clusterName),
Port: 27001,
Priority: &one,
Votes: &one,
Priority: pointy.Float64(1),
Votes: pointy.Float64(1),
WiredTiger: &map[string]interface{}{
"collectionConfig": map[string]interface{}{},
"engineConfig": map[string]interface{}{
Expand All @@ -137,8 +137,8 @@ func generateRSConfig(filename, hostname, clusterName, version, fcVersion string
Hostname: hostname,
LogPath: fmt.Sprintf("/data/%s/27002/mongodb.log", clusterName),
Port: 27002,
Priority: &one,
Votes: &one,
Priority: pointy.Float64(1),
Votes: pointy.Float64(1),
WiredTiger: &map[string]interface{}{
"collectionConfig": map[string]interface{}{},
"engineConfig": map[string]interface{}{
Expand All @@ -163,7 +163,6 @@ func generateShardedConfig(filename, hostname, clusterName, version, fcVersion s
}
defer feedFile.Close()

var one float64 = 1
downloadArchive := &convert.ClusterConfig{
RSConfig: convert.RSConfig{
FCVersion: fcVersion,
Expand All @@ -178,8 +177,8 @@ func generateShardedConfig(filename, hostname, clusterName, version, fcVersion s
Hostname: hostname,
LogPath: fmt.Sprintf("/data/%s/29000/mongodb.log", clusterName),
Port: 29000,
Priority: &one,
Votes: &one,
Priority: pointy.Float64(1),
Votes: pointy.Float64(1),
WiredTiger: &map[string]interface{}{
"collectionConfig": map[string]interface{}{},
"engineConfig": map[string]interface{}{
Expand All @@ -193,8 +192,8 @@ func generateShardedConfig(filename, hostname, clusterName, version, fcVersion s
Hostname: hostname,
LogPath: fmt.Sprintf("/data/%s/29001/mongodb.log", clusterName),
Port: 29001,
Priority: &one,
Votes: &one,
Priority: pointy.Float64(1),
Votes: pointy.Float64(1),
WiredTiger: &map[string]interface{}{
"collectionConfig": map[string]interface{}{},
"engineConfig": map[string]interface{}{
Expand All @@ -208,8 +207,8 @@ func generateShardedConfig(filename, hostname, clusterName, version, fcVersion s
Hostname: hostname,
LogPath: fmt.Sprintf("/data/%s/29002/mongodb.log", clusterName),
Port: 29002,
Priority: &one,
Votes: &one,
Priority: pointy.Float64(1),
Votes: pointy.Float64(1),
WiredTiger: &map[string]interface{}{
"collectionConfig": map[string]interface{}{},
"engineConfig": map[string]interface{}{
Expand All @@ -236,8 +235,8 @@ func generateShardedConfig(filename, hostname, clusterName, version, fcVersion s
Hostname: hostname,
LogPath: fmt.Sprintf("/data/%s/27000/mongodb.log", clusterName),
Port: 27000,
Priority: &one,
Votes: &one,
Priority: pointy.Float64(1),
Votes: pointy.Float64(1),
WiredTiger: &map[string]interface{}{
"collectionConfig": map[string]interface{}{},
"engineConfig": map[string]interface{}{
Expand All @@ -251,8 +250,8 @@ func generateShardedConfig(filename, hostname, clusterName, version, fcVersion s
Hostname: hostname,
LogPath: fmt.Sprintf("/data/%s/27001/mongodb.log", clusterName),
Port: 27001,
Priority: &one,
Votes: &one,
Priority: pointy.Float64(1),
Votes: pointy.Float64(1),
WiredTiger: &map[string]interface{}{
"collectionConfig": map[string]interface{}{},
"engineConfig": map[string]interface{}{
Expand All @@ -266,8 +265,8 @@ func generateShardedConfig(filename, hostname, clusterName, version, fcVersion s
Hostname: hostname,
LogPath: fmt.Sprintf("/data/%s/27002/mongodb.log", clusterName),
Port: 27002,
Priority: &one,
Votes: &one,
Priority: pointy.Float64(1),
Votes: pointy.Float64(1),
WiredTiger: &map[string]interface{}{
"collectionConfig": map[string]interface{}{},
"engineConfig": map[string]interface{}{
Expand All @@ -286,24 +285,24 @@ func generateShardedConfig(filename, hostname, clusterName, version, fcVersion s
Hostname: hostname,
LogPath: fmt.Sprintf("/data/%s/28000/mongodb.log", clusterName),
Port: 28000,
Priority: &one,
Votes: &one,
Priority: pointy.Float64(1),
Votes: pointy.Float64(1),
},
{
DBPath: fmt.Sprintf("/data/%s/28001", clusterName),
Hostname: hostname,
LogPath: fmt.Sprintf("/data/%s/28001/mongodb.log", clusterName),
Port: 28001,
Priority: &one,
Votes: &one,
Priority: pointy.Float64(1),
Votes: pointy.Float64(1),
},
{
DBPath: fmt.Sprintf("/data/%s/28002", clusterName),
Hostname: hostname,
LogPath: fmt.Sprintf("/data/%s/28002/mongodb.log", clusterName),
Port: 28002,
Priority: &one,
Votes: &one,
Priority: pointy.Float64(1),
Votes: pointy.Float64(1),
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/alerts/acknowledge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/mongodb/mongocli/internal/cli"
"github.com/mongodb/mongocli/internal/flag"
"github.com/mongodb/mongocli/internal/mocks"
"github.com/mongodb/mongocli/internal/test"
"github.com/stretchr/testify/assert"
"go.mongodb.org/atlas/mongodbatlas"
)

func TestAcknowledgeBuilder(t *testing.T) {
cli.CmdValidator(
test.CmdValidator(
t,
AcknowledgeBuilder(),
0,
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/alerts/alerts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package alerts
import (
"testing"

"github.com/mongodb/mongocli/internal/cli"
"github.com/mongodb/mongocli/internal/test"
)

func TestBuilder(t *testing.T) {
cli.CmdValidator(
test.CmdValidator(
t,
Builder(),
6,
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/alerts/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/mongodb/mongocli/internal/cli"
"github.com/mongodb/mongocli/internal/flag"
"github.com/mongodb/mongocli/internal/mocks"
"github.com/mongodb/mongocli/internal/test"
"github.com/stretchr/testify/assert"
"go.mongodb.org/atlas/mongodbatlas"
)

func TestDescribeBuilder(t *testing.T) {
cli.CmdValidator(
test.CmdValidator(
t,
DescribeBuilder(),
0,
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/alerts/settings/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/mongodb/mongocli/internal/cli"
"github.com/mongodb/mongocli/internal/flag"
"github.com/mongodb/mongocli/internal/mocks"
"github.com/mongodb/mongocli/internal/test"
"go.mongodb.org/atlas/mongodbatlas"
)

Expand Down Expand Up @@ -66,7 +66,7 @@ func TestCreate_Run(t *testing.T) {
}

func TestAcknowledgeBuilder(t *testing.T) {
cli.CmdValidator(
test.CmdValidator(
t,
CreateBuilder(),
0,
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/alerts/settings/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package settings
import (
"testing"

"github.com/mongodb/mongocli/internal/cli"
"github.com/mongodb/mongocli/internal/test"
)

func TestBuilder(t *testing.T) {
cli.CmdValidator(
test.CmdValidator(
t,
Builder(),
5,
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/atlas/accesslists/access_lists_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package accesslists
import (
"testing"

"github.com/mongodb/mongocli/internal/cli"
"github.com/mongodb/mongocli/internal/test"
)

func TestBuilder(t *testing.T) {
cli.CmdValidator(
test.CmdValidator(
t,
Builder(),
4,
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/atlas/customdns/aws/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package aws
import (
"testing"

"github.com/mongodb/mongocli/internal/cli"
"github.com/mongodb/mongocli/internal/test"
)

func TestAWSBuilder(t *testing.T) {
cli.CmdValidator(
test.CmdValidator(
t,
Builder(),
3,
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/atlas/customdns/aws/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/mongodb/mongocli/internal/cli"
"github.com/mongodb/mongocli/internal/flag"
"github.com/mongodb/mongocli/internal/mocks"
"github.com/mongodb/mongocli/internal/test"
atlas "go.mongodb.org/atlas/mongodbatlas"
)

func TestDescribeBuilder(t *testing.T) {
cli.CmdValidator(
test.CmdValidator(
t,
DescribeBuilder(),
0,
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/atlas/customdns/aws/disable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/mongodb/mongocli/internal/cli"
"github.com/mongodb/mongocli/internal/flag"
"github.com/mongodb/mongocli/internal/mocks"
"github.com/mongodb/mongocli/internal/test"
atlas "go.mongodb.org/atlas/mongodbatlas"
)

func TestDisableBuilder(t *testing.T) {
cli.CmdValidator(
test.CmdValidator(
t,
DisableBuilder(),
0,
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/atlas/customdns/aws/enable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/mongodb/mongocli/internal/cli"
"github.com/mongodb/mongocli/internal/flag"
"github.com/mongodb/mongocli/internal/mocks"
"github.com/mongodb/mongocli/internal/test"
atlas "go.mongodb.org/atlas/mongodbatlas"
)

func TestEnableBuilder(t *testing.T) {
cli.CmdValidator(
test.CmdValidator(
t,
EnableBuilder(),
0,
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/atlas/customdns/custom_dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package customdns
import (
"testing"

"github.com/mongodb/mongocli/internal/cli"
"github.com/mongodb/mongocli/internal/test"
)

func TestCustomDNSBuilder(t *testing.T) {
cli.CmdValidator(
test.CmdValidator(
t,
Builder(),
1,
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/atlas/integrations/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package create
import (
"testing"

"github.com/mongodb/mongocli/internal/cli"
"github.com/mongodb/mongocli/internal/test"
)

func TestBuilder(t *testing.T) {
cli.CmdValidator(
test.CmdValidator(
t,
Builder(),
7,
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/atlas/integrations/create/datadog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/mongodb/mongocli/internal/cli"
"github.com/mongodb/mongocli/internal/flag"
"github.com/mongodb/mongocli/internal/mocks"
"github.com/mongodb/mongocli/internal/test"
"go.mongodb.org/atlas/mongodbatlas"
)

Expand All @@ -47,7 +47,7 @@ func TestDatadogOpts_Run(t *testing.T) {
}

func TestDatadogBuilder(t *testing.T) {
cli.CmdValidator(
test.CmdValidator(
t,
DatadogBuilder(),
0,
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/atlas/integrations/create/flowdock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/mongodb/mongocli/internal/cli"
"github.com/mongodb/mongocli/internal/flag"
"github.com/mongodb/mongocli/internal/mocks"
"github.com/mongodb/mongocli/internal/test"
"go.mongodb.org/atlas/mongodbatlas"
)

Expand All @@ -47,7 +47,7 @@ func TestFlowDockOpts_Run(t *testing.T) {
}

func TestFlowDockBuilder(t *testing.T) {
cli.CmdValidator(
test.CmdValidator(
t,
FlowdockBuilder(),
0,
Expand Down
Loading

0 comments on commit 8b726bd

Please sign in to comment.