diff --git a/.gitignore b/.gitignore index 2e42bcd17bc..e2f78cb8f2c 100644 --- a/.gitignore +++ b/.gitignore @@ -59,7 +59,4 @@ yarn.lock default.profraw **errorutil_analyze_errors.json **errorutil_analyze_summary.json -**errorutil_errors_export.json - -# Temporary test files -/mesheryctl/pkg/utils/fixtures/.meshery/ \ No newline at end of file +**errorutil_errors_export.json \ No newline at end of file diff --git a/mesheryctl/internal/cli/root/system/channel_test.go b/mesheryctl/internal/cli/root/system/channel_test.go index 7aa848b1698..4d6df35e171 100644 --- a/mesheryctl/internal/cli/root/system/channel_test.go +++ b/mesheryctl/internal/cli/root/system/channel_test.go @@ -21,7 +21,7 @@ func SetupContextEnv(t *testing.T) { t.Error("unable to locate meshery directory") } viper.Reset() - viper.SetConfigFile(path + "/../../../../pkg/utils/fixtures/TestConfig.yaml") + viper.SetConfigFile(path + "/../../../../pkg/utils/TestConfig.yaml") //fmt.Println(viper.ConfigFileUsed()) err = viper.ReadInConfig() if err != nil { diff --git a/mesheryctl/pkg/utils/TestConfig.yaml b/mesheryctl/pkg/utils/TestConfig.yaml new file mode 100644 index 00000000000..cfb8f8858a4 --- /dev/null +++ b/mesheryctl/pkg/utils/TestConfig.yaml @@ -0,0 +1,21 @@ +contexts: + gke: + adapters: + - meshery-istio + channel: stable + endpoint: http://localhost:9081 + platform: gke + token: Default + version: v0.4.2 + local: + endpoint: http://localhost:9081 + token: Default + platform: docker + adapters: + - meshery-istio + channel: stable + version: v0.5.10 +current-context: local +tokens: +- location: auth.json + name: Default diff --git a/mesheryctl/pkg/utils/platform_test.go b/mesheryctl/pkg/utils/platform_test.go index 0ab3c99b32b..d88cb44de4c 100644 --- a/mesheryctl/pkg/utils/platform_test.go +++ b/mesheryctl/pkg/utils/platform_test.go @@ -2,35 +2,31 @@ package utils import ( "encoding/json" - "fmt" "io/ioutil" "os" "path/filepath" - "runtime" "testing" "github.com/jarcoal/httpmock" "github.com/layer5io/meshery/mesheryctl/internal/cli/root/config" "github.com/layer5io/meshery/mesheryctl/pkg/constants" - meshkitkube "github.com/layer5io/meshkit/utils/kubernetes" log "github.com/sirupsen/logrus" "github.com/spf13/viper" ) func init() { - // Get current directory - _, filename, _, ok := runtime.Caller(0) - if !ok { - log.Fatal("Not able to get current working directory") + + home, err := os.UserHomeDir() + if err != nil { + log.Fatal("Failed to get users home directory") } - basePath := filepath.Dir(filename) - SetFileLocationTesting(basePath) + SetFileLocationTesting(home) // Create required directories for testing, if not already existing manifestsFolder := filepath.Join(MesheryFolder, "manifests") - err := os.MkdirAll(manifestsFolder, os.ModePerm) + err = os.MkdirAll(manifestsFolder, os.ModePerm) if err != nil { log.Fatal("Failed to create test directory") } @@ -260,48 +256,6 @@ func TestGetManifestURL(t *testing.T) { } } -func TestGetPods(t *testing.T) { - tests := []struct { - name string - namespace string - wantErr bool - }{ - { - name: "GetPods() with MesheryNamespace", - namespace: MesheryNamespace, - wantErr: false, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - // create an kubernetes client - client, err := meshkitkube.New([]byte("")) - - if err != nil { - t.Fatalf("Error in creating kubernetes client in GetPods() test") - } - - // List the pods in the MesheryNamespace - got, err := GetPods(client, tt.namespace) - - if (err != nil) != tt.wantErr { - t.Fatalf("GetPods() error = %v, wantErr %v", err, tt.wantErr) - } - - // check return type - if fmt.Sprintf("%T", got) != "*v1.PodList" { - t.Errorf("GetPods() error: want type = *v1.PodList, got type %T", got) - } - - // check non nil - if got == nil { - t.Fatalf("GetPods() error: got nil PodList") - } - }) - } -} - func TestIsPodRequired(t *testing.T) { type args struct { requiredPods []string diff --git a/mesheryctl/pkg/utils/testing.go b/mesheryctl/pkg/utils/testing.go index a847f99bfa4..cb4e4b702a7 100644 --- a/mesheryctl/pkg/utils/testing.go +++ b/mesheryctl/pkg/utils/testing.go @@ -135,15 +135,15 @@ func (tf *GoldenFile) WriteInByte(content []byte) { } } -// use default context /pkg/utils/fixtures/TestConfig.yaml +// use default context /pkg/utils/TestConfig.yaml func SetupContextEnv(t *testing.T) { path, err := os.Getwd() if err != nil { t.Error("unable to locate meshery directory") } viper.Reset() - viper.SetConfigFile(path + "/../../../../pkg/utils/fixtures/TestConfig.yaml") - DefaultConfigPath = path + "/../../../../pkg/utils/fixtures/TestConfig.yaml" + viper.SetConfigFile(path + "/../../../../pkg/utils/TestConfig.yaml") + DefaultConfigPath = path + "/../../../../pkg/utils/TestConfig.yaml" //fmt.Println(viper.ConfigFileUsed()) err = viper.ReadInConfig() if err != nil {