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

     1  package integration
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/ActiveState/cli/internal/testhelpers/e2e"
     9  	"github.com/ActiveState/cli/internal/testhelpers/suite"
    10  	"github.com/ActiveState/cli/internal/testhelpers/tagsuite"
    11  )
    12  
    13  type PlatformsIntegrationTestSuite struct {
    14  	tagsuite.Suite
    15  }
    16  
    17  func (suite *PlatformsIntegrationTestSuite) TestPlatforms_searchSimple() {
    18  	suite.OnlyRunForTags(tagsuite.Platforms)
    19  	ts := e2e.New(suite.T(), false)
    20  	defer ts.Close()
    21  
    22  	ts.PrepareProject("cli-integration-tests/ExercisePlatforms", e2e.CommitIDNotChecked)
    23  
    24  	cp := ts.Spawn("platforms", "search")
    25  	expectations := []string{
    26  		"Darwin",
    27  		"Darwin",
    28  		"Linux",
    29  		"Linux",
    30  		"Windows",
    31  		"Windows",
    32  	}
    33  	for _, expectation := range expectations {
    34  		cp.Expect(expectation)
    35  	}
    36  	cp.ExpectExitCode(0)
    37  }
    38  
    39  func (suite *PlatformsIntegrationTestSuite) TestPlatforms_listSimple() {
    40  	suite.OnlyRunForTags(tagsuite.Platforms)
    41  	ts := e2e.New(suite.T(), false)
    42  	defer ts.Close()
    43  
    44  	ts.PrepareProject("cli-integration-tests/ExercisePlatforms", "f5a2494d-1b76-4a77-bafa-97b3562c5304")
    45  
    46  	cmds := [][]string{
    47  		{"platforms"},
    48  		{"platforms", "search"},
    49  	}
    50  	for _, cmd := range cmds {
    51  		cp := ts.Spawn(cmd...)
    52  		expectations := []string{
    53  			"Linux",
    54  			"4.15.0",
    55  			"64",
    56  		}
    57  		for _, expectation := range expectations {
    58  			cp.Expect(expectation)
    59  		}
    60  		cp.ExpectExitCode(0)
    61  	}
    62  }
    63  
    64  func (suite *PlatformsIntegrationTestSuite) TestPlatforms_addRemove() {
    65  	suite.OnlyRunForTags(tagsuite.Platforms)
    66  	ts := e2e.New(suite.T(), false)
    67  	defer ts.Close()
    68  
    69  	ts.LoginAsPersistentUser()
    70  
    71  	ts.PrepareProject("ActiveState-CLI/Platforms", "e685d3d8-98bc-4703-927f-e1d7225c6457")
    72  
    73  	platform := "Windows"
    74  	version := "10.0.17134.1"
    75  
    76  	cp := ts.Spawn("platforms", "add", fmt.Sprintf("%s@%s", platform, version))
    77  	cp.ExpectExitCode(0)
    78  
    79  	cp = ts.Spawn("platforms")
    80  	expectations := []string{
    81  		platform,
    82  		version,
    83  		"64",
    84  	}
    85  	for _, expectation := range expectations {
    86  		cp.Expect(expectation)
    87  	}
    88  
    89  	cp = ts.Spawn("platforms", "remove", fmt.Sprintf("%s@%s", platform, version))
    90  	cp.ExpectExitCode(0)
    91  
    92  	cp = ts.Spawn("platforms")
    93  	cp.ExpectExitCode(0)
    94  	output := cp.Output()
    95  	if strings.Contains(output, "Windows") {
    96  		suite.T().Fatal("Windows platform should not be present after removal")
    97  	}
    98  }
    99  
   100  func (suite *PlatformsIntegrationTestSuite) TestPlatforms_addRemoveLatest() {
   101  	suite.OnlyRunForTags(tagsuite.Platforms)
   102  	ts := e2e.New(suite.T(), false)
   103  	defer ts.Close()
   104  
   105  	ts.LoginAsPersistentUser()
   106  
   107  	ts.PrepareProject("ActiveState-CLI/Platforms", "e685d3d8-98bc-4703-927f-e1d7225c6457")
   108  
   109  	platform := "Windows"
   110  	version := "10.0.17134.1"
   111  
   112  	cp := ts.Spawn("platforms", "add", "windows")
   113  	cp.ExpectExitCode(0)
   114  
   115  	cp = ts.Spawn("platforms")
   116  	expectations := []string{
   117  		platform,
   118  		version,
   119  		"64",
   120  	}
   121  	for _, expectation := range expectations {
   122  		cp.Expect(expectation)
   123  	}
   124  
   125  	cp = ts.Spawn("platforms", "remove", fmt.Sprintf("%s@%s", platform, version))
   126  	cp.ExpectExitCode(0)
   127  
   128  	cp = ts.Spawn("platforms")
   129  	cp.ExpectExitCode(0)
   130  	output := cp.Output()
   131  	if strings.Contains(output, "Windows") {
   132  		suite.T().Fatal("Windows platform should not be present after removal")
   133  	}
   134  }
   135  
   136  func (suite *PlatformsIntegrationTestSuite) TestJSON() {
   137  	suite.OnlyRunForTags(tagsuite.Platforms, tagsuite.JSON)
   138  	ts := e2e.New(suite.T(), false)
   139  	defer ts.Close()
   140  
   141  	cp := ts.Spawn("checkout", "ActiveState-CLI/Python3", ".")
   142  	cp.Expect("Skipping runtime setup")
   143  	cp.Expect("Checked out")
   144  	cp.ExpectExitCode(0)
   145  
   146  	cp = ts.Spawn("platforms", "-o", "json")
   147  	cp.Expect(`[{"name":`)
   148  	cp.ExpectExitCode(0)
   149  	AssertValidJSON(suite.T(), cp)
   150  
   151  	cp = ts.Spawn("platforms", "search", "-o", "json")
   152  	cp.Expect(`[{"name":`)
   153  	cp.ExpectExitCode(0)
   154  	AssertValidJSON(suite.T(), cp)
   155  }
   156  
   157  func TestPlatformsIntegrationTestSuite(t *testing.T) {
   158  	suite.Run(t, new(PlatformsIntegrationTestSuite))
   159  }