Skip to content

Commit b57841c

Browse files
authored
Merge pull request #70 from Antonboom/fixes/go-require-fp
go-require: do not skip anonymous test funcs
2 parents 3e95e80 + fc2093d commit b57841c

19 files changed

+698
-5
lines changed

analyzer/analyzer_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ func TestTestifyLint(t *testing.T) {
3838
},
3939
},
4040
{dir: "ginkgo"},
41+
{
42+
dir: "go-require-issue67",
43+
flags: map[string]string{"disable-all": "true", "enable": checkers.NewGoRequire().Name()},
44+
},
4145
{
4246
dir: "not-std-funcs",
4347
flags: map[string]string{"enable-all": "true"},
@@ -79,7 +83,7 @@ func TestTestifyLint(t *testing.T) {
7983
t.Fatal(err)
8084
}
8185
}
82-
analysistest.RunWithSuggestedFixes(t, analysistest.TestData(), anlzr, tt.dir)
86+
analysistest.RunWithSuggestedFixes(t, analysistest.TestData(), anlzr, filepath.Join(tt.dir, "..."))
8387
})
8488
}
8589
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package conformance_test
2+
3+
import (
4+
"testing"
5+
6+
"go-require-issue67/suite"
7+
"go-require-issue67/tests"
8+
)
9+
10+
func TestConformance(t *testing.T) {
11+
cSuite := new(suite.ConformanceTestSuite)
12+
cSuite.Run(t, tests.ConformanceTests)
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package suite
2+
3+
// SupportedFeature allows opting in to additional conformance tests at an
4+
// individual feature granularity.
5+
type SupportedFeature string
6+
7+
const (
8+
// This option indicates support for Gateway.
9+
// Opting out of this is allowed only for GAMMA-only implementations
10+
SupportGateway SupportedFeature = "Gateway"
11+
)
12+
13+
const (
14+
// This option indicates that the Gateway can also use port 8080
15+
SupportGatewayPort8080 SupportedFeature = "GatewayPort8080"
16+
17+
// SupportGatewayStaticAddresses option indicates that the Gateway is capable
18+
// of allocating pre-determined addresses, rather than dynamically having
19+
// addresses allocated for it.
20+
SupportGatewayStaticAddresses SupportedFeature = "GatewayStaticAddresses"
21+
)
22+
23+
const (
24+
// This option indicates support for ReferenceGrant.
25+
SupportReferenceGrant SupportedFeature = "ReferenceGrant"
26+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package suite
2+
3+
import "testing"
4+
5+
type ConformanceTestSuite struct{}
6+
7+
// Run runs the provided set of conformance tests.
8+
func (suite *ConformanceTestSuite) Run(t *testing.T, tests []ConformanceTest) {
9+
for _, test := range tests {
10+
t.Run(test.ShortName, func(t *testing.T) {
11+
test.Run(t, suite)
12+
})
13+
}
14+
}
15+
16+
type ConformanceTest struct {
17+
ShortName string
18+
Description string
19+
Features []SupportedFeature
20+
Manifests []string
21+
Parallel bool
22+
Test func(*testing.T, *ConformanceTestSuite)
23+
}
24+
25+
// Run runs an individual tests, applying and cleaning up the required manifests
26+
// before calling the Test function.
27+
func (test *ConformanceTest) Run(t *testing.T, suite *ConformanceTestSuite) {
28+
if test.Parallel {
29+
t.Parallel()
30+
}
31+
32+
test.Test(t, suite)
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package tests
2+
3+
import (
4+
"testing"
5+
6+
"go-require-issue67/suite"
7+
)
8+
9+
func init() {
10+
ConformanceTests = append(ConformanceTests, GatewayInvalidRouteKind)
11+
}
12+
13+
var GatewayInvalidRouteKind = suite.ConformanceTest{
14+
ShortName: "GatewayInvalidRouteKind",
15+
Description: "A Gateway in the gateway-conformance-infra namespace should fail to become ready an invalid Route kind is specified.",
16+
Features: []suite.SupportedFeature{
17+
suite.SupportGateway,
18+
},
19+
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
20+
t.Run("Gateway listener should have a false ResolvedRefs condition with reason InvalidRouteKinds and no supportedKinds", func(t *testing.T) {
21+
// ...
22+
})
23+
24+
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) {
25+
// ...
26+
})
27+
},
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package tests
2+
3+
import (
4+
"testing"
5+
6+
"go-require-issue67/suite"
7+
)
8+
9+
func init() {
10+
ConformanceTests = append(ConformanceTests, GatewayInvalidTLSConfiguration)
11+
}
12+
13+
var GatewayInvalidTLSConfiguration = suite.ConformanceTest{
14+
ShortName: "GatewayInvalidTLSConfiguration",
15+
Description: "A Gateway should fail to become ready if the Gateway has an invalid TLS configuration",
16+
Features: []suite.SupportedFeature{
17+
suite.SupportGateway,
18+
},
19+
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
20+
testCases := []struct {
21+
name string
22+
gatewayNamespacedName NamespacedName
23+
}{
24+
{
25+
name: "Nonexistent secret referenced as CertificateRef in a Gateway listener",
26+
gatewayNamespacedName: NamespacedName{Name: "gateway-certificate-nonexistent-secret", Namespace: "gateway-conformance-infra"},
27+
},
28+
{
29+
name: "Unsupported group resource referenced as CertificateRef in a Gateway listener",
30+
gatewayNamespacedName: NamespacedName{Name: "gateway-certificate-unsupported-group", Namespace: "gateway-conformance-infra"},
31+
},
32+
{
33+
name: "Unsupported kind resource referenced as CertificateRef in a Gateway listener",
34+
gatewayNamespacedName: NamespacedName{Name: "gateway-certificate-unsupported-kind", Namespace: "gateway-conformance-infra"},
35+
},
36+
{
37+
name: "Malformed secret referenced as CertificateRef in a Gateway listener",
38+
gatewayNamespacedName: NamespacedName{Name: "gateway-certificate-malformed-secret", Namespace: "gateway-conformance-infra"},
39+
},
40+
}
41+
42+
for _, tc := range testCases {
43+
tc := tc
44+
t.Run(tc.name, func(t *testing.T) {
45+
t.Parallel()
46+
// ...
47+
})
48+
}
49+
},
50+
}
51+
52+
type NamespacedName struct {
53+
Namespace string
54+
Name string
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package tests
2+
3+
import (
4+
"context"
5+
"testing"
6+
"time"
7+
8+
"github.com/stretchr/testify/require"
9+
"go-require-issue67/suite"
10+
)
11+
12+
func init() {
13+
ConformanceTests = append(ConformanceTests, GatewayModifyListeners)
14+
}
15+
16+
var GatewayModifyListeners = suite.ConformanceTest{
17+
ShortName: "GatewayModifyListeners",
18+
Features: []suite.SupportedFeature{
19+
suite.SupportGateway,
20+
},
21+
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
22+
t.Run("should be able to add a listener that then becomes available for routing traffic", func(t *testing.T) {
23+
_, cancel := context.WithTimeout(context.Background(), time.Minute)
24+
defer cancel()
25+
26+
var err error
27+
require.NoErrorf(t, err, "error getting Gateway: %v", err)
28+
29+
var err2 error
30+
require.NoErrorf(t, err2, "error patching the Gateway: %v", err)
31+
32+
var err3 error
33+
require.NoErrorf(t, err3, "error getting Gateway: %v", err)
34+
require.NotEqual(t, "original.Generation", "updated.Generation",
35+
"generation should change after an update")
36+
})
37+
38+
t.Run("should be able to remove listeners, which would then stop routing the relevant traffic", func(t *testing.T) {
39+
_, cancel := context.WithTimeout(context.Background(), time.Minute)
40+
defer cancel()
41+
42+
var err error
43+
require.NoErrorf(t, err, "error getting Gateway: %v", err)
44+
45+
require.Equalf(t, 2, "len(mutate.Spec.Listeners", "the gateway must have 2 listeners")
46+
47+
var err2 error
48+
require.NoErrorf(t, err2, "error patching the Gateway: %v", err)
49+
50+
var err3 error
51+
require.NoErrorf(t, err3, "error getting Gateway: %v", err)
52+
53+
require.NotEqual(t, "original.Generation", "updated.Generation",
54+
"generation should change after an update")
55+
})
56+
},
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package tests
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
"go-require-issue67/suite"
8+
)
9+
10+
func init() {
11+
ConformanceTests = append(ConformanceTests, GatewayObservedGenerationBump)
12+
}
13+
14+
var GatewayObservedGenerationBump = suite.ConformanceTest{
15+
ShortName: "GatewayObservedGenerationBump",
16+
Features: []suite.SupportedFeature{
17+
suite.SupportGateway,
18+
suite.SupportGatewayPort8080,
19+
},
20+
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
21+
t.Run("observedGeneration should increment", func(t *testing.T) {
22+
var err error
23+
require.NoErrorf(t, err, "error getting Gateway: %v", err)
24+
require.NotEqual(t, "original.Generation", "updated.Generation",
25+
"generation should change after an update")
26+
})
27+
},
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package tests
2+
3+
import (
4+
"testing"
5+
6+
"go-require-issue67/suite"
7+
)
8+
9+
func init() {
10+
ConformanceTests = append(ConformanceTests, GatewaySecretInvalidReferenceGrant)
11+
}
12+
13+
var GatewaySecretInvalidReferenceGrant = suite.ConformanceTest{
14+
ShortName: "GatewaySecretInvalidReferenceGrant",
15+
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",
16+
Features: []suite.SupportedFeature{
17+
suite.SupportGateway,
18+
suite.SupportReferenceGrant,
19+
},
20+
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
21+
_ = NamespacedName{Name: "gateway-secret-invalid-reference-grant", Namespace: "gateway-conformance-infra"}
22+
23+
t.Run("Gateway listener should have a false ResolvedRefs condition with reason RefNotPermitted", func(t *testing.T) {
24+
// ...
25+
})
26+
},
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package tests
2+
3+
import (
4+
"testing"
5+
6+
"go-require-issue67/suite"
7+
)
8+
9+
func init() {
10+
ConformanceTests = append(ConformanceTests, GatewaySecretMissingReferenceGrant)
11+
}
12+
13+
var GatewaySecretMissingReferenceGrant = suite.ConformanceTest{
14+
ShortName: "GatewaySecretMissingReferenceGrant",
15+
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",
16+
Features: []suite.SupportedFeature{
17+
suite.SupportGateway,
18+
suite.SupportReferenceGrant,
19+
},
20+
Manifests: []string{"tests/gateway-secret-missing-reference-grant.yaml"},
21+
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
22+
_ = NamespacedName{Name: "gateway-secret-missing-reference-grant", Namespace: "gateway-conformance-infra"}
23+
24+
t.Run("Gateway listener should have a false ResolvedRefs condition with reason RefNotPermitted", func(t *testing.T) {
25+
// ...
26+
})
27+
},
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package tests
2+
3+
import (
4+
"testing"
5+
6+
"go-require-issue67/suite"
7+
)
8+
9+
func init() {
10+
ConformanceTests = append(ConformanceTests, GatewaySecretReferenceGrantAllInNamespace)
11+
}
12+
13+
var GatewaySecretReferenceGrantAllInNamespace = suite.ConformanceTest{
14+
ShortName: "GatewaySecretReferenceGrantAllInNamespace",
15+
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",
16+
Features: []suite.SupportedFeature{
17+
suite.SupportGateway,
18+
suite.SupportReferenceGrant,
19+
},
20+
Manifests: []string{"tests/gateway-secret-reference-grant-all-in-namespace.yaml"},
21+
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
22+
_ = NamespacedName{Name: "gateway-secret-reference-grant-all-in-namespace", Namespace: "gateway-conformance-infra"}
23+
24+
t.Run("Gateway listener should have a true ResolvedRefs condition and a true Programmed condition", func(t *testing.T) {
25+
// ....
26+
})
27+
},
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package tests
2+
3+
import (
4+
"testing"
5+
6+
"go-require-issue67/suite"
7+
)
8+
9+
func init() {
10+
ConformanceTests = append(ConformanceTests, GatewaySecretReferenceGrantSpecific)
11+
}
12+
13+
var GatewaySecretReferenceGrantSpecific = suite.ConformanceTest{
14+
ShortName: "GatewaySecretReferenceGrantSpecific",
15+
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",
16+
Features: []suite.SupportedFeature{
17+
suite.SupportGateway,
18+
suite.SupportReferenceGrant,
19+
},
20+
Manifests: []string{"tests/gateway-secret-reference-grant-specific.yaml"},
21+
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
22+
_ = NamespacedName{Name: "gateway-secret-reference-grant-specific", Namespace: "gateway-conformance-infra"}
23+
24+
t.Run("Gateway listener should have a true ResolvedRefs condition and a true Programmed condition", func(t *testing.T) {
25+
// ...
26+
})
27+
},
28+
}

0 commit comments

Comments
 (0)