istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/test/framework/components/environment/kube/fake.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 kube
    16  
    17  import (
    18  	"fmt"
    19  
    20  	"istio.io/istio/pkg/test/framework/components/cluster"
    21  	"istio.io/istio/pkg/test/framework/components/cluster/clusterboot"
    22  	"istio.io/istio/pkg/test/framework/resource"
    23  )
    24  
    25  var _ resource.Environment = FakeEnvironment{}
    26  
    27  // FakeEnvironment for testing.
    28  type FakeEnvironment struct {
    29  	Name        string
    30  	NumClusters int
    31  	IDValue     string
    32  }
    33  
    34  func (f FakeEnvironment) ID() resource.ID {
    35  	return resource.FakeID(f.IDValue)
    36  }
    37  
    38  func (f FakeEnvironment) IsMultiCluster() bool {
    39  	return false
    40  }
    41  
    42  func (f FakeEnvironment) IsMultiNetwork() bool {
    43  	return false
    44  }
    45  
    46  func (f FakeEnvironment) EnvironmentName() string {
    47  	if len(f.Name) == 0 {
    48  		return "fake"
    49  	}
    50  	return f.Name
    51  }
    52  
    53  func (f FakeEnvironment) AllClusters() cluster.Clusters {
    54  	factory := clusterboot.NewFactory()
    55  	for i := 0; i < f.NumClusters; i++ {
    56  		factory = factory.With(cluster.Config{Kind: cluster.Fake, Name: fmt.Sprintf("cluster-%d", i)})
    57  	}
    58  	out, err := factory.Build()
    59  	if err != nil {
    60  		panic(err)
    61  	}
    62  	return out
    63  }
    64  
    65  func (f FakeEnvironment) Clusters() cluster.Clusters {
    66  	return f.AllClusters().MeshClusters()
    67  }