github.com/solo-io/service-mesh-hub@v0.9.2/test/e2e/istio/istio_e2e_suite_test.go (about)

     1  package istio_test
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"os"
     7  	"path/filepath"
     8  	"testing"
     9  	"time"
    10  
    11  	. "github.com/onsi/ginkgo"
    12  	. "github.com/onsi/gomega"
    13  	"github.com/solo-io/go-utils/testutils"
    14  	networkingv1alpha2 "github.com/solo-io/service-mesh-hub/pkg/api/networking.smh.solo.io/v1alpha2"
    15  	"github.com/solo-io/service-mesh-hub/test/data"
    16  	. "github.com/solo-io/service-mesh-hub/test/e2e"
    17  	"github.com/solo-io/service-mesh-hub/test/utils"
    18  	v1 "github.com/solo-io/skv2/pkg/api/core.skv2.solo.io/v1"
    19  	"sigs.k8s.io/controller-runtime/pkg/client"
    20  )
    21  
    22  var (
    23  	err                 error
    24  	VirtualMesh         *networkingv1alpha2.VirtualMesh
    25  	VirtualMeshManifest utils.Manifest
    26  )
    27  
    28  // to skip testing this package, run `make run-tests SKIP_PACKAGES=test/e2e/istio
    29  // to test only this package, run `make run-tests TEST_PKG=test/e2e/istio
    30  func TestIstio(t *testing.T) {
    31  	if os.Getenv("RUN_E2E") == "" {
    32  		fmt.Println("skipping E2E tests")
    33  		return
    34  	}
    35  	RegisterFailHandler(func(message string, callerSkip ...int) {
    36  		utils.RunShell("./ci/print-kind-info.sh")
    37  		Fail(message, callerSkip...)
    38  	})
    39  	RunSpecs(t, "E2e Suite")
    40  }
    41  
    42  // Before running tests, federate the two clusters by creating a VirtualMesh with mTLS enabled.
    43  var _ = BeforeSuite(func() {
    44  	VirtualMeshManifest, err = utils.NewManifest("virtualmesh.yaml")
    45  	Expect(err).NotTo(HaveOccurred())
    46  
    47  	ctx, cancel := context.WithTimeout(context.Background(), 20*time.Minute)
    48  	defer cancel()
    49  
    50  	ensureWorkingDirectory()
    51  	/* env := */ StartEnvOnce(ctx)
    52  
    53  	var err error
    54  	dynamicClient, err = client.New(GetEnv().Management.Config, client.Options{})
    55  	Expect(err).NotTo(HaveOccurred())
    56  
    57  	federateClusters(dynamicClient)
    58  })
    59  
    60  func federateClusters(dynamicClient client.Client) {
    61  	VirtualMesh = data.SelfSignedVirtualMesh(
    62  		"bookinfo-federation",
    63  		BookinfoNamespace,
    64  		[]*v1.ObjectRef{
    65  			masterMesh,
    66  			remoteMesh,
    67  		})
    68  
    69  	err = VirtualMeshManifest.AppendResources(VirtualMesh)
    70  	Expect(err).NotTo(HaveOccurred())
    71  	err = VirtualMeshManifest.KubeApply(BookinfoNamespace)
    72  	Expect(err).NotTo(HaveOccurred())
    73  
    74  	// ensure status is updated
    75  	utils.AssertVirtualMeshStatuses(dynamicClient, BookinfoNamespace)
    76  
    77  	// check we can hit the remote service
    78  	// give 5 minutes because the workflow depends on restarting pods
    79  	// which can take several minutes
    80  	Eventually(curlRemoteReviews, "5m", "2s").Should(ContainSubstring("200 OK"))
    81  }
    82  
    83  func ensureWorkingDirectory() {
    84  	// ensure we are in proper directory
    85  	currentFile, err := testutils.GetCurrentFile()
    86  	Expect(err).NotTo(HaveOccurred())
    87  	projectRoot := filepath.Join(filepath.Dir(currentFile), "..", "..", "..")
    88  	err = os.Chdir(projectRoot)
    89  	Expect(err).NotTo(HaveOccurred())
    90  }
    91  
    92  var _ = AfterSuite(func() {
    93  	err = VirtualMeshManifest.KubeDelete(BookinfoNamespace)
    94  	Expect(err).NotTo(HaveOccurred())
    95  
    96  	ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
    97  	defer cancel()
    98  	if os.Getenv("NO_CLEANUP") != "" {
    99  		return
   100  	}
   101  	_ = ClearEnv(ctx)
   102  })