Test that the creation of Option values with non-sensible inputs produces a run-time panic with a decent error message
(t *testing.T)
| 16 | // Test that the creation of Option values with non-sensible inputs produces |
| 17 | // a run-time panic with a decent error message |
| 18 | func TestOptionPanic(t *testing.T) { |
| 19 | type myBool bool |
| 20 | tests := []struct { |
| 21 | label string // Test description |
| 22 | fnc interface{} // Option function to call |
| 23 | args []interface{} // Arguments to pass in |
| 24 | wantPanic string // Expected panic message |
| 25 | }{{ |
| 26 | label: "AllowUnexported", |
| 27 | fnc: AllowUnexported, |
| 28 | args: []interface{}{}, |
| 29 | }, { |
| 30 | label: "AllowUnexported", |
| 31 | fnc: AllowUnexported, |
| 32 | args: []interface{}{1}, |
| 33 | wantPanic: "invalid struct type", |
| 34 | }, { |
| 35 | label: "AllowUnexported", |
| 36 | fnc: AllowUnexported, |
| 37 | args: []interface{}{ts.StructA{}}, |
| 38 | }, { |
| 39 | label: "AllowUnexported", |
| 40 | fnc: AllowUnexported, |
| 41 | args: []interface{}{ts.StructA{}, ts.StructB{}, ts.StructA{}}, |
| 42 | }, { |
| 43 | label: "AllowUnexported", |
| 44 | fnc: AllowUnexported, |
| 45 | args: []interface{}{ts.StructA{}, &ts.StructB{}, ts.StructA{}}, |
| 46 | wantPanic: "invalid struct type", |
| 47 | }, { |
| 48 | label: "Comparer", |
| 49 | fnc: Comparer, |
| 50 | args: []interface{}{5}, |
| 51 | wantPanic: "invalid comparer function", |
| 52 | }, { |
| 53 | label: "Comparer", |
| 54 | fnc: Comparer, |
| 55 | args: []interface{}{func(x, y interface{}) bool { return true }}, |
| 56 | }, { |
| 57 | label: "Comparer", |
| 58 | fnc: Comparer, |
| 59 | args: []interface{}{func(x, y io.Reader) bool { return true }}, |
| 60 | }, { |
| 61 | label: "Comparer", |
| 62 | fnc: Comparer, |
| 63 | args: []interface{}{func(x, y io.Reader) myBool { return true }}, |
| 64 | wantPanic: "invalid comparer function", |
| 65 | }, { |
| 66 | label: "Comparer", |
| 67 | fnc: Comparer, |
| 68 | args: []interface{}{func(x string, y interface{}) bool { return true }}, |
| 69 | wantPanic: "invalid comparer function", |
| 70 | }, { |
| 71 | label: "Comparer", |
| 72 | fnc: Comparer, |
| 73 | args: []interface{}{(func(int, int) bool)(nil)}, |
| 74 | wantPanic: "invalid comparer function", |
| 75 | }, { |