From 6384e98b4d8cf265953032c6550705dcd55580c8 Mon Sep 17 00:00:00 2001 From: Arko Dasgupta Date: Tue, 8 Aug 2023 20:48:31 -0700 Subject: [PATCH] add another test to improve coverage Signed-off-by: Arko Dasgupta --- api/run_test.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/api/run_test.go b/api/run_test.go index b7530774..d43a10b8 100644 --- a/api/run_test.go +++ b/api/run_test.go @@ -32,7 +32,7 @@ var ( runArgs = []string{"--version"} ) -func TestRun(t *testing.T) { +func TestRunWithCtxDone(t *testing.T) { tmpDir := t.TempDir() envoyVersion := version.LastKnownEnvoy @@ -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) @@ -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) + +}