github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/test/integration/import_int_test.go (about) 1 package integration 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 "runtime" 8 "strings" 9 "testing" 10 11 "github.com/ActiveState/cli/internal/testhelpers/e2e" 12 "github.com/ActiveState/cli/internal/testhelpers/suite" 13 "github.com/ActiveState/cli/internal/testhelpers/tagsuite" 14 ) 15 16 type ImportIntegrationTestSuite struct { 17 tagsuite.Suite 18 } 19 20 func (suite *ImportIntegrationTestSuite) TestImport_detached() { 21 suite.T().Skip("Skipping import test until DX-2444 is resolved: https://activestatef.atlassian.net/browse/DX-2444") 22 suite.OnlyRunForTags(tagsuite.Import) 23 if runtime.GOOS == "darwin" { 24 suite.T().Skip("Skipping mac for now as the builds are still too unreliable") 25 return 26 } 27 28 ts := e2e.New(suite.T(), false) 29 defer ts.Close() 30 31 cp := ts.Spawn("checkout", "ActiveState-CLI/Python3-Import", ".") 32 cp.Expect("Skipping runtime setup") 33 cp.Expect("Checked out project") 34 cp.ExpectExitCode(0) 35 36 contents := `requests 37 urllib3` 38 importPath := filepath.Join(ts.Dirs.Work, "requirements.txt") 39 40 err := os.WriteFile(importPath, []byte(strings.TrimSpace(contents)), 0644) 41 suite.Require().NoError(err) 42 43 cp = ts.Spawn("import", importPath) 44 cp.Expect("Operating on project") 45 cp.Expect("ActiveState-CLI/Python3-Import") 46 cp.ExpectExitCode(0) 47 48 cp = ts.Spawn("packages") 49 cp.Expect("requests") 50 cp.Expect("urllib3") 51 cp.ExpectExitCode(0) 52 } 53 54 const ( 55 reqsFileName = "requirements.txt" 56 reqsData = `Click==7.0 57 Flask==1.1.1 58 Flask-Cors==3.0.8 59 itsdangerous==1.1.0 60 Jinja2==2.10.3 61 MarkupSafe==1.1.1 62 packaging==20.3 63 pyparsing==2.4.6 64 six==1.14.0 65 Werkzeug==0.15.6 66 ` 67 badReqsData = `Click==7.0 68 garbage---<<001.X 69 six==1.14.0 70 ` 71 72 complexReqsData = `coverage!=3.5 73 docopt>=0.6.1 74 Mopidy-Dirble>=1.1,<2 75 requests>=2.2,<2.31.0 76 urllib3>=1.21.1,<=1.26.5 77 ` 78 ) 79 80 func (suite *ImportIntegrationTestSuite) TestImport() { 81 suite.T().Skip("Skipping import test until DX-2444 is resolved: https://activestatef.atlassian.net/browse/DX-2444") 82 suite.OnlyRunForTags(tagsuite.Import) 83 ts := e2e.New(suite.T(), false) 84 defer ts.Close() 85 86 user := ts.CreateNewUser() 87 namespace := fmt.Sprintf("%s/%s", user.Username, "Python3") 88 89 cp := ts.Spawn("init", "--language", "python", namespace, ts.Dirs.Work) 90 cp.Expect("successfully initialized") 91 cp.ExpectExitCode(0) 92 93 reqsFilePath := filepath.Join(cp.WorkDirectory(), reqsFileName) 94 95 suite.Run("invalid requirements.txt", func() { 96 ts.SetT(suite.T()) 97 ts.PrepareFile(reqsFilePath, badReqsData) 98 99 cp := ts.Spawn("import", "requirements.txt") 100 cp.ExpectNotExitCode(0) 101 }) 102 103 suite.Run("valid requirements.txt", func() { 104 ts.SetT(suite.T()) 105 ts.PrepareFile(reqsFilePath, reqsData) 106 107 cp := ts.Spawn("import", "requirements.txt") 108 cp.ExpectExitCode(0) 109 110 cp = ts.Spawn("push") 111 cp.ExpectExitCode(0) 112 113 cp = ts.Spawn("import", "requirements.txt") 114 cp.Expect("No new changes") 115 cp.ExpectNotExitCode(0) 116 }) 117 118 suite.Run("complex requirements.txt", func() { 119 ts.SetT(suite.T()) 120 ts.PrepareFile(reqsFilePath, complexReqsData) 121 122 cp := ts.Spawn("import", "requirements.txt") 123 cp.ExpectExitCode(0) 124 125 cp = ts.Spawn("packages") 126 cp.Expect("coverage") 127 cp.Expect("docopt") 128 cp.Expect("Mopidy-Dirble") 129 cp.Expect("requests") 130 cp.Expect("Auto") // DX-2272 will change this to 2.30.0 131 cp.Expect("urllib3") 132 cp.Expect("Auto") // DX-2272 will change this to 1.26.5 133 cp.ExpectExitCode(0) 134 }) 135 ts.IgnoreLogErrors() 136 } 137 138 func TestImportIntegrationTestSuite(t *testing.T) { 139 suite.Run(t, new(ImportIntegrationTestSuite)) 140 }