@@ -117,6 +117,19 @@ func (scs *ServerConfigs) UnmarshalJSON(data []byte) error {
117117 return nil
118118}
119119
120+ // String returns a string representation of the ServerConfigs, by concatenating
121+ // the string representations of the underlying server configs.
122+ func (scs * ServerConfigs ) String () string {
123+ ret := ""
124+ for i , sc := range * scs {
125+ if i > 0 {
126+ ret += ", "
127+ }
128+ ret += sc .String ()
129+ }
130+ return ret
131+ }
132+
120133// Authority contains configuration for an xDS control plane authority.
121134//
122135// This type does not implement custom JSON marshal/unmarshal logic because it
@@ -237,14 +250,6 @@ func (sc *ServerConfig) Equal(other *ServerConfig) bool {
237250}
238251
239252// String returns the string representation of the ServerConfig.
240- //
241- // This string representation will be used as map keys in federation
242- // (`map[ServerConfig]authority`), so that the xDS ClientConn and stream will be
243- // shared by authorities with different names but the same server config.
244- //
245- // It covers (almost) all the fields so the string can represent the config
246- // content. It doesn't cover NodeProto because NodeProto isn't used by
247- // federation.
248253func (sc * ServerConfig ) String () string {
249254 if len (sc .serverFeatures ) == 0 {
250255 return fmt .Sprintf ("%s-%s" , sc .serverURI , sc .selectedCreds .String ())
@@ -361,7 +366,7 @@ type Config struct {
361366
362367// XDSServers returns the top-level list of management servers to connect to,
363368// ordered by priority.
364- func (c * Config ) XDSServers () [] * ServerConfig {
369+ func (c * Config ) XDSServers () ServerConfigs {
365370 return c .xDSServers
366371}
367372
@@ -608,8 +613,9 @@ func newConfigFromContents(data []byte) (*Config, error) {
608613//
609614// # Testing-Only
610615type ConfigOptionsForTesting struct {
611- // Servers is the top-level xDS server configuration
612- Servers []json.RawMessage
616+ // Servers is the top-level xDS server configuration. It contains a list of
617+ // server configurations.
618+ Servers json.RawMessage
613619 // CertificateProviders is the certificate providers configuration.
614620 CertificateProviders map [string ]json.RawMessage
615621 // ServerListenerResourceNameTemplate is the listener resource name template
@@ -630,13 +636,9 @@ type ConfigOptionsForTesting struct {
630636//
631637// # Testing-Only
632638func NewContentsForTesting (opts ConfigOptionsForTesting ) ([]byte , error ) {
633- var servers []* ServerConfig
634- for _ , serverCfgJSON := range opts .Servers {
635- server := & ServerConfig {}
636- if err := server .UnmarshalJSON (serverCfgJSON ); err != nil {
637- return nil , err
638- }
639- servers = append (servers , server )
639+ var servers ServerConfigs
640+ if err := json .Unmarshal (opts .Servers , & servers ); err != nil {
641+ return nil , err
640642 }
641643 certProviders := make (map [string ]certproviderNameAndConfig )
642644 for k , v := range opts .CertificateProviders {
0 commit comments