...

Source file src/github.com/go-openapi/validate/schema_option_test.go

Documentation: github.com/go-openapi/validate

     1  // Copyright 2015 go-swagger maintainers
     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 validate
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/require"
    21  )
    22  
    23  func TestSchemaOptions(t *testing.T) {
    24  	t.Run("EnableObjectArrayTypeCheck", func(t *testing.T) {
    25  		opts := &SchemaValidatorOptions{}
    26  		setter := EnableObjectArrayTypeCheck(true)
    27  		setter(opts)
    28  		require.True(t, opts.EnableObjectArrayTypeCheck)
    29  	})
    30  
    31  	t.Run("skipSchemataResult", func(t *testing.T) {
    32  		opts := &SchemaValidatorOptions{}
    33  		setter := WithSkipSchemataResult(true)
    34  		setter(opts)
    35  		require.True(t, opts.skipSchemataResult)
    36  	})
    37  
    38  	t.Run("default Options()", func(t *testing.T) {
    39  		opts := &SchemaValidatorOptions{}
    40  		setters := opts.Options()
    41  
    42  		target := &SchemaValidatorOptions{}
    43  		for _, apply := range setters {
    44  			apply(target)
    45  		}
    46  		require.Equal(t, opts, target)
    47  	})
    48  
    49  	t.Run("all set Options()", func(t *testing.T) {
    50  		opts := &SchemaValidatorOptions{
    51  			EnableObjectArrayTypeCheck:    true,
    52  			EnableArrayMustHaveItemsCheck: true,
    53  			recycleValidators:             true,
    54  			recycleResult:                 true,
    55  			skipSchemataResult:            true,
    56  		}
    57  		setters := opts.Options()
    58  
    59  		target := &SchemaValidatorOptions{}
    60  		for _, apply := range setters {
    61  			apply(target)
    62  		}
    63  		require.Equal(t, opts, target)
    64  	})
    65  }
    66  

View as plain text