options.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. Copyright 2018 The Kubernetes Authors.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package wrapper
  14. import (
  15. "errors"
  16. "flag"
  17. )
  18. // Options exposes the configuration options
  19. // used when wrapping test execution
  20. type Options struct {
  21. // ProcessLog will contain std{out,err} from the
  22. // wrapped test process
  23. ProcessLog string `json:"process_log"`
  24. // MarkerFile will be written with the exit code
  25. // of the test process or an internal error code
  26. // if the entrypoint fails.
  27. MarkerFile string `json:"marker_file"`
  28. }
  29. // AddFlags adds flags to the FlagSet that populate
  30. // the wrapper options struct provided.
  31. func (o *Options) AddFlags(fs *flag.FlagSet) {
  32. fs.StringVar(&o.ProcessLog, "process-log", "", "path to the log where stdout and stderr are streamed for the process we execute")
  33. fs.StringVar(&o.MarkerFile, "marker-file", "", "file we write the return code of the process we execute once it has finished running")
  34. }
  35. // Validate ensures that the set of options are
  36. // self-consistent and valid
  37. func (o *Options) Validate() error {
  38. if o.ProcessLog == "" {
  39. return errors.New("no log file specified with --process-log")
  40. }
  41. if o.MarkerFile == "" {
  42. return errors.New("no marker file specified with --marker-file")
  43. }
  44. return nil
  45. }