Skip to content

Commit

Permalink
Add tests for retry behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
rednafi committed Feb 9, 2024
1 parent 6008876 commit dbead98
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,40 @@ func TestCLI_ErrorOkExitsWithCodeZero(t *testing.T) {
assert.Contains(t, out.String(), "OK : false\n")
}

func TestCLI_Retry(t *testing.T) {
// Create a sample markdown file
filePath := MakeMockMarkdownFile()

// Capture the output by using a bytes.Buffer
var out bytes.Buffer
w := tabwriter.NewWriter(&out, 0, 4, 4, ' ', 0)
defer w.Flush()

// Simulate executing -f and -e flags
args := os.Args[0:1] // Keep the program name only
args = append(
args,
"-f",
filePath,
"-t",
"200ms",
"--max-retries",
"2",
"--start-backoff",
"100ms",
"--max-backoff",
"200ms",
)
os.Args = args

CLI(w, "0.1.0-test", os.Exit)

// Verify that the CLI exits with code 0. This means the program did not
// encounter any errors
fmt.Println(out.String())
assert.Contains(t, out.String(), "Attempt : 2\n\n")
}

// Benchmark for checkUrls
func BenchmarkCheckUrls(b *testing.B) {
ts := httptest.NewServer(
Expand Down

0 comments on commit dbead98

Please sign in to comment.