Skip to content

Commit

Permalink
Merge pull request #3492 from ActiveState/mitchell/dx-2897
Browse files Browse the repository at this point in the history
Added test that verifies a bare `state` is not making any API calls.
  • Loading branch information
mitchell-as authored Sep 17, 2024
2 parents 7bc2caa + 55d90ba commit 42309b3
Showing 1 changed file with 27 additions and 0 deletions.
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))
}

0 comments on commit 42309b3

Please sign in to comment.