Skip to content

Commit 74ceb85

Browse files
committed
Add E2E tests
1 parent cbae5f8 commit 74ceb85

File tree

8 files changed

+233
-223
lines changed

8 files changed

+233
-223
lines changed

e2e/application_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ import (
66
"strings"
77
"testing"
88

9+
"github.com/jfrog/jfrog-cli-application/e2e/utils"
910
"github.com/stretchr/testify/assert"
1011
)
1112

1213
func TestCreateApp(t *testing.T) {
13-
projectKey := GetTestProjectKey(t)
14-
appKey := generateUniqueKey("app-create")
14+
projectKey := utils.GetTestProjectKey(t)
15+
appKey := utils.GenerateUniqueKey("app-create")
1516
appName := "Full Test Application"
1617
description := "Application with all fields populated"
1718
businessCriticality := "critical"
1819
maturityLevel := "production"
1920
userOwners := []string{"admin", "developer"}
2021
groupOwners := []string{"devops-team", "security-team"}
2122

22-
err := AppTrustCli.Exec("app-create", appKey,
23+
err := utils.AppTrustCli.Exec("app-create", appKey,
2324
"--project="+projectKey,
2425
"--application-name="+appName,
2526
"--desc="+description,
@@ -31,7 +32,7 @@ func TestCreateApp(t *testing.T) {
3132
assert.NoError(t, err)
3233

3334
// Fetch and verify the application was created correctly
34-
app, _, err := getApplication(appKey)
35+
app, _, err := utils.GetApplication(appKey)
3536
assert.NoError(t, err)
3637
assert.Equal(t, appKey, app.ApplicationKey)
3738
assert.Equal(t, appName, app.ApplicationName)
@@ -43,24 +44,23 @@ func TestCreateApp(t *testing.T) {
4344
assert.Equal(t, userOwners, *app.UserOwners)
4445
assert.Equal(t, groupOwners, *app.GroupOwners)
4546

46-
deleteApplication(t, appKey)
47+
utils.DeleteApplication(t, appKey)
4748
}
4849

4950
func TestUpdateApp(t *testing.T) {
50-
projectKey := GetTestProjectKey(t)
51-
appKey := generateUniqueKey("app-update")
51+
projectKey := utils.GetTestProjectKey(t)
52+
appKey := utils.GenerateUniqueKey("app-update")
5253

53-
createBasicApplication(t, appKey)
54+
utils.CreateBasicApplication(t, appKey)
5455

55-
// Update the application with new values
5656
updatedAppName := "Updated Test Application"
5757
updatedDescription := "Updated description"
5858
updatedBusinessCriticality := "high"
5959
updatedMaturityLevel := "production"
6060
updatedUserOwners := []string{"app-admin", "frog"}
6161
updatedGroupOwners := []string{"dev-team", "security-team"}
6262

63-
err := AppTrustCli.Exec("app-update", appKey,
63+
err := utils.AppTrustCli.Exec("app-update", appKey,
6464
"--application-name="+updatedAppName,
6565
"--desc="+updatedDescription,
6666
"--business-criticality="+updatedBusinessCriticality,
@@ -71,7 +71,7 @@ func TestUpdateApp(t *testing.T) {
7171
assert.NoError(t, err)
7272

7373
// Fetch and verify the application was updated correctly
74-
app, _, err := getApplication(appKey)
74+
app, _, err := utils.GetApplication(appKey)
7575
assert.NoError(t, err)
7676
assert.Equal(t, appKey, app.ApplicationKey)
7777
assert.Equal(t, updatedAppName, app.ApplicationName)
@@ -83,24 +83,24 @@ func TestUpdateApp(t *testing.T) {
8383
assert.Equal(t, updatedUserOwners, *app.UserOwners)
8484
assert.Equal(t, updatedGroupOwners, *app.GroupOwners)
8585

86-
deleteApplication(t, appKey)
86+
utils.DeleteApplication(t, appKey)
8787
}
8888

8989
func TestDeleteApp(t *testing.T) {
90-
appKey := generateUniqueKey("app-delete")
91-
createBasicApplication(t, appKey)
90+
appKey := utils.GenerateUniqueKey("app-delete")
91+
utils.CreateBasicApplication(t, appKey)
9292

9393
// Verify the application exists
94-
app, _, err := getApplication(appKey)
94+
app, _, err := utils.GetApplication(appKey)
9595
assert.NoError(t, err)
9696
assert.Equal(t, appKey, app.ApplicationKey)
9797

9898
// Delete the application
99-
err = AppTrustCli.Exec("app-delete", appKey)
99+
err = utils.AppTrustCli.Exec("app-delete", appKey)
100100
assert.NoError(t, err)
101101

102102
// Verify the application no longer exists
103-
_, statusCode, err := getApplication(appKey)
103+
_, statusCode, err := utils.GetApplication(appKey)
104104
assert.NoError(t, err)
105105
assert.Equal(t, 404, statusCode)
106106
}

e2e/main_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import (
77
"testing"
88

99
"github.com/jfrog/jfrog-cli-application/cli"
10+
"github.com/jfrog/jfrog-cli-application/e2e/utils"
1011
"github.com/jfrog/jfrog-cli-core/v2/plugins"
1112
coreTests "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
1213
)
1314

1415
func TestMain(m *testing.M) {
15-
loadCredentials()
16-
AppTrustCli = coreTests.NewJfrogCli(plugins.RunCliWithPlugin(cli.GetJfrogCliApptrustApp()), "jf at", credentials)
16+
credentials := utils.LoadCredentials()
17+
utils.AppTrustCli = coreTests.NewJfrogCli(plugins.RunCliWithPlugin(cli.GetJfrogCliApptrustApp()), "jf at", credentials)
1718
code := m.Run()
18-
deleteTestProject()
19+
utils.DeleteTestProject()
1920
os.Exit(code)
2021
}

e2e/package_test.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,58 @@ import (
66
"net/http"
77
"testing"
88

9+
"github.com/jfrog/jfrog-cli-application/e2e/utils"
910
"github.com/stretchr/testify/assert"
1011
"github.com/stretchr/testify/require"
1112
)
1213

1314
func TestBindPackage(t *testing.T) {
1415
// Prepare
15-
appKey := generateUniqueKey("package-bind")
16-
createBasicApplication(t, appKey)
17-
defer deleteApplication(t, appKey)
18-
testPackage := getTestPackage(t)
16+
appKey := utils.GenerateUniqueKey("package-bind")
17+
utils.CreateBasicApplication(t, appKey)
18+
defer utils.DeleteApplication(t, appKey)
19+
testPackage := utils.GetTestPackage(t)
1920

2021
// Execute
21-
err := AppTrustCli.Exec("package-bind", appKey, testPackage.packageType, testPackage.packageName, testPackage.packageVersion)
22+
err := utils.AppTrustCli.Exec("package-bind", appKey, testPackage.PackageType, testPackage.PackageName, testPackage.PackageVersion)
2223
require.NoError(t, err)
2324

2425
// Assert
25-
response, statusCode, err := getPackageBindings(appKey)
26+
response, statusCode, err := utils.GetPackageBindings(appKey)
2627
require.NoError(t, err)
2728
assert.Equal(t, http.StatusOK, statusCode)
2829
require.NotNil(t, response)
2930
assert.Len(t, response.Packages, 1)
30-
assert.Equal(t, testPackage.packageType, response.Packages[0].Type)
31-
assert.Equal(t, testPackage.packageName, response.Packages[0].Name)
31+
assert.Equal(t, testPackage.PackageType, response.Packages[0].Type)
32+
assert.Equal(t, testPackage.PackageName, response.Packages[0].Name)
3233
assert.Equal(t, 1, response.Packages[0].NumVersions)
33-
assert.Equal(t, testPackage.packageVersion, response.Packages[0].LatestVersion)
34+
assert.Equal(t, testPackage.PackageVersion, response.Packages[0].LatestVersion)
3435
}
3536

3637
func TestUnbindPackage(t *testing.T) {
3738
// Prepare
38-
appKey := generateUniqueKey("package-unbind")
39-
createBasicApplication(t, appKey)
40-
defer deleteApplication(t, appKey)
41-
testPackage := getTestPackage(t)
39+
appKey := utils.GenerateUniqueKey("package-unbind")
40+
utils.CreateBasicApplication(t, appKey)
41+
defer utils.DeleteApplication(t, appKey)
42+
testPackage := utils.GetTestPackage(t)
4243

4344
// First bind the package
44-
err := AppTrustCli.Exec("package-bind", appKey, testPackage.packageType, testPackage.packageName, testPackage.packageVersion)
45+
err := utils.AppTrustCli.Exec("package-bind", appKey, testPackage.PackageType, testPackage.PackageName, testPackage.PackageVersion)
4546
require.NoError(t, err)
4647

4748
// Verify it's bound
48-
bindings, statusCode, err := getPackageBindings(appKey)
49+
bindings, statusCode, err := utils.GetPackageBindings(appKey)
4950
require.NoError(t, err)
5051
assert.Equal(t, http.StatusOK, statusCode)
5152
require.NotNil(t, bindings)
5253
assert.Len(t, bindings.Packages, 1)
5354

5455
// Unbind the package
55-
err = AppTrustCli.Exec("package-unbind", appKey, testPackage.packageType, testPackage.packageName, testPackage.packageVersion)
56+
err = utils.AppTrustCli.Exec("package-unbind", appKey, testPackage.PackageType, testPackage.PackageName, testPackage.PackageVersion)
5657
require.NoError(t, err)
5758

5859
// Verify the package is no longer bound
59-
bindings, statusCode, err = getPackageBindings(appKey)
60+
bindings, statusCode, err = utils.GetPackageBindings(appKey)
6061
require.NoError(t, err)
6162
assert.Equal(t, http.StatusOK, statusCode)
6263
require.NotNil(t, bindings)

e2e/system_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ package e2e
55
import (
66
"testing"
77

8+
"github.com/jfrog/jfrog-cli-application/e2e/utils"
89
"github.com/stretchr/testify/assert"
910
)
1011

1112
func TestPing(t *testing.T) {
12-
output := AppTrustCli.RunCliCmdWithOutput(t, "ping")
13+
output := utils.AppTrustCli.RunCliCmdWithOutput(t, "ping")
1314
assert.Contains(t, output, "OK")
1415
}
Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//go:build e2e
22

3-
package e2e
3+
package utils
44

55
import (
66
"flag"
@@ -19,29 +19,28 @@ const (
1919
testJfrogTokenEnvVar = "JFROG_APPTRUST_CLI_TESTS_JFROG_ACCESS_TOKEN"
2020
)
2121

22-
type testPackageResources struct {
23-
packageType string
24-
packageName string
25-
packageVersion string
26-
packagePath string
27-
buildName string
28-
buildNumber string
22+
type TestPackageResources struct {
23+
PackageType string
24+
PackageName string
25+
PackageVersion string
26+
PackagePath string
27+
RepoKey string
28+
BuildName string
29+
BuildNumber string
2930
}
3031

3132
var (
3233
serverDetails *coreConfig.ServerDetails
3334
artifactoryServicesManager artifactory.ArtifactoryServicesManager
3435

35-
credentials string
3636
AppTrustCli *coreTests.JfrogCli
3737

3838
testProjectKey string
39-
testRepoKey string
40-
testPackageRes *testPackageResources
39+
testPackageRes *TestPackageResources
4140
)
4241

43-
func loadCredentials() {
44-
platformUrlFlag := flag.String("jfrog.url", getTestUrlDefaultValue(), "JFrog Platform URL")
42+
func LoadCredentials() string {
43+
platformUrlFlag := flag.String("jfrog.url", getTestPlatformUrlFromEnvVar(), "JFrog Platform URL")
4544
accessTokenFlag := flag.String("jfrog.adminToken", os.Getenv(testJfrogTokenEnvVar), "JFrog Platform admin token")
4645
platformUrl := clientUtils.AddTrailingSlashIfNeeded(*platformUrlFlag)
4746

@@ -51,10 +50,10 @@ func loadCredentials() {
5150
LifecycleUrl: platformUrl + "lifecycle/",
5251
AccessToken: *accessTokenFlag,
5352
}
54-
credentials = fmt.Sprintf("--url=%s --access-token=%s", *platformUrlFlag, *accessTokenFlag)
53+
return fmt.Sprintf("--url=%s --access-token=%s", *platformUrlFlag, *accessTokenFlag)
5554
}
5655

57-
func getTestUrlDefaultValue() string {
56+
func getTestPlatformUrlFromEnvVar() string {
5857
if os.Getenv(testJfrogUrlEnvVar) != "" {
5958
return os.Getenv(testJfrogUrlEnvVar)
6059
}
@@ -68,7 +67,7 @@ func GetTestProjectKey(t *testing.T) string {
6867
return testProjectKey
6968
}
7069

71-
func getTestPackage(t *testing.T) *testPackageResources {
70+
func GetTestPackage(t *testing.T) *TestPackageResources {
7271
// Upload the test package to Artifactory if not already done
7372
if testPackageRes == nil {
7473
uploadPackageToArtifactory(t)

0 commit comments

Comments
 (0)