github.com/oam-dev/kubevela@v1.9.11/pkg/resourcekeeper/options_test.go (about)

     1  /*
     2  Copyright 2021 The KubeVela 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 resourcekeeper
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/stretchr/testify/require"
    23  )
    24  
    25  func TestDispatchOptions(t *testing.T) {
    26  	testCases := map[string]struct {
    27  		option DispatchOption
    28  		cfg    dispatchConfig
    29  	}{
    30  		"meta-only": {
    31  			option: MetaOnlyOption{},
    32  			cfg:    dispatchConfig{metaOnly: true},
    33  		},
    34  		"skip-gc": {
    35  			option: SkipGCOption{},
    36  			cfg:    dispatchConfig{rtConfig: rtConfig{skipGC: true}},
    37  		},
    38  		"use-root": {
    39  			option: UseRootOption{},
    40  			cfg:    dispatchConfig{rtConfig: rtConfig{useRoot: true}},
    41  		},
    42  	}
    43  	for name, tc := range testCases {
    44  		t.Run(name, func(t *testing.T) {
    45  			require.New(t).Equal(tc.cfg, *newDispatchConfig(tc.option))
    46  		})
    47  	}
    48  }
    49  
    50  func TestDeleteOptions(t *testing.T) {
    51  	testCases := map[string]struct {
    52  		option DeleteOption
    53  		cfg    deleteConfig
    54  	}{
    55  		"skip-gc": {
    56  			option: SkipGCOption{},
    57  			cfg:    deleteConfig{rtConfig: rtConfig{skipGC: true}},
    58  		},
    59  		"use-root": {
    60  			option: UseRootOption{},
    61  			cfg:    deleteConfig{rtConfig: rtConfig{useRoot: true}},
    62  		},
    63  	}
    64  	for name, tc := range testCases {
    65  		t.Run(name, func(t *testing.T) {
    66  			require.New(t).Equal(tc.cfg, *newDeleteConfig(tc.option))
    67  		})
    68  	}
    69  }
    70  
    71  func TestGCOptions(t *testing.T) {
    72  	testCases := map[string]struct {
    73  		option GCOption
    74  		cfg    gcConfig
    75  	}{
    76  		"passive": {
    77  			option: PassiveGCOption{},
    78  			cfg:    gcConfig{passive: true},
    79  		},
    80  		"disable-mark-stage": {
    81  			option: DisableMarkStageGCOption{},
    82  			cfg:    gcConfig{disableMark: true},
    83  		},
    84  		"disable-gc-comp-rev": {
    85  			option: DisableGCComponentRevisionOption{},
    86  			cfg:    gcConfig{disableComponentRevisionGC: true},
    87  		},
    88  	}
    89  	for name, tc := range testCases {
    90  		t.Run(name, func(t *testing.T) {
    91  			require.New(t).Equal(tc.cfg, *newGCConfig(tc.option))
    92  		})
    93  	}
    94  }