vitess.io/vitess@v0.16.2/go/vt/vtadmin/cluster/internal/caches/schemacache/cache_test.go (about) 1 /* 2 Copyright 2022 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package schemacache 18 19 import ( 20 "testing" 21 22 "github.com/stretchr/testify/assert" 23 24 vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata" 25 ) 26 27 func TestLoadOptions(t *testing.T) { 28 t.Parallel() 29 30 t.Run("isFullPayload", func(t *testing.T) { 31 t.Parallel() 32 33 tests := []struct { 34 name string 35 opts LoadOptions 36 isFullPayload bool 37 }{ 38 { 39 name: "full payload", 40 opts: LoadOptions{ 41 BaseRequest: &vtctldatapb.GetSchemaRequest{ 42 IncludeViews: true, 43 }, 44 AggregateSizes: true, 45 }, 46 isFullPayload: true, 47 }, 48 { 49 name: "tables", 50 opts: LoadOptions{ 51 BaseRequest: &vtctldatapb.GetSchemaRequest{ 52 Tables: []string{"t1"}, 53 IncludeViews: true, 54 }, 55 AggregateSizes: true, 56 }, 57 isFullPayload: false, 58 }, 59 { 60 name: "exclude tables", 61 opts: LoadOptions{ 62 BaseRequest: &vtctldatapb.GetSchemaRequest{ 63 ExcludeTables: []string{"t1"}, 64 IncludeViews: true, 65 }, 66 AggregateSizes: true, 67 }, 68 isFullPayload: false, 69 }, 70 { 71 name: "no views", 72 opts: LoadOptions{ 73 BaseRequest: &vtctldatapb.GetSchemaRequest{ 74 IncludeViews: false, 75 }, 76 AggregateSizes: true, 77 }, 78 isFullPayload: false, 79 }, 80 { 81 name: "names only", 82 opts: LoadOptions{ 83 BaseRequest: &vtctldatapb.GetSchemaRequest{ 84 IncludeViews: true, 85 TableNamesOnly: true, 86 }, 87 AggregateSizes: true, 88 }, 89 isFullPayload: false, 90 }, 91 { 92 name: "sizes only", 93 opts: LoadOptions{ 94 BaseRequest: &vtctldatapb.GetSchemaRequest{ 95 IncludeViews: true, 96 TableSizesOnly: true, 97 }, 98 AggregateSizes: true, 99 }, 100 isFullPayload: false, 101 }, 102 { 103 name: "schema only", 104 opts: LoadOptions{ 105 BaseRequest: &vtctldatapb.GetSchemaRequest{ 106 IncludeViews: true, 107 TableSchemaOnly: true, 108 }, 109 AggregateSizes: true, 110 }, 111 isFullPayload: false, 112 }, 113 { 114 name: "no size aggregation", 115 opts: LoadOptions{ 116 BaseRequest: &vtctldatapb.GetSchemaRequest{ 117 IncludeViews: true, 118 }, 119 AggregateSizes: false, 120 }, 121 isFullPayload: false, 122 }, 123 { 124 name: "missing request", 125 opts: LoadOptions{ 126 BaseRequest: nil, 127 AggregateSizes: true, 128 }, 129 isFullPayload: false, 130 }, 131 } 132 133 for _, tt := range tests { 134 tt := tt 135 t.Run(tt.name, func(t *testing.T) { 136 t.Parallel() 137 138 assert.Equal(t, tt.isFullPayload, tt.opts.isFullPayload(), "%+v", tt.opts) 139 }) 140 } 141 }) 142 }