github.com/jfrog/jfrog-cli-core/v2@v2.52.0/pipelines/commands/syncstatus_test.go (about)

     1  package commands
     2  
     3  import (
     4  	"bytes"
     5  	"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/transferfiles/state"
     6  	"github.com/jfrog/jfrog-cli-core/v2/utils/config"
     7  	"github.com/jfrog/jfrog-cli-core/v2/utils/tests"
     8  	"github.com/jfrog/jfrog-client-go/pipelines/services"
     9  	"github.com/jfrog/jfrog-client-go/utils/log"
    10  	"github.com/stretchr/testify/assert"
    11  	"testing"
    12  	"time"
    13  )
    14  
    15  func initDisplaySyncStatusTest(t *testing.T) (*bytes.Buffer, func()) {
    16  	cleanUpJfrogHome, err := tests.SetJfrogHome()
    17  	assert.NoError(t, err)
    18  
    19  	// Redirect log to buffer
    20  	buffer, _, previousLog := tests.RedirectLogOutputToBuffer()
    21  
    22  	undoSaveInterval := state.SetAutoSaveState()
    23  	return buffer, func() {
    24  		undoSaveInterval()
    25  		log.SetLogger(previousLog)
    26  		cleanUpJfrogHome()
    27  	}
    28  }
    29  
    30  func TestSyncStatusCommand_displaySyncStatus(t *testing.T) {
    31  	buffer, cleanup := initDisplaySyncStatusTest(t)
    32  	defer cleanup()
    33  
    34  	// Create pipeline sync status response
    35  	pipelineSyncStatuses := createPipelinesSyncStatus()
    36  
    37  	t.Run("Should print these expected details to standard output", func(t *testing.T) {
    38  		sc := &SyncStatusCommand{
    39  			serverDetails: &config.ServerDetails{},
    40  			branch:        "master",
    41  			repoPath:      "jfrog/jfrog-cli-core",
    42  		}
    43  		sc.displaySyncStatus(pipelineSyncStatuses)
    44  		results := buffer.String()
    45  		assert.Contains(t, results, "Committer: testUser")
    46  		assert.Contains(t, results, "CommitSHA: 83749i34urbjbrjkrwoeurheiwrhtt35")
    47  		assert.Contains(t, results, "CommitMessage: Added test cases")
    48  		assert.Contains(t, results, "SyncSummary: Sync is in progress")
    49  		assert.Contains(t, results, "IsSyncing: true")
    50  		assert.Contains(t, results, "Status: success")
    51  	})
    52  }
    53  
    54  func createPipelinesSyncStatus() []services.PipelineSyncStatus {
    55  	isSyncing := true
    56  	commitDetails := services.CommitData{
    57  		CommitSha: "83749i34urbjbrjkrwoeurheiwrhtt35",
    58  		Committer: "testUser",
    59  		CommitMsg: "Added test cases",
    60  	}
    61  	pipelineSyncStatus := services.PipelineSyncStatus{
    62  		IsSyncing:          &isSyncing,
    63  		LastSyncStartedAt:  time.Now(),
    64  		LastSyncEndedAt:    time.Now().Add(2 * time.Minute),
    65  		CommitData:         commitDetails,
    66  		LastSyncLogs:       "Sync is in progress",
    67  		LastSyncStatusCode: 4002,
    68  	}
    69  	return []services.PipelineSyncStatus{pipelineSyncStatus}
    70  }