Skip to content

Commit

Permalink
Be able to run individual e2e tests in Intellij (googleforgames#1506)
Browse files Browse the repository at this point in the history
Had an issue with running a single e2e test within IntelliJ, because of
flag parsing.

Updating the pflag library, and making a small tweak to the framework
library seems to have done the trick.
  • Loading branch information
markmandel authored May 1, 2020
1 parent d12ae7b commit 2e884c3
Show file tree
Hide file tree
Showing 21 changed files with 1,102 additions and 15 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v0.9.2
github.com/sirupsen/logrus v1.2.0
github.com/spf13/pflag v1.0.3
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.3.1
github.com/stretchr/testify v1.5.0
go.opencensus.io v0.22.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb6
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.3.1 h1:5+8j8FTpnFV4nEImW/ofkzEt8VoOiLXxdYIDsB73T38=
github.com/spf13/viper v1.3.1/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
19 changes: 17 additions & 2 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import (
"testing"
"time"

"k8s.io/apimachinery/pkg/api/resource"

agonesv1 "agones.dev/agones/pkg/apis/agones/v1"
allocationv1 "agones.dev/agones/pkg/apis/allocation/v1"
autoscaling "agones.dev/agones/pkg/apis/autoscaling/v1"
Expand All @@ -42,6 +40,7 @@ import (
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
types "k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -124,6 +123,13 @@ const (
// https://github.com/spf13/pflag/issues/63
// https://github.com/spf13/pflag/issues/238
func ParseTestFlags() error {
// if we have a "___" in the arguments path, then this is IntelliJ running the test, so ignore this, as otherwise
// it breaks.
if strings.Contains(os.Args[0], "___") {
logrus.Info("Running test via Intellij. Skipping Test Flag Parsing")
return nil
}

var testFlags []string
for _, f := range os.Args[1:] {
if strings.HasPrefix(f, "-test.") {
Expand Down Expand Up @@ -157,6 +163,7 @@ func NewFromFlags() (*Framework, error) {
runtime.FeaturesBindFlags()
pflag.Parse()

viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
runtime.Must(viper.BindEnv(kubeconfigFlag))
runtime.Must(viper.BindEnv(gsimageFlag))
runtime.Must(viper.BindEnv(pullSecretFlag))
Expand All @@ -177,6 +184,14 @@ func NewFromFlags() (*Framework, error) {
framework.PerfOutputDir = *perfOutputDir
framework.Version = *version

logrus.WithField("gameServerImage", framework.GameServerImage).
WithField("pullSecret", framework.PullSecret).
WithField("stressTestLevel", framework.StressTestLevel).
WithField("perfOutputDir", framework.PerfOutputDir).
WithField("version", framework.Version).
WithField("featureGates", runtime.EncodeFeatures()).
Info("Starting e2e test(s)")

return framework, nil
}

Expand Down
4 changes: 2 additions & 2 deletions vendor/github.com/spf13/pflag/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions vendor/github.com/spf13/pflag/bool_slice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/github.com/spf13/pflag/count.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions vendor/github.com/spf13/pflag/duration_slice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions vendor/github.com/spf13/pflag/flag.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

174 changes: 174 additions & 0 deletions vendor/github.com/spf13/pflag/float32_slice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2e884c3

Please sign in to comment.