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

     1  package integration
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/ActiveState/cli/internal/constants"
     7  	"github.com/ActiveState/cli/internal/testhelpers/e2e"
     8  	"github.com/ActiveState/cli/internal/testhelpers/suite"
     9  	"github.com/ActiveState/cli/internal/testhelpers/tagsuite"
    10  )
    11  
    12  type ConfigIntegrationTestSuite struct {
    13  	tagsuite.Suite
    14  }
    15  
    16  func (suite *ConfigIntegrationTestSuite) TestConfig() {
    17  	suite.OnlyRunForTags(tagsuite.Config)
    18  	ts := e2e.New(suite.T(), false)
    19  	defer ts.Close()
    20  
    21  	cp := ts.Spawn("config", "set", "invalid++", "value")
    22  	cp.Expect("Invalid")
    23  	cp.ExpectExitCode(1)
    24  	ts.IgnoreLogErrors()
    25  
    26  	cp = ts.Spawn("config", "set", constants.UnstableConfig, "true")
    27  	cp.Expect("Successfully")
    28  	cp.ExpectExitCode(0)
    29  
    30  	cp = ts.Spawn("config", "get", constants.UnstableConfig)
    31  	cp.Expect("true")
    32  
    33  	cp = ts.Spawn("config", "set", constants.UnstableConfig, "false")
    34  	cp.Expect("Successfully")
    35  	cp.ExpectExitCode(0)
    36  
    37  	cp = ts.Spawn("config", "get", constants.UnstableConfig)
    38  	cp.Expect("false")
    39  
    40  	cp = ts.Spawn("config", "set", constants.UnstableConfig, "oops")
    41  	cp.Expect("Invalid boolean value")
    42  }
    43  
    44  func (suite *ConfigIntegrationTestSuite) TestJSON() {
    45  	suite.OnlyRunForTags(tagsuite.Config, tagsuite.JSON)
    46  	ts := e2e.New(suite.T(), false)
    47  	defer ts.Close()
    48  
    49  	cp := ts.Spawn("config", "set", constants.UnstableConfig, "true", "-o", "json")
    50  	cp.Expect(`"name":`)
    51  	cp.Expect(`"value":`)
    52  	cp.ExpectExitCode(0)
    53  	AssertValidJSON(suite.T(), cp)
    54  
    55  	cp = ts.Spawn("config", "get", constants.UnstableConfig, "-o", "json")
    56  	cp.Expect(`"name":`)
    57  	cp.Expect(`"value":`)
    58  	cp.ExpectExitCode(0)
    59  	AssertValidJSON(suite.T(), cp)
    60  }
    61  
    62  func TestConfigIntegrationTestSuite(t *testing.T) {
    63  	suite.Run(t, new(ConfigIntegrationTestSuite))
    64  }