github.com/argoproj/argo-cd/v3@v3.2.1/test/e2e/fixture/versions.go (about) 1 package fixture 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "strings" 7 "testing" 8 9 "github.com/argoproj/gitops-engine/pkg/cache" 10 "github.com/argoproj/gitops-engine/pkg/utils/kube" 11 "github.com/stretchr/testify/require" 12 13 "github.com/argoproj/argo-cd/v3/util/argo" 14 "github.com/argoproj/argo-cd/v3/util/errors" 15 kubeutil "github.com/argoproj/argo-cd/v3/util/kube" 16 ) 17 18 type Versions struct { 19 ServerVersion Version 20 } 21 22 type Version struct { 23 Major, Minor string 24 } 25 26 func (v Version) String() string { 27 return v.Format("%s.%s") 28 } 29 30 func (v Version) Format(format string) string { 31 return fmt.Sprintf(format, v.Major, v.Minor) 32 } 33 34 func GetVersions(t *testing.T) *Versions { 35 t.Helper() 36 output := errors.NewHandler(t).FailOnErr(Run(".", "kubectl", "version", "-o", "json")).(string) 37 version := &Versions{} 38 require.NoError(t, json.Unmarshal([]byte(output), version)) 39 return version 40 } 41 42 func GetApiResources(t *testing.T) string { //nolint:revive //FIXME(var-naming) 43 t.Helper() 44 kubectl := kubeutil.NewKubectl() 45 resources := errors.NewHandler(t).FailOnErr(kubectl.GetAPIResources(KubeConfig, false, cache.NewNoopSettings())).([]kube.APIResourceInfo) 46 return strings.Join(argo.APIResourcesToStrings(resources, true), ",") 47 }