istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/config/schema/collections/mock.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 collections
    16  
    17  import (
    18  	"errors"
    19  
    20  	"istio.io/istio/pkg/config"
    21  	"istio.io/istio/pkg/config/schema/collection"
    22  	"istio.io/istio/pkg/config/schema/resource"
    23  	"istio.io/istio/pkg/config/validation"
    24  	testconfig "istio.io/istio/pkg/test/config"
    25  )
    26  
    27  var (
    28  	// Mock is used purely for testing
    29  	Mock = resource.Builder{
    30  		ClusterScoped: false,
    31  		Kind:          "MockConfig",
    32  		Plural:        "mockconfigs",
    33  		Group:         "test.istio.io",
    34  		Version:       "v1",
    35  		Proto:         "config.MockConfig",
    36  		ProtoPackage:  "istio.io/istio/pkg/test/config",
    37  		ValidateProto: func(cfg config.Config) (validation.Warning, error) {
    38  			if cfg.Spec.(*testconfig.MockConfig).Key == "" {
    39  				return nil, errors.New("empty key")
    40  			}
    41  			return nil, nil
    42  		},
    43  	}.MustBuild()
    44  
    45  	// Mocks is a Schemas containing the Mock Schema.
    46  	Mocks = collection.NewSchemasBuilder().MustAdd(Mock).Build()
    47  )