github.com/inspektor-gadget/inspektor-gadget@v0.28.1/pkg/testing/containers/options.go (about)

     1  // Copyright 2023-2024 The Inspektor Gadget 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 containers
    16  
    17  import (
    18  	"github.com/inspektor-gadget/inspektor-gadget/pkg/container-utils/testutils"
    19  )
    20  
    21  type cOptions struct {
    22  	options      []testutils.Option
    23  	cleanup      bool
    24  	startAndStop bool
    25  }
    26  
    27  // containerOption is a function that modifies a ContainerSpec and exposes only
    28  // few options from testutils.Option to the user.
    29  type containerOption func(opts *cOptions)
    30  
    31  func (o *cOptions) IsCleanup() bool {
    32  	return o.cleanup
    33  }
    34  
    35  func (o *cOptions) IsStartAndStop() bool {
    36  	return o.startAndStop
    37  }
    38  
    39  func WithContainerImage(image string) containerOption {
    40  	return func(opts *cOptions) {
    41  		opts.options = append(opts.options, testutils.WithImage(image))
    42  	}
    43  }
    44  
    45  func WithContainerSeccompProfile(profile string) containerOption {
    46  	return func(opts *cOptions) {
    47  		opts.options = append(opts.options, testutils.WithSeccompProfile(profile))
    48  	}
    49  }
    50  
    51  func WithCleanup() containerOption {
    52  	return func(opts *cOptions) {
    53  		opts.cleanup = true
    54  	}
    55  }
    56  
    57  func WithStartAndStop() containerOption {
    58  	return func(opts *cOptions) {
    59  		opts.startAndStop = true
    60  	}
    61  }