Files
my-rook-config/pkg/util/exec/exec_test.go
T

46 lines
1.3 KiB
Go
Raw Normal View History

2020-10-28 10:54:20 +01:00
/*
Copyright 2020 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package exec
import (
"errors"
"os/exec"
"testing"
)
func Test_assertErrorType(t *testing.T) {
type args struct {
err error
}
tests := []struct {
name string
args args
want string
}{
{"unknown error type", args{err: errors.New("i don't know this error")}, ""},
{"exec.exitError type", args{err: &exec.ExitError{Stderr: []byte("this is an error")}}, "this is an error"},
{"exec.Error type", args{err: &exec.Error{Name: "my error", Err: errors.New("this is an error")}}, "exec: \"my error\": this is an error"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := assertErrorType(tt.args.err); got != tt.want {
t.Errorf("assertErrorType() = %v, want %v", got, tt.want)
}
})
}
}