-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(confirm) Options.Timeout was ignored, now works as documented
- Loading branch information
1 parent
1023911
commit cf0a8d1
Showing
2 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package confirm | ||
|
||
import ( | ||
"fmt" | ||
"github.com/charmbracelet/huh" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestOptions_errIsValidTimeout(t *testing.T) { | ||
type testCase struct { | ||
Description string | ||
GivenTimeout time.Duration | ||
GivenError error | ||
ExpectedResult bool | ||
} | ||
|
||
cases := []testCase{ | ||
{ | ||
Description: "timeout is positive, err is a timeout", | ||
GivenTimeout: time.Second, | ||
GivenError: huh.ErrTimeout, | ||
ExpectedResult: true, | ||
}, | ||
{ | ||
Description: "timeout is zero, err is a timeout", | ||
GivenTimeout: 0, | ||
GivenError: huh.ErrTimeout, | ||
ExpectedResult: false, | ||
}, | ||
{ | ||
Description: "timeout is positive, err is not a timeout", | ||
GivenTimeout: 1, | ||
GivenError: fmt.Errorf("i'm not a timeout"), | ||
ExpectedResult: false, | ||
}, | ||
{ | ||
Description: "timeout is zero, err is not a timeout", | ||
GivenTimeout: 0, | ||
GivenError: fmt.Errorf("i'm not a timeout"), | ||
ExpectedResult: false, | ||
}, | ||
} | ||
|
||
for _, testCase := range cases { | ||
t.Run(testCase.Description, func(t *testing.T) { | ||
sut := Options{Timeout: testCase.GivenTimeout} | ||
actualResult := sut.errIsValidTimeout(testCase.GivenError) | ||
if actualResult != testCase.ExpectedResult { | ||
t.Errorf("got: %v, want: %v", actualResult, testCase.ExpectedResult) | ||
} | ||
}) | ||
} | ||
} |