github.com/jfrog/frogbot@v1.1.1-0.20231221090046-821a26f50338/main_test.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/jfrog/frogbot/utils"
     6  	"github.com/jfrog/jfrog-client-go/utils/log"
     7  	clientTests "github.com/jfrog/jfrog-client-go/utils/tests"
     8  	"io"
     9  	"os"
    10  	"strings"
    11  	"testing"
    12  
    13  	"github.com/stretchr/testify/assert"
    14  )
    15  
    16  var IntegrationTestPackages = []string{
    17  	"github.com/jfrog/frogbot",
    18  	"github.com/jfrog/frogbot/scanrepository",
    19  	"github.com/jfrog/frogbot/scanpullrequest",
    20  	"github.com/jfrog/frogbot/packagehandlers",
    21  }
    22  
    23  func TestUnitTests(t *testing.T) {
    24  	packages := clientTests.GetTestPackages("./...")
    25  	for _, integrationPackage := range IntegrationTestPackages {
    26  		packages = clientTests.ExcludeTestsPackage(packages, integrationPackage)
    27  	}
    28  	log.Info("Running Unit tests on the following packages:\n", strings.Join(packages, "\n"))
    29  	assert.NoError(t, clientTests.RunTests(packages, false))
    30  }
    31  
    32  func TestVersion(t *testing.T) {
    33  	originalStdout := os.Stdout
    34  	r, w, _ := os.Pipe()
    35  	defer func() {
    36  		os.Stdout = originalStdout
    37  	}()
    38  	os.Stdout = w
    39  
    40  	os.Args = []string{"frogbot", "--version"}
    41  	main()
    42  
    43  	assert.NoError(t, w.Close())
    44  	out, err := io.ReadAll(r)
    45  	assert.NoError(t, err)
    46  	expectedVersion := fmt.Sprintf("Frogbot version %s", utils.FrogbotVersion)
    47  	assert.Equal(t, expectedVersion, strings.TrimSpace(string(out)))
    48  }