github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/pkg/ruler/rulestore/config_test.go (about)

     1  package rulestore
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/grafana/dskit/flagext"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestIsDefaults(t *testing.T) {
    11  	tests := map[string]struct {
    12  		setup    func(cfg *Config)
    13  		expected bool
    14  	}{
    15  		"should return true if the config only contains default values": {
    16  			setup: func(cfg *Config) {
    17  				flagext.DefaultValues(cfg)
    18  			},
    19  			expected: true,
    20  		},
    21  		"should return false if the config contains zero values": {
    22  			setup:    func(cfg *Config) {},
    23  			expected: false,
    24  		},
    25  		"should return false if the config contains default values and some overrides": {
    26  			setup: func(cfg *Config) {
    27  				flagext.DefaultValues(cfg)
    28  				cfg.Backend = "local"
    29  			},
    30  			expected: false,
    31  		},
    32  	}
    33  
    34  	for testName, testData := range tests {
    35  		t.Run(testName, func(t *testing.T) {
    36  			cfg := Config{}
    37  			testData.setup(&cfg)
    38  
    39  			assert.Equal(t, testData.expected, cfg.IsDefaults())
    40  		})
    41  	}
    42  }