error_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. Copyright 2021 The Rook Authors. All rights reserved.
  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 exec
  14. import (
  15. "errors"
  16. "os"
  17. "os/exec"
  18. "testing"
  19. )
  20. func TestExitStatus(t *testing.T) {
  21. e := &exec.ExitError{ProcessState: &os.ProcessState{}}
  22. c := &CephCLIError{err: e}
  23. type args struct {
  24. err error
  25. }
  26. tests := []struct {
  27. name string
  28. args args
  29. want int
  30. want1 bool
  31. }{
  32. {"error type is unknown", args{err: errors.New("unknownerror")}, 0, false},
  33. {"error type is ExitError", args{err: e}, 0, true},
  34. {"error type is CephCLIError and contains ExitError ", args{err: c}, 0, true},
  35. {"error type is CephCLIError and does not contain ExitError", args{err: &CephCLIError{err: errors.New("foo")}}, 0, false},
  36. }
  37. for _, tt := range tests {
  38. t.Run(tt.name, func(t *testing.T) {
  39. got, got1 := ExitStatus(tt.args.err)
  40. if got != tt.want {
  41. t.Errorf("ExitStatus() got = %v, want %v", got, tt.want)
  42. }
  43. if got1 != tt.want1 {
  44. t.Errorf("ExitStatus() got1 = %v, want %v", got1, tt.want1)
  45. }
  46. })
  47. }
  48. }