Skip to content

Commit

Permalink
add another test to improve coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Arko Dasgupta <[email protected]>
  • Loading branch information
arkodg committed Aug 9, 2023
1 parent 8b44356 commit 6384e98
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions api/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (
runArgs = []string{"--version"}
)

func TestRun(t *testing.T) {
func TestRunWithCtxDone(t *testing.T) {

tmpDir := t.TempDir()
envoyVersion := version.LastKnownEnvoy
Expand All @@ -44,7 +44,8 @@ func TestRun(t *testing.T) {
require.Equal(t, 0, b.Len())

ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
// Use a very small ctx timeout
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
defer cancel()
err := Run(ctx, runArgs, Out(b), HomeDir(tmpDir), EnvoyVersionsURL(envoyVersionsURL))
require.NoError(t, err)
Expand All @@ -53,3 +54,28 @@ func TestRun(t *testing.T) {
_, err = os.Stat(filepath.Join(tmpDir, "versions"))
require.NoError(t, err)
}

func TestRunToCompletion(t *testing.T) {

tmpDir := t.TempDir()
envoyVersion := version.LastKnownEnvoy
versionsServer := test.RequireEnvoyVersionsTestServer(t, envoyVersion)
defer versionsServer.Close()
envoyVersionsURL := versionsServer.URL + "/envoy-versions.json"
b := bytes.NewBufferString("")

require.Equal(t, 0, b.Len())

ctx := context.Background()
// Set a large ctx timeout value
ctx, cancel := context.WithTimeout(ctx, 1000*time.Minute)
defer cancel()

err := Run(ctx, runArgs, Out(b), HomeDir(tmpDir), EnvoyVersionsURL(envoyVersionsURL))
require.NoError(t, err)

require.NotEqual(t, 0, b.Len())
_, err = os.Stat(filepath.Join(tmpDir, "versions"))
require.NoError(t, err)

}

0 comments on commit 6384e98

Please sign in to comment.