github.com/argoproj/argo-cd@v1.8.7/util/ksonnet/ksonnet_test.go (about)

     1  package ksonnet
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"path/filepath"
     7  	"regexp"
     8  	"runtime"
     9  	"testing"
    10  
    11  	log "github.com/sirupsen/logrus"
    12  	"github.com/stretchr/testify/assert"
    13  )
    14  
    15  var (
    16  	testDataDir string
    17  )
    18  
    19  const (
    20  	testAppName = "ksonnet"
    21  	testEnvName = "prod"
    22  )
    23  
    24  func init() {
    25  	_, filename, _, _ := runtime.Caller(0)
    26  	testDataDir = filepath.Join(filepath.Dir(filename), "../../test/e2e/testdata")
    27  }
    28  
    29  func TestKsonnet(t *testing.T) {
    30  	ksApp, err := NewKsonnetApp(filepath.Join(testDataDir, testAppName))
    31  	assert.Nil(t, err)
    32  	defaultDest, err := ksApp.Destination(testEnvName)
    33  	assert.True(t, err == nil)
    34  	assert.Equal(t, "https://kubernetes.default.svc", defaultDest.Server)
    35  }
    36  
    37  func TestShow(t *testing.T) {
    38  	ksApp, err := NewKsonnetApp(filepath.Join(testDataDir, testAppName))
    39  	assert.Nil(t, err)
    40  	objs, err := ksApp.Show(testEnvName)
    41  	assert.Nil(t, err)
    42  	assert.Equal(t, 2, len(objs))
    43  	for _, obj := range objs {
    44  		jsonBytes, err := json.Marshal(obj)
    45  		assert.Nil(t, err)
    46  		log.Infof("%v", string(jsonBytes))
    47  	}
    48  }
    49  
    50  func TestVersion(t *testing.T) {
    51  	ver, err := Version()
    52  	assert.NoError(t, err)
    53  	SemverRegexValidation := `^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$`
    54  	re := regexp.MustCompile(SemverRegexValidation)
    55  	fmt.Println(ver)
    56  	assert.True(t, re.MatchString(ver))
    57  }