istio.io/istio@v0.0.0-20240520182934-d79c90f27776/tests/util/sanitycheck/sanity_check.go (about)

     1  // Copyright Istio Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package sanitycheck
    16  
    17  import (
    18  	"istio.io/istio/pkg/config/protocol"
    19  	"istio.io/istio/pkg/test/framework"
    20  	"istio.io/istio/pkg/test/framework/components/echo"
    21  	"istio.io/istio/pkg/test/framework/components/echo/check"
    22  	"istio.io/istio/pkg/test/framework/components/echo/deployment"
    23  	"istio.io/istio/pkg/test/framework/components/namespace"
    24  	"istio.io/istio/pkg/test/framework/resource"
    25  	"istio.io/istio/pkg/test/scopes"
    26  )
    27  
    28  // RunTrafficTest deploys echo server/client and runs an Istio traffic test
    29  func RunTrafficTest(t framework.TestContext, ctx resource.Context) {
    30  	scopes.Framework.Infof("running sanity test")
    31  	_, client, server := SetupTrafficTest(t, ctx, "")
    32  	RunTrafficTestClientServer(t, client, server)
    33  }
    34  
    35  func SetupTrafficTest(t framework.TestContext, ctx resource.Context, revision string) (namespace.Instance, echo.Instance, echo.Instance) {
    36  	var client, server echo.Instance
    37  	testNs := namespace.NewOrFail(t, ctx, namespace.Config{
    38  		Prefix:   "default",
    39  		Revision: revision,
    40  		Inject:   true,
    41  	})
    42  	deployment.New(ctx).
    43  		With(&client, echo.Config{
    44  			Service:   "client",
    45  			Namespace: testNs,
    46  			Ports:     []echo.Port{},
    47  		}).
    48  		With(&server, echo.Config{
    49  			Service:   "server",
    50  			Namespace: testNs,
    51  			Ports: []echo.Port{
    52  				{
    53  					Name:         "http",
    54  					Protocol:     protocol.HTTP,
    55  					WorkloadPort: 8090,
    56  				},
    57  			},
    58  		}).
    59  		BuildOrFail(t)
    60  
    61  	return testNs, client, server
    62  }
    63  
    64  func RunTrafficTestClientServer(t framework.TestContext, client, server echo.Instance) {
    65  	_ = client.CallOrFail(t, echo.CallOptions{
    66  		To:    server,
    67  		Count: 1,
    68  		Port: echo.Port{
    69  			Name: "http",
    70  		},
    71  		Check: check.OK(),
    72  	})
    73  }