github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/test/integration/upgen_int_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path/filepath"
     7  	"runtime"
     8  	"testing"
     9  
    10  	"github.com/ActiveState/cli/internal/installation"
    11  	"github.com/ActiveState/cli/internal/osutils"
    12  	"github.com/ActiveState/cli/internal/testhelpers/suite"
    13  
    14  	"github.com/ActiveState/cli/internal/constants"
    15  	"github.com/ActiveState/cli/internal/environment"
    16  	"github.com/ActiveState/cli/internal/testhelpers/e2e"
    17  	"github.com/ActiveState/cli/internal/testhelpers/tagsuite"
    18  )
    19  
    20  type UpdateGenIntegrationTestSuite struct {
    21  	tagsuite.Suite
    22  }
    23  
    24  func (suite *UpdateGenIntegrationTestSuite) TestUpdateBits() {
    25  	suite.OnlyRunForTags(tagsuite.CLIDeploy, tagsuite.Critical)
    26  	root := environment.GetRootPathUnsafe()
    27  
    28  	ext := ".tar.gz"
    29  	if runtime.GOOS == "windows" {
    30  		ext = ".zip"
    31  	}
    32  	hostArch := runtime.GOARCH
    33  	if runtime.GOOS == "darwin" && hostArch == "arm64" {
    34  		hostArch = "amd64"
    35  	}
    36  	platform := runtime.GOOS + "-" + hostArch
    37  
    38  	archivePath := filepath.Join(root, "build/update", constants.ChannelName, constants.VersionNumber, platform, fmt.Sprintf("state-%s-%s%s", platform, constants.Version, ext))
    39  	suite.Require().FileExists(archivePath, "Make sure you ran 'state run generate-update'")
    40  	suite.T().Logf("file %s exists\n", archivePath)
    41  
    42  	tempPath, err := os.MkdirTemp("", "")
    43  	suite.Require().NoError(err)
    44  
    45  	ts := e2e.New(suite.T(), false)
    46  	defer ts.Close()
    47  
    48  	var cp *e2e.SpawnedCmd
    49  
    50  	if runtime.GOOS == "windows" {
    51  		cp = ts.SpawnCmd("powershell.exe", "-nologo", "-noprofile", "-command",
    52  			fmt.Sprintf("Expand-Archive -Path '%s' -DestinationPath '%s'", archivePath, tempPath))
    53  	} else {
    54  		cp = ts.SpawnCmd("tar", "-C", tempPath, "-xf", archivePath)
    55  	}
    56  
    57  	cp.ExpectExitCode(0)
    58  
    59  	baseDir := filepath.Join(tempPath, constants.LegacyToplevelInstallArchiveDir)
    60  	suite.FileExists(filepath.Join(baseDir, installation.BinDirName, constants.StateCmd+osutils.ExeExtension))
    61  	suite.FileExists(filepath.Join(baseDir, installation.BinDirName, constants.StateSvcCmd+osutils.ExeExtension))
    62  }
    63  
    64  func TestUpdateGenIntegrationTestSuite(t *testing.T) {
    65  	suite.Run(t, new(UpdateGenIntegrationTestSuite))
    66  }