-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from Antonboom/fixes/go-require-fp
go-require: do not skip anonymous test funcs
- Loading branch information
Showing
19 changed files
with
698 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
analyzer/testdata/src/go-require-issue67/conformance_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
26
analyzer/testdata/src/go-require-issue67/suite/features.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
28 changes: 28 additions & 0 deletions
28
analyzer/testdata/src/go-require-issue67/tests/gateway-invalid-route-kind.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
// ... | ||
}) | ||
}, | ||
} |
55 changes: 55 additions & 0 deletions
55
analyzer/testdata/src/go-require-issue67/tests/gateway-invalid-tls-configuration.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
57 changes: 57 additions & 0 deletions
57
analyzer/testdata/src/go-require-issue67/tests/gateway-modify-listeners.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
}) | ||
}, | ||
} |
28 changes: 28 additions & 0 deletions
28
analyzer/testdata/src/go-require-issue67/tests/gateway-observed-generation-bump.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
}) | ||
}, | ||
} |
27 changes: 27 additions & 0 deletions
27
analyzer/testdata/src/go-require-issue67/tests/gateway-secret-invalid-reference-grant.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
// ... | ||
}) | ||
}, | ||
} |
28 changes: 28 additions & 0 deletions
28
analyzer/testdata/src/go-require-issue67/tests/gateway-secret-missing-reference-grant.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
// ... | ||
}) | ||
}, | ||
} |
28 changes: 28 additions & 0 deletions
28
.../testdata/src/go-require-issue67/tests/gateway-secret-reference-grant-all-in-namespace.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
// .... | ||
}) | ||
}, | ||
} |
28 changes: 28 additions & 0 deletions
28
analyzer/testdata/src/go-require-issue67/tests/gateway-secret-reference-grant-specific.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
// ... | ||
}) | ||
}, | ||
} |
Oops, something went wrong.