...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/pkg/util/valutil/valutil_test.go

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/pkg/util/valutil

     1  // Copyright 2022 Google LLC
     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 valutil_test
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/util/valutil"
    21  )
    22  
    23  func TestIsDefaultValue(t *testing.T) {
    24  	testCases := []struct {
    25  		Name           string
    26  		Value          interface{}
    27  		ExpectedResult bool
    28  	}{
    29  		{
    30  			Name:           "Default string",
    31  			Value:          "",
    32  			ExpectedResult: true,
    33  		},
    34  		{
    35  			Name:           "String value",
    36  			Value:          "a",
    37  			ExpectedResult: false,
    38  		},
    39  		{
    40  			Name:           "Default bool",
    41  			Value:          false,
    42  			ExpectedResult: true,
    43  		},
    44  		{
    45  			Name:           "Bool value",
    46  			Value:          true,
    47  			ExpectedResult: false,
    48  		},
    49  		{
    50  			Name:           "Pointer to string",
    51  			Value:          new(string),
    52  			ExpectedResult: true,
    53  		},
    54  		{
    55  			Name:           "Pointer to bool",
    56  			Value:          new(bool),
    57  			ExpectedResult: true,
    58  		},
    59  	}
    60  	for _, tc := range testCases {
    61  		t.Run(tc.Name, func(t *testing.T) {
    62  			result := valutil.IsDefaultValue(tc.Value)
    63  			if result != tc.ExpectedResult {
    64  				t.Fatalf("unexpected result: got '%v', want '%v'", result, tc.ExpectedResult)
    65  			}
    66  		})
    67  	}
    68  }
    69  

View as plain text