From 55d90ba719b640b7135ebdfef50e5e49185a043b Mon Sep 17 00:00:00 2001 From: mitchell Date: Tue, 17 Sep 2024 11:35:00 -0400 Subject: [PATCH] Added test that verifies a bare `state` is not making any API calls. --- test/integration/api_int_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/integration/api_int_test.go b/test/integration/api_int_test.go index cb656871cc..c00cf5c6a6 100644 --- a/test/integration/api_int_test.go +++ b/test/integration/api_int_test.go @@ -1,9 +1,12 @@ package integration import ( + "path/filepath" + "strings" "testing" "github.com/ActiveState/cli/internal/constants" + "github.com/ActiveState/cli/internal/fileutils" "github.com/ActiveState/cli/internal/testhelpers/e2e" "github.com/ActiveState/cli/internal/testhelpers/suite" "github.com/ActiveState/cli/internal/testhelpers/tagsuite" @@ -29,6 +32,30 @@ func (suite *ApiIntegrationTestSuite) TestRequestHeaders() { cp.ExpectExitCode(0) } +// TestNoApiCallsForPlainInvocation asserts that a bare `state` does not make any API calls. +func (suite *ApiIntegrationTestSuite) TestNoApiCallsForPlainInvocation() { + suite.OnlyRunForTags(tagsuite.Critical) + + ts := e2e.New(suite.T(), false) + defer ts.Close() + + cp := ts.SpawnWithOpts( + e2e.OptAppendEnv(constants.DebugServiceRequestsEnvVarName + "=true"), + ) + cp.ExpectExitCode(0) + + readLogFile := false + for _, path := range ts.LogFiles() { + if !strings.HasPrefix(filepath.Base(path), "state-") { + continue + } + contents := string(fileutils.ReadFileUnsafe(path)) + suite.Assert().NotContains(contents, "URL: ") // pkg/platform/api logs URL, User-Agent, and X-Requestor for API calls + readLogFile = true + } + suite.Assert().True(readLogFile, "did not read log file") +} + func TestApiIntegrationTestSuite(t *testing.T) { suite.Run(t, new(ApiIntegrationTestSuite)) }