Skip to content

Commit

Permalink
Bring the message to the users back
Browse files Browse the repository at this point in the history
  • Loading branch information
kavir1698 committed May 6, 2024
1 parent fe7392e commit f54f9c1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
11 changes: 11 additions & 0 deletions datasetUtils/getAvailableDatasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func GetAvailableDatasets(username string, RSYNCServer string, singleDatasetId s
if singleDatasetId != "" {
datasetList = append(datasetList, formatDatasetId(singleDatasetId))
} else {
printMessage(RSYNCServer)
datasets, err := fetchDatasetsFromServer(username, RSYNCServer)
if err != nil {
return nil, err
Expand Down Expand Up @@ -94,3 +95,13 @@ var getRsyncVersion = func() (string, error) {

return versionNumber, nil
}

func printMessage(RSYNCServer string) {
var message strings.Builder
message.WriteString("\n\n\n====== Checking for available datasets on archive cache server ")
message.WriteString(RSYNCServer)
message.WriteString(":\n====== (only datasets highlighted in green will be retrieved)\n\n")
message.WriteString("====== If you can not find the dataset in this listing: may be you forgot\n")
message.WriteString("====== to start the necessary retrieve job from the the data catalog first?\n\n")
fmt.Print(message.String())
}
32 changes: 32 additions & 0 deletions datasetUtils/getAvailableDatasets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
"testing"
"reflect"
"os/exec"
"os"
"bytes"
"io"
"strings"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -76,3 +80,31 @@ func TestFormatDatasetId(t *testing.T) {
t.Errorf("Expected %s, but got %s", expected, actual)
}
}

func TestPrintMessage(t *testing.T) {
RSYNCServer := "testServer"

expected := "\n\n\n====== Checking for available datasets on archive cache server testServer:\n"
expected += "====== (only datasets highlighted in green will be retrieved)\n\n"
expected += "====== If you can not find the dataset in this listing: may be you forgot\n"
expected += "====== to start the necessary retrieve job from the the data catalog first?\n\n"

// Redirect standard output to a buffer
old := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w

printMessage(RSYNCServer)

// Restore standard output
w.Close()
os.Stdout = old

var buf bytes.Buffer
io.Copy(&buf, r)
actual := buf.String()

if !strings.EqualFold(expected, actual) {
t.Errorf("Expected %s, but got %s", expected, actual)
}
}

0 comments on commit f54f9c1

Please sign in to comment.