@ -633,6 +633,131 @@ func TestConfigEntry_ListAll(t *testing.T) {
} )
}
func TestConfigEntry_List_Filter ( t * testing . T ) {
if testing . Short ( ) {
t . Skip ( "too slow for testing.Short" )
}
t . Parallel ( )
dir1 , s1 := testServer ( t )
t . Cleanup ( func ( ) { os . RemoveAll ( dir1 ) } )
t . Cleanup ( func ( ) { s1 . Shutdown ( ) } )
codec := rpcClient ( t , s1 )
t . Cleanup ( func ( ) { codec . Close ( ) } )
// Create some services
state := s1 . fsm . State ( )
expected := structs . IndexedConfigEntries {
Entries : [ ] structs . ConfigEntry {
& structs . ServiceConfigEntry {
Kind : structs . ServiceDefaults ,
Name : "svc1" ,
MutualTLSMode : structs . MutualTLSModeDefault ,
} ,
& structs . ServiceConfigEntry {
Kind : structs . ServiceDefaults ,
Name : "svc2" ,
MutualTLSMode : structs . MutualTLSModeStrict ,
} ,
& structs . ServiceConfigEntry {
Kind : structs . ServiceDefaults ,
Name : "svc3" ,
MutualTLSMode : structs . MutualTLSModePermissive ,
} ,
} ,
}
require . NoError ( t , state . EnsureConfigEntry ( 1 , & structs . MeshConfigEntry {
AllowEnablingPermissiveMutualTLS : true ,
} ) )
for i , e := range expected . Entries {
require . NoError ( t , state . EnsureConfigEntry ( uint64 ( i + 2 ) , e ) )
}
cases := [ ] struct {
filter string
expected [ ] structs . ConfigEntry
} {
{
filter : ` MutualTLSMode == "" ` ,
expected : expected . Entries [ 0 : 1 ] ,
} ,
{
filter : ` MutualTLSMode == "strict" ` ,
expected : expected . Entries [ 1 : 2 ] ,
} ,
{
filter : ` MutualTLSMode == "permissive" ` ,
expected : expected . Entries [ 2 : 3 ] ,
} ,
}
for _ , c := range cases {
c := c
t . Run ( c . filter , func ( t * testing . T ) {
args := structs . ConfigEntryQuery {
Kind : structs . ServiceDefaults ,
Datacenter : "dc1" ,
QueryOptions : structs . QueryOptions {
Filter : c . filter ,
} ,
}
var out structs . IndexedConfigEntries
require . NoError ( t , msgpackrpc . CallWithCodec ( codec , "ConfigEntry.List" , & args , & out ) )
require . Equal ( t , out . Entries , c . expected )
} )
}
}
func TestConfigEntry_List_Filter_UnsupportedType ( t * testing . T ) {
if testing . Short ( ) {
t . Skip ( "too slow for testing.Short" )
}
t . Parallel ( )
dir1 , s1 := testServer ( t )
t . Cleanup ( func ( ) { os . RemoveAll ( dir1 ) } )
t . Cleanup ( func ( ) { s1 . Shutdown ( ) } )
codec := rpcClient ( t , s1 )
t . Cleanup ( func ( ) { codec . Close ( ) } )
for _ , kind := range [ ] string {
// Only service-defaults is supported for now.
structs . ProxyDefaults ,
structs . ServiceRouter ,
structs . ServiceSplitter ,
structs . ServiceResolver ,
structs . IngressGateway ,
structs . TerminatingGateway ,
structs . ServiceIntentions ,
structs . MeshConfig ,
structs . ExportedServices ,
structs . SamenessGroup ,
structs . APIGateway ,
structs . BoundAPIGateway ,
structs . InlineCertificate ,
structs . HTTPRoute ,
structs . TCPRoute ,
structs . JWTProvider ,
} {
args := structs . ConfigEntryQuery {
Kind : kind ,
Datacenter : "dc1" ,
QueryOptions : structs . QueryOptions {
Filter : ` X == "y" ` ,
} ,
}
var out structs . IndexedConfigEntries
err := msgpackrpc . CallWithCodec ( codec , "ConfigEntry.List" , & args , & out )
require . Error ( t , err )
require . Equal ( t , "filtering not supported for config entry kind=" + kind , err . Error ( ) )
}
}
func TestConfigEntry_List_ACLDeny ( t * testing . T ) {
if testing . Short ( ) {
t . Skip ( "too slow for testing.Short" )