Skip to content

Commit

Permalink
test: add ability to specify extra cluster (#764)
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander authored Oct 11, 2024
1 parent 3e29c94 commit 146a165
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions api/plugins/tests/integration/dataplane/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ type bootstrap struct {
consumers map[string]map[string]interface{}
httpFilterGolang map[string]interface{}
accessLogFormat string
clusters []map[string]interface{}
}

func Bootstrap() *bootstrap {
return &bootstrap{
backendRoutes: []map[string]interface{}{},
consumers: map[string]map[string]interface{}{},
clusters: []map[string]interface{}{},
}
}

Expand Down Expand Up @@ -81,6 +83,16 @@ func (b *bootstrap) SetAccessLogFormat(fmt string) *bootstrap {
return b
}

func (b *bootstrap) AddCluster(s string) *bootstrap {
var n map[string]interface{}
err := yaml.Unmarshal([]byte(s), &n)
if err != nil {
panic(err)
}
b.clusters = append(b.clusters, n)
return b
}

func (b *bootstrap) buildConfiguration() (map[string]interface{}, error) {
var root map[string]interface{}
// check if the input is valid yaml
Expand Down Expand Up @@ -135,6 +147,13 @@ func (b *bootstrap) buildConfiguration() (map[string]interface{}, error) {
}
}

staticResources := root["static_resources"].(map[string]interface{})
clusters := staticResources["clusters"].([]interface{})
newClusters := []interface{}{}
for _, c := range b.clusters {
newClusters = append(newClusters, c)
}
staticResources["clusters"] = append(clusters, newClusters...)
return root, nil
}

Expand Down

0 comments on commit 146a165

Please sign in to comment.