istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/test/framework/integration/component.go (about)

     1  // Copyright Istio Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package integration
    16  
    17  import (
    18  	"io"
    19  
    20  	"istio.io/istio/pkg/test/framework/resource"
    21  )
    22  
    23  var _ io.Closer = &component{}
    24  
    25  type component struct {
    26  	name        string
    27  	id          resource.ID
    28  	handleClose func(*component)
    29  }
    30  
    31  func (c *component) ID() resource.ID {
    32  	return c.id
    33  }
    34  
    35  func (c *component) Close() error {
    36  	if c.handleClose != nil {
    37  		c.handleClose(c)
    38  	}
    39  	return nil
    40  }
    41  
    42  func newComponent(ctx resource.Context, name string, handleClose func(*component)) *component {
    43  	c := &component{
    44  		name:        name,
    45  		handleClose: handleClose,
    46  	}
    47  	c.id = ctx.TrackResource(c)
    48  	return c
    49  }