github.com/cloudfoundry-attic/garden-linux@v0.333.2-candidate/port_pool/fake_port_pool/fake_port_pool.go (about)

     1  package fake_port_pool
     2  
     3  type FakePortPool struct {
     4  	nextPort uint32
     5  
     6  	AcquireError error
     7  	RemoveError  error
     8  
     9  	Acquired []uint32
    10  	Released []uint32
    11  	Removed  []uint32
    12  }
    13  
    14  func New(start uint32) *FakePortPool {
    15  	return &FakePortPool{
    16  		nextPort: start,
    17  	}
    18  }
    19  
    20  func (p *FakePortPool) Acquire() (uint32, error) {
    21  	if p.AcquireError != nil {
    22  		return 0, p.AcquireError
    23  	}
    24  
    25  	port := p.nextPort
    26  	p.nextPort++
    27  
    28  	return port, nil
    29  }
    30  
    31  func (p *FakePortPool) Remove(port uint32) error {
    32  	if p.RemoveError != nil {
    33  		return p.RemoveError
    34  	}
    35  
    36  	p.Removed = append(p.Removed, port)
    37  
    38  	return nil
    39  }
    40  
    41  func (p *FakePortPool) Release(port uint32) {
    42  	p.Released = append(p.Released, port)
    43  }