...

Source file src/github.com/cybertec-postgresql/pgwatch/v3/internal/metrics/cmdopts_test.go

Documentation: github.com/cybertec-postgresql/pgwatch/v3/internal/metrics

     1  package metrics
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestCacheAge(t *testing.T) {
    11  	tests := []struct {
    12  		name     string
    13  		opts     CmdOpts
    14  		expected time.Duration
    15  	}{
    16  		{
    17  			name:     "Cache enabled with positive value",
    18  			opts:     CmdOpts{InstanceLevelCacheMaxSeconds: 30},
    19  			expected: 30 * time.Second,
    20  		},
    21  		{
    22  			name:     "Cache disabled with zero value",
    23  			opts:     CmdOpts{InstanceLevelCacheMaxSeconds: 0},
    24  			expected: 0,
    25  		},
    26  		{
    27  			name:     "Cache disable with incorrect value",
    28  			opts:     CmdOpts{InstanceLevelCacheMaxSeconds: -30},
    29  			expected: 0,
    30  		},
    31  	}
    32  
    33  	for _, tt := range tests {
    34  		t.Run(tt.name, func(t *testing.T) {
    35  			assert.Equal(t, tt.expected, tt.opts.CacheAge())
    36  		})
    37  	}
    38  }
    39