Skip to content

Commit

Permalink
Add comments to commonly used steps. (istio#3120)
Browse files Browse the repository at this point in the history
  • Loading branch information
bianpengyuan authored Dec 7, 2020
1 parent 32a5195 commit 0058550
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions test/envoye2e/driver/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
Any = "*"
)

// HTTPCall sends a HTTP request to a localhost port, and then check the response code, and response headers.
type HTTPCall struct {
// Method
Method string
Expand Down
3 changes: 3 additions & 0 deletions test/envoye2e/driver/envoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"istio.io/proxy/test/envoye2e/env"
)

// Envoy starts up a Envoy process locally.
type Envoy struct {
// template for the bootstrap
Bootstrap string
Expand All @@ -60,6 +61,7 @@ type Envoy struct {

var _ Step = &Envoy{}

// Run starts a Envoy process.
func (e *Envoy) Run(p *Params) error {
bootstrap, err := p.Fill(e.Bootstrap)
if err != nil {
Expand Down Expand Up @@ -128,6 +130,7 @@ func (e *Envoy) Run(p *Params) error {
return env.WaitForHTTPServer(url)
}

// Cleanup stops the Envoy process.
func (e *Envoy) Cleanup() {
log.Printf("stop envoy ...\n")
defer os.Remove(e.tmpFile)
Expand Down
32 changes: 28 additions & 4 deletions test/envoye2e/driver/scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,60 @@ import (
)

type (
// Params include test context that is shared by all steps.
Params struct {
// Config is the XDS server state.
Config XDSServer
Ports *env.Ports
Vars map[string]string
N int

// Ports record the port assignment for a test.
Ports *env.Ports

// Vars include the variables which are used to fill in configuration template files.
Vars map[string]string

// N records the index of repetition. It is only valid when using with Repeat step.
N int
}

// Step is a unit of execution in the integration test.
Step interface {
// Run wraps the logic of a test step.
Run(*Params) error

// Cleanup cleans up all the test artifacts created by Run.
Cleanup()
}

// Scenario is a collection of Steps. It runs and cleans up all steps sequentially.
Scenario struct {
// Steps is a collection of steps which be executed sequentially.
Steps []Step
}

// Repeat a step either for N number or duration
Repeat struct {
N int
Duration time.Duration
Step Step
}

// Sleep injects a sleep with the given duration into the test execution.
Sleep struct {
time.Duration
}

// Fork will copy params to avoid concurrent access
Fork struct {
Fore Step
Back Step
}
// Lambda captured step

// StepFunction models Lambda captured step
StepFunction func(p *Params) error
)

// NewTestParams creates a new test params struct which keeps state of a test. vars will be used for template filling.
// A set of ports will be assigned. If TestInventory is provided, the port assignment will be offsetted based on the index of the test in the inventory.
func NewTestParams(t *testing.T, vars map[string]string, inv *env.TestInventory) *Params {
ind := inv.GetTestIndex(t)
ports := env.NewPorts(ind)
Expand Down Expand Up @@ -111,6 +134,7 @@ func (s *Sleep) Run(_ *Params) error {
}
func (s *Sleep) Cleanup() {}

// Fill a template file with ariable map in Params.
func (p *Params) Fill(s string) (string, error) {
t := template.Must(template.New("params").
Option("missingkey=zero").
Expand Down
2 changes: 2 additions & 0 deletions test/envoye2e/driver/xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type XDSServer struct {

var _ Step = &XDS{}

// Run starts up an Envoy XDS server.
func (x *XDS) Run(p *Params) error {
log.Printf("XDS server starting on %d\n", p.Ports.XDSPort)
x.grpc = grpc.NewServer()
Expand All @@ -65,6 +66,7 @@ func (x *XDS) Run(p *Params) error {
return nil
}

// Cleanup stops the XDS server.
func (x *XDS) Cleanup() {
log.Println("stopping XDS server")
x.grpc.GracefulStop()
Expand Down

0 comments on commit 0058550

Please sign in to comment.