github.com/leanovate/gopter@v0.2.9/prop/convert_result_test.go (about) 1 package prop 2 3 import ( 4 "errors" 5 "reflect" 6 "testing" 7 8 "github.com/leanovate/gopter" 9 ) 10 11 func TestConvertResult(t *testing.T) { 12 trueResult := convertResult(true, nil) 13 if trueResult.Status != gopter.PropTrue || trueResult.Error != nil { 14 t.Errorf("Invalid true result: %#v", trueResult) 15 } 16 17 falseResult := convertResult(false, nil) 18 if falseResult.Status != gopter.PropFalse || falseResult.Error != nil { 19 t.Errorf("Invalid false result: %#v", falseResult) 20 } 21 22 stringTrueResult := convertResult("", nil) 23 if stringTrueResult.Status != gopter.PropTrue || 24 stringTrueResult.Error != nil { 25 t.Errorf("Invalid string true result: %#v", stringTrueResult) 26 } 27 28 stringFalseResult := convertResult("Something is wrong", nil) 29 if stringFalseResult.Status != gopter.PropFalse || 30 stringFalseResult.Error != nil || 31 !reflect.DeepEqual(stringFalseResult.Labels, []string{"Something is wrong"}) { 32 t.Errorf("Invalid string false result: %#v", stringFalseResult) 33 } 34 35 errorResult := convertResult("Anthing", errors.New("Booom")) 36 if errorResult.Status != gopter.PropError || errorResult.Error == nil || errorResult.Error.Error() != "Booom" { 37 t.Errorf("Invalid error result: %#v", errorResult) 38 } 39 40 propResult := convertResult(&gopter.PropResult{ 41 Status: gopter.PropProof, 42 }, nil) 43 if propResult.Status != gopter.PropProof || propResult.Error != nil { 44 t.Errorf("Invalid prop result: %#v", propResult) 45 } 46 47 invalidResult := convertResult(0, nil) 48 if invalidResult.Status != gopter.PropError || invalidResult.Error == nil { 49 t.Errorf("Invalid prop result: %#v", invalidResult) 50 } 51 }