-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize test helpers for testing api-gateway resource generation
- Loading branch information
1 parent
2b69d79
commit e229b33
Showing
2 changed files
with
147 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package proxycfg | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/mitchellh/go-testing-interface" | ||
|
||
"github.com/hashicorp/consul/agent/connect" | ||
"github.com/hashicorp/consul/agent/consul/discoverychain" | ||
"github.com/hashicorp/consul/agent/structs" | ||
) | ||
|
||
func TestConfigSnapshotAPIGateway(t testing.T) *ConfigSnapshot { | ||
roots, placeholderLeaf := TestCerts(t) | ||
|
||
entries := []structs.ConfigEntry{ | ||
&structs.ProxyConfigEntry{ | ||
Kind: structs.ProxyDefaults, | ||
Name: structs.ProxyConfigGlobal, | ||
Config: map[string]interface{}{ | ||
"protocol": "tcp", | ||
}, | ||
}, | ||
&structs.ServiceResolverConfigEntry{ | ||
Kind: structs.ServiceResolver, | ||
Name: "api-gateway", | ||
}, | ||
} | ||
|
||
baseEvents := []UpdateEvent{ | ||
{ | ||
CorrelationID: rootsWatchID, | ||
Result: roots, | ||
}, | ||
{ | ||
CorrelationID: leafWatchID, | ||
Result: placeholderLeaf, | ||
}, | ||
{ | ||
CorrelationID: gatewayConfigWatchID, | ||
Result: &structs.ConfigEntryResponse{ | ||
Entry: &structs.APIGatewayConfigEntry{ | ||
Kind: structs.APIGateway, | ||
Name: "api-gateway", | ||
Listeners: []structs.APIGatewayListener{ | ||
{ | ||
Name: "", | ||
Hostname: "", | ||
Port: 8080, | ||
Protocol: structs.ListenerProtocolTCP, | ||
TLS: structs.APIGatewayTLSConfiguration{ | ||
Certificates: []structs.ResourceReference{ | ||
{ | ||
Kind: structs.InlineCertificate, | ||
Name: "my-inline-certificate", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
CorrelationID: gatewayConfigWatchID, | ||
Result: &structs.ConfigEntryResponse{ | ||
Entry: &structs.BoundAPIGatewayConfigEntry{ | ||
Kind: structs.BoundAPIGateway, | ||
Name: "api-gateway", | ||
Listeners: []structs.BoundAPIGatewayListener{ | ||
{ | ||
Name: "", | ||
Certificates: []structs.ResourceReference{ | ||
{ | ||
Kind: structs.InlineCertificate, | ||
Name: "my-inline-certificate", | ||
}, | ||
}, | ||
Routes: []structs.ResourceReference{ | ||
{ | ||
Kind: structs.TCPRoute, | ||
Name: "my-tcp-route", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
CorrelationID: routeConfigWatchID, | ||
Result: &structs.ConfigEntryResponse{ | ||
Entry: &structs.TCPRouteConfigEntry{ | ||
Kind: structs.TCPRoute, | ||
Name: "my-tcp-route", | ||
Parents: []structs.ResourceReference{ | ||
{ | ||
Kind: structs.APIGateway, | ||
Name: "api-gateway", | ||
}, | ||
}, | ||
Services: []structs.TCPService{ | ||
{Name: "my-tcp-service"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
CorrelationID: inlineCertificateConfigWatchID, | ||
Result: &structs.ConfigEntryResponse{ | ||
Entry: &structs.InlineCertificateConfigEntry{ | ||
Kind: structs.InlineCertificate, | ||
Name: "my-inline-certificate", | ||
Certificate: "certificate", | ||
PrivateKey: "private key", | ||
}, | ||
}, | ||
}, | ||
{ | ||
CorrelationID: fmt.Sprintf("discovery-chain:%s", UpstreamIDString("","","my-tcp-service",nil, "")), | ||
Result: &structs.DiscoveryChainResponse{ | ||
Chain: discoverychain.TestCompileConfigEntries(t,"my-tcp-service","default","default","dc1", connect.TestClusterID+".consul",nil,entries...), | ||
}, | ||
}, | ||
} | ||
|
||
return testConfigSnapshotFixture(t, &structs.NodeService{ | ||
Kind: structs.ServiceKindAPIGateway, | ||
Service: "api-gateway", | ||
Port: 9999, | ||
Address: "1.2.3.4", | ||
Meta: nil, | ||
TaggedAddresses: nil, | ||
}, nil, nil, testSpliceEvents(baseEvents, nil)) | ||
} |
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