diff --git a/app/safe/internal/backoff/retry_test.go b/app/safe/internal/backoff/retry_test.go index 0a124163..d2907d81 100644 --- a/app/safe/internal/backoff/retry_test.go +++ b/app/safe/internal/backoff/retry_test.go @@ -59,6 +59,12 @@ func TestRetry(t *testing.T) { strategy: Strategy{}, expectError: false, }, + { + name: "TestSetMaxDurationIfExponentialEnabledAndMaxDurationZero", + failuresBeforeSuccess: 3, + strategy: Strategy{Exponential: true, MaxDuration: 0}, + expectError: false, + }, } for _, tt := range tests { diff --git a/core/entity/data/v1/v1_test.go b/core/entity/data/v1/v1_test.go index 1443df77..905a422a 100644 --- a/core/entity/data/v1/v1_test.go +++ b/core/entity/data/v1/v1_test.go @@ -44,6 +44,46 @@ func TestJsonTime_MarshalJSON(t *testing.T) { } } +func TestJsonTimeUnmarshalJSON(t *testing.T) { + testCases := []struct { + name string + jsonData []byte + wantErr bool + }{ + { + name: "invalid_json_data", + jsonData: []byte(`"invalid_date"`), + wantErr: true, + }, + { + name: "valid_json_data", + jsonData: []byte(`"2024-03-01T12:00:00Z"`), + wantErr: false, + }, + } + for _, tt := range testCases { + t.Run(tt.name, func(t *testing.T) { + var jsonTime JsonTime + err := jsonTime.UnmarshalJSON(tt.jsonData) + if (err != nil) != tt.wantErr { + t.Errorf("UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestJsonTimeString(t *testing.T) { + jsonTime := JsonTime(time.Now()) + + expectedTimeStr := time.Now().Format(time.RFC3339) + + result := jsonTime.String() + + if result != expectedTimeStr { + t.Errorf("Expected: %s, Got: %s", expectedTimeStr, result) + } +} + func Test_parseForK8sSecret(t *testing.T) { type args struct { secret SecretStored diff --git a/core/env/safe_test.go b/core/env/safe_test.go index cc9de6e0..f743fd68 100644 --- a/core/env/safe_test.go +++ b/core/env/safe_test.go @@ -676,6 +676,59 @@ func TestSafeRootKeyPath(t *testing.T) { } } +func TestSourceAcquisitionTimeout(t *testing.T) { + tests := []struct { + name string + setup func() error + cleanup func() error + want time.Duration + }{ + { + name: "default_safe_source_acquisition_timeout", + want: 10000 * time.Millisecond, + }, + { + name: "safe_source_acquisition_timeout_from_env", + setup: func() error { + return os.Setenv("VSECM_SAFE_SOURCE_ACQUISITION_TIMEOUT", "500") + }, + cleanup: func() error { + return os.Unsetenv("VSECM_SAFE_SOURCE_ACQUISITION_TIMEOUT") + }, + want: 500 * time.Millisecond, + }, + { + name: "invalid_safe_source_acquisition_timeout_from_env", + setup: func() error { + return os.Setenv("VSECM_SAFE_SOURCE_ACQUISITION_TIMEOUT", "test") + }, + cleanup: func() error { + return os.Unsetenv("VSECM_SAFE_SOURCE_ACQUISITION_TIMEOUT") + }, + want: 10000 * time.Millisecond, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if tt.setup != nil { + if err := tt.setup(); err != nil { + t.Errorf("SourceAcquisitionTimeoutForSafe() = failed to setup, with error: %+v", err) + } + } + defer func() { + if tt.cleanup != nil { + if err := tt.cleanup(); err != nil { + t.Errorf("SourceAcquisitionTimeoutForSafe() = failed to cleanup, with error: %+v", err) + } + } + }() + if got := SourceAcquisitionTimeoutForSafe(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("SourceAcquisitionTimeoutForSafe() = %v, want %v", got, tt.want) + } + }) + } +} + func TestSafeBootstrapTimeout(t *testing.T) { tests := []struct { name string diff --git a/core/template/template_test.go b/core/template/template_test.go index 3c84a0d3..3323bcd0 100644 --- a/core/template/template_test.go +++ b/core/template/template_test.go @@ -124,6 +124,14 @@ func TestTryParse(t *testing.T) { }, want: "{username}", }, + { + name: "invalid_template_valid_json", + args: args{ + tmpStr: "{\"USER\":\"{{}}\", \"PASS\":\"{{.password}}\"}", + jason: "{\"username\":\"admin\",\"password\":\"VSecMRocks\"}", + }, + want: "{\"username\":\"admin\",\"password\":\"VSecMRocks\"}", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {