Skip to content

Commit

Permalink
Improve testing, remove GetPods test for now
Browse files Browse the repository at this point in the history
Signed-off-by: Krithik Vaidya <[email protected]>
  • Loading branch information
krithikvaidya committed Sep 10, 2021
1 parent dddbc03 commit 7f0acc1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 60 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
**errorutil_errors_export.json
2 changes: 1 addition & 1 deletion mesheryctl/internal/cli/root/system/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 21 additions & 0 deletions mesheryctl/pkg/utils/TestConfig.yaml
Original file line number Diff line number Diff line change
@@ -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
58 changes: 6 additions & 52 deletions mesheryctl/pkg/utils/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions mesheryctl/pkg/utils/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7f0acc1

Please sign in to comment.