Skip to content

Commit

Permalink
updating test location
Browse files Browse the repository at this point in the history
  • Loading branch information
eranturgeman committed Apr 9, 2024
1 parent 4fd91af commit e1c3a33
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
25 changes: 1 addition & 24 deletions utils/errorreport_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package utils

import (
"errors"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-cli-security/tests"
clienttestutils "github.com/jfrog/jfrog-client-go/utils/tests"
"github.com/stretchr/testify/assert"
"net/http"
Expand All @@ -17,27 +15,6 @@ const (
supportedXscVersionForErrorLogs = minXscVersionForErrorReport
)

func TestReportError(t *testing.T) {
serverDetails := &config.ServerDetails{
Url: *tests.JfrogUrl,
ArtifactoryUrl: *tests.JfrogUrl + tests.ArtifactoryEndpoint,
XrayUrl: *tests.JfrogUrl + tests.XrayEndpoint,
AccessToken: *tests.JfrogAccessToken,
ServerId: tests.ServerId,
}

// Prior to initiating the test, we verify whether Xsc is enabled for the customer. If not, the test is skipped.
xscManager, err := CreateXscServiceManager(serverDetails)
assert.NoError(t, err)

if !isReportLogErrorEventPossible(xscManager) {
t.Skip("Skipping test since Xsc server is not enabled or below minimal required version")
}

errorToReport := errors.New("THIS IS NOT A REAL ERROR! This Error is posted as part of TestReportError test")
assert.NoError(t, ReportError(serverDetails, errorToReport, "cli"))
}

func TestReportLogErrorEventPossible(t *testing.T) {
restoreEnvVarFunc := clienttestutils.SetEnvWithCallbackAndAssert(t, coreutils.ReportUsage, "")
defer restoreEnvVarFunc()
Expand Down Expand Up @@ -81,7 +58,7 @@ func TestReportLogErrorEventPossible(t *testing.T) {
mockServer, serverDetails := testcase.serverCreationFunc()
xscManager, err := CreateXscServiceManager(serverDetails)
assert.NoError(t, err)
reportPossible := isReportLogErrorEventPossible(xscManager)
reportPossible := IsReportLogErrorEventPossible(xscManager)
if testcase.expectedResponse {
assert.True(t, reportPossible)
} else {
Expand Down
4 changes: 2 additions & 2 deletions utils/xscmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ func CreateXscServiceManager(serviceDetails *config.ServerDetails) (*xsc.XscServ
}

func SendXscLogMessageIfEnabled(errorLog *services.ExternalErrorLog, xscManager *xsc.XscServicesManager) error {
if !isReportLogErrorEventPossible(xscManager) {
if !IsReportLogErrorEventPossible(xscManager) {
return nil
}
return xscManager.SendXscLogErrorRequest(errorLog)
}

// Determines if reporting the error is feasible.
func isReportLogErrorEventPossible(xscManager *xsc.XscServicesManager) bool {
func IsReportLogErrorEventPossible(xscManager *xsc.XscServicesManager) bool {
xscVersion, err := xscManager.GetVersion()
if err != nil {
log.Debug(fmt.Sprintf("failed to check availability of Xsc service:%s\nReporting to JFrog analytics is skipped...", err.Error()))
Expand Down
31 changes: 31 additions & 0 deletions xsc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"errors"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-security/tests"
"github.com/jfrog/jfrog-cli-security/utils"
"github.com/stretchr/testify/assert"
"testing"
)

func TestReportError(t *testing.T) {
serverDetails := &config.ServerDetails{
Url: *tests.JfrogUrl,
ArtifactoryUrl: *tests.JfrogUrl + tests.ArtifactoryEndpoint,
XrayUrl: *tests.JfrogUrl + tests.XrayEndpoint,
AccessToken: *tests.JfrogAccessToken,
ServerId: tests.ServerId,
}

// Prior to initiating the test, we verify whether Xsc is enabled for the customer. If not, the test is skipped.
xscManager, err := utils.CreateXscServiceManager(serverDetails)
assert.NoError(t, err)

if !utils.IsReportLogErrorEventPossible(xscManager) {
t.Skip("Skipping test since Xsc server is not enabled or below minimal required version")
}

errorToReport := errors.New("THIS IS NOT A REAL ERROR! This Error is posted as part of TestReportError test")
assert.NoError(t, utils.ReportError(serverDetails, errorToReport, "cli"))
}

0 comments on commit e1c3a33

Please sign in to comment.