Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go-require: do not skip anonymous test funcs #70

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion analyzer/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func TestTestifyLint(t *testing.T) {
},
},
{dir: "ginkgo"},
{
dir: "go-require-issue67",
flags: map[string]string{"disable-all": "true", "enable": checkers.NewGoRequire().Name()},
},
{
dir: "not-std-funcs",
flags: map[string]string{"enable-all": "true"},
Expand Down Expand Up @@ -79,7 +83,7 @@ func TestTestifyLint(t *testing.T) {
t.Fatal(err)
}
}
analysistest.RunWithSuggestedFixes(t, analysistest.TestData(), anlzr, tt.dir)
analysistest.RunWithSuggestedFixes(t, analysistest.TestData(), anlzr, filepath.Join(tt.dir, "..."))
})
}
}
Expand Down
13 changes: 13 additions & 0 deletions analyzer/testdata/src/go-require-issue67/conformance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package conformance_test

import (
"testing"

"go-require-issue67/suite"
"go-require-issue67/tests"
)

func TestConformance(t *testing.T) {
cSuite := new(suite.ConformanceTestSuite)
cSuite.Run(t, tests.ConformanceTests)
}
26 changes: 26 additions & 0 deletions analyzer/testdata/src/go-require-issue67/suite/features.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package suite

// SupportedFeature allows opting in to additional conformance tests at an
// individual feature granularity.
type SupportedFeature string

const (
// This option indicates support for Gateway.
// Opting out of this is allowed only for GAMMA-only implementations
SupportGateway SupportedFeature = "Gateway"
)

const (
// This option indicates that the Gateway can also use port 8080
SupportGatewayPort8080 SupportedFeature = "GatewayPort8080"

// SupportGatewayStaticAddresses option indicates that the Gateway is capable
// of allocating pre-determined addresses, rather than dynamically having
// addresses allocated for it.
SupportGatewayStaticAddresses SupportedFeature = "GatewayStaticAddresses"
)

const (
// This option indicates support for ReferenceGrant.
SupportReferenceGrant SupportedFeature = "ReferenceGrant"
)
33 changes: 33 additions & 0 deletions analyzer/testdata/src/go-require-issue67/suite/suite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package suite

import "testing"

type ConformanceTestSuite struct{}

// Run runs the provided set of conformance tests.
func (suite *ConformanceTestSuite) Run(t *testing.T, tests []ConformanceTest) {
for _, test := range tests {
t.Run(test.ShortName, func(t *testing.T) {
test.Run(t, suite)
})
}
}

type ConformanceTest struct {
ShortName string
Description string
Features []SupportedFeature
Manifests []string
Parallel bool
Test func(*testing.T, *ConformanceTestSuite)
}

// Run runs an individual tests, applying and cleaning up the required manifests
// before calling the Test function.
func (test *ConformanceTest) Run(t *testing.T, suite *ConformanceTestSuite) {
if test.Parallel {
t.Parallel()
}

test.Test(t, suite)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tests

import (
"testing"

"go-require-issue67/suite"
)

func init() {
ConformanceTests = append(ConformanceTests, GatewayInvalidRouteKind)
}

var GatewayInvalidRouteKind = suite.ConformanceTest{
ShortName: "GatewayInvalidRouteKind",
Description: "A Gateway in the gateway-conformance-infra namespace should fail to become ready an invalid Route kind is specified.",
Features: []suite.SupportedFeature{
suite.SupportGateway,
},
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
t.Run("Gateway listener should have a false ResolvedRefs condition with reason InvalidRouteKinds and no supportedKinds", func(t *testing.T) {
// ...
})

t.Run("Gateway listener should have a false ResolvedRefs condition with reason InvalidRouteKinds and HTTPRoute must be put in the supportedKinds", func(t *testing.T) {
// ...
})
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package tests

import (
"testing"

"go-require-issue67/suite"
)

func init() {
ConformanceTests = append(ConformanceTests, GatewayInvalidTLSConfiguration)
}

var GatewayInvalidTLSConfiguration = suite.ConformanceTest{
ShortName: "GatewayInvalidTLSConfiguration",
Description: "A Gateway should fail to become ready if the Gateway has an invalid TLS configuration",
Features: []suite.SupportedFeature{
suite.SupportGateway,
},
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
testCases := []struct {
name string
gatewayNamespacedName NamespacedName
}{
{
name: "Nonexistent secret referenced as CertificateRef in a Gateway listener",
gatewayNamespacedName: NamespacedName{Name: "gateway-certificate-nonexistent-secret", Namespace: "gateway-conformance-infra"},
},
{
name: "Unsupported group resource referenced as CertificateRef in a Gateway listener",
gatewayNamespacedName: NamespacedName{Name: "gateway-certificate-unsupported-group", Namespace: "gateway-conformance-infra"},
},
{
name: "Unsupported kind resource referenced as CertificateRef in a Gateway listener",
gatewayNamespacedName: NamespacedName{Name: "gateway-certificate-unsupported-kind", Namespace: "gateway-conformance-infra"},
},
{
name: "Malformed secret referenced as CertificateRef in a Gateway listener",
gatewayNamespacedName: NamespacedName{Name: "gateway-certificate-malformed-secret", Namespace: "gateway-conformance-infra"},
},
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
// ...
})
}
},
}

type NamespacedName struct {
Namespace string
Name string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package tests

import (
"context"
"testing"
"time"

"github.com/stretchr/testify/require"
"go-require-issue67/suite"
)

func init() {
ConformanceTests = append(ConformanceTests, GatewayModifyListeners)
}

var GatewayModifyListeners = suite.ConformanceTest{
ShortName: "GatewayModifyListeners",
Features: []suite.SupportedFeature{
suite.SupportGateway,
},
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
t.Run("should be able to add a listener that then becomes available for routing traffic", func(t *testing.T) {
_, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

var err error
require.NoErrorf(t, err, "error getting Gateway: %v", err)

var err2 error
require.NoErrorf(t, err2, "error patching the Gateway: %v", err)

var err3 error
require.NoErrorf(t, err3, "error getting Gateway: %v", err)
require.NotEqual(t, "original.Generation", "updated.Generation",
"generation should change after an update")
})

t.Run("should be able to remove listeners, which would then stop routing the relevant traffic", func(t *testing.T) {
_, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

var err error
require.NoErrorf(t, err, "error getting Gateway: %v", err)

require.Equalf(t, 2, "len(mutate.Spec.Listeners", "the gateway must have 2 listeners")

var err2 error
require.NoErrorf(t, err2, "error patching the Gateway: %v", err)

var err3 error
require.NoErrorf(t, err3, "error getting Gateway: %v", err)

require.NotEqual(t, "original.Generation", "updated.Generation",
"generation should change after an update")
})
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tests

import (
"testing"

"github.com/stretchr/testify/require"
"go-require-issue67/suite"
)

func init() {
ConformanceTests = append(ConformanceTests, GatewayObservedGenerationBump)
}

var GatewayObservedGenerationBump = suite.ConformanceTest{
ShortName: "GatewayObservedGenerationBump",
Features: []suite.SupportedFeature{
suite.SupportGateway,
suite.SupportGatewayPort8080,
},
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
t.Run("observedGeneration should increment", func(t *testing.T) {
var err error
require.NoErrorf(t, err, "error getting Gateway: %v", err)
require.NotEqual(t, "original.Generation", "updated.Generation",
"generation should change after an update")
})
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package tests

import (
"testing"

"go-require-issue67/suite"
)

func init() {
ConformanceTests = append(ConformanceTests, GatewaySecretInvalidReferenceGrant)
}

var GatewaySecretInvalidReferenceGrant = suite.ConformanceTest{
ShortName: "GatewaySecretInvalidReferenceGrant",
Description: "A Gateway in the gateway-conformance-infra namespace should fail to become ready if the Gateway has a certificateRef for a Secret in the gateway-conformance-web-backend namespace and a ReferenceGrant exists but does not grant permission to that specific Secret",
Features: []suite.SupportedFeature{
suite.SupportGateway,
suite.SupportReferenceGrant,
},
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
_ = NamespacedName{Name: "gateway-secret-invalid-reference-grant", Namespace: "gateway-conformance-infra"}

t.Run("Gateway listener should have a false ResolvedRefs condition with reason RefNotPermitted", func(t *testing.T) {
// ...
})
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tests

import (
"testing"

"go-require-issue67/suite"
)

func init() {
ConformanceTests = append(ConformanceTests, GatewaySecretMissingReferenceGrant)
}

var GatewaySecretMissingReferenceGrant = suite.ConformanceTest{
ShortName: "GatewaySecretMissingReferenceGrant",
Description: "A Gateway in the gateway-conformance-infra namespace should fail to become programmed if the Gateway has a certificateRef for a Secret in the gateway-conformance-web-backend namespace and a ReferenceGrant granting permission to the Secret does not exist",
Features: []suite.SupportedFeature{
suite.SupportGateway,
suite.SupportReferenceGrant,
},
Manifests: []string{"tests/gateway-secret-missing-reference-grant.yaml"},
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
_ = NamespacedName{Name: "gateway-secret-missing-reference-grant", Namespace: "gateway-conformance-infra"}

t.Run("Gateway listener should have a false ResolvedRefs condition with reason RefNotPermitted", func(t *testing.T) {
// ...
})
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tests

import (
"testing"

"go-require-issue67/suite"
)

func init() {
ConformanceTests = append(ConformanceTests, GatewaySecretReferenceGrantAllInNamespace)
}

var GatewaySecretReferenceGrantAllInNamespace = suite.ConformanceTest{
ShortName: "GatewaySecretReferenceGrantAllInNamespace",
Description: "A Gateway in the gateway-conformance-infra namespace should become programmed if the Gateway has a certificateRef for a Secret in the gateway-conformance-web-backend namespace and a ReferenceGrant granting permission to all Secrets in the namespace exists",
Features: []suite.SupportedFeature{
suite.SupportGateway,
suite.SupportReferenceGrant,
},
Manifests: []string{"tests/gateway-secret-reference-grant-all-in-namespace.yaml"},
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
_ = NamespacedName{Name: "gateway-secret-reference-grant-all-in-namespace", Namespace: "gateway-conformance-infra"}

t.Run("Gateway listener should have a true ResolvedRefs condition and a true Programmed condition", func(t *testing.T) {
// ....
})
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tests

import (
"testing"

"go-require-issue67/suite"
)

func init() {
ConformanceTests = append(ConformanceTests, GatewaySecretReferenceGrantSpecific)
}

var GatewaySecretReferenceGrantSpecific = suite.ConformanceTest{
ShortName: "GatewaySecretReferenceGrantSpecific",
Description: "A Gateway in the gateway-conformance-infra namespace should become programmed if the Gateway has a certificateRef for a Secret in the gateway-conformance-web-backend namespace and a ReferenceGrant granting permission to the specific Secret exists",
Features: []suite.SupportedFeature{
suite.SupportGateway,
suite.SupportReferenceGrant,
},
Manifests: []string{"tests/gateway-secret-reference-grant-specific.yaml"},
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
_ = NamespacedName{Name: "gateway-secret-reference-grant-specific", Namespace: "gateway-conformance-infra"}

t.Run("Gateway listener should have a true ResolvedRefs condition and a true Programmed condition", func(t *testing.T) {
// ...
})
},
}
Loading
Loading