Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test that verifies a bare state is not making any API calls. #3492

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions test/integration/api_int_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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))
}
Loading