-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gabriel Saratura
committed
Jan 31, 2025
1 parent
7c0c4db
commit ec72028
Showing
9 changed files
with
253 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package stackgres | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestGetLatestMinorVersion(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
inputVersion string | ||
versionList *PgVersions | ||
expected string | ||
expectedError string | ||
}{ | ||
{ | ||
name: "No version list provided", | ||
inputVersion: "14", | ||
versionList: nil, | ||
expected: "14", | ||
}, | ||
{ | ||
name: "Empty version list", | ||
inputVersion: "14", | ||
versionList: &PgVersions{Postgresql: []string{}}, | ||
expected: "14", | ||
}, | ||
{ | ||
name: "Single matching minor version", | ||
inputVersion: "14", | ||
versionList: &PgVersions{Postgresql: []string{"14.3"}}, | ||
expected: "14.3", | ||
}, | ||
{ | ||
name: "Multiple minor versions, latest chosen", | ||
inputVersion: "14", | ||
versionList: &PgVersions{Postgresql: []string{"14.1", "14.3", "14.4"}}, | ||
expected: "14.4", | ||
}, | ||
{ | ||
name: "No matching major version", | ||
inputVersion: "14", | ||
versionList: &PgVersions{Postgresql: []string{"13.5", "15.1"}}, | ||
expected: "14", | ||
}, | ||
{ | ||
name: "Minor version is 0", | ||
inputVersion: "14", | ||
versionList: &PgVersions{Postgresql: []string{"13.3", "14.0"}}, | ||
expected: "14", | ||
}, | ||
{ | ||
name: "Invalid input version format", | ||
inputVersion: "invalid-version", | ||
versionList: &PgVersions{Postgresql: []string{"14.3", "14.4"}}, | ||
expectedError: "Malformed version: invalid-version", | ||
}, | ||
{ | ||
name: "Invalid version in version list", | ||
inputVersion: "14.2", | ||
versionList: &PgVersions{Postgresql: []string{"14.3", "invalid-version"}}, | ||
expectedError: "Malformed version: invalid-version", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result, err := GetLatestMinorVersion(tt.inputVersion, tt.versionList) | ||
|
||
if tt.expectedError != "" { | ||
assert.EqualError(t, err, tt.expectedError) | ||
} else { | ||
assert.NoError(t, err) | ||
assert.Equal(t, tt.expected, result) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
pkg/comp-functions/functions/vshnpostgres/major_version_upgrade_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package vshnpostgres | ||
|
||
import ( | ||
sgv1 "github.com/vshn/appcat/v4/apis/stackgres/v1" | ||
"k8s.io/utils/ptr" | ||
"testing" | ||
) | ||
|
||
func Test_IsSuccessful(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
conditions *[]sgv1.SGDbOpsStatusConditionsItem | ||
expected bool | ||
}{ | ||
{ | ||
name: "Nil conditions", | ||
conditions: nil, | ||
expected: false, | ||
}, | ||
{ | ||
name: "Empty conditions", | ||
conditions: &[]sgv1.SGDbOpsStatusConditionsItem{}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "OperationCompleted is True, no OperationFailed", | ||
conditions: &[]sgv1.SGDbOpsStatusConditionsItem{ | ||
{Reason: ptr.To("OperationCompleted"), Status: ptr.To("True")}, | ||
}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "OperationFailed is True", | ||
conditions: &[]sgv1.SGDbOpsStatusConditionsItem{ | ||
{Reason: ptr.To("OperationFailed"), Status: ptr.To("True")}, | ||
}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "Both OperationCompleted and OperationFailed are True", | ||
conditions: &[]sgv1.SGDbOpsStatusConditionsItem{ | ||
{Reason: ptr.To("OperationCompleted"), Status: ptr.To("True")}, | ||
{Reason: ptr.To("OperationFailed"), Status: ptr.To("True")}, | ||
}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "OperationRunning is True", | ||
conditions: &[]sgv1.SGDbOpsStatusConditionsItem{ | ||
{Reason: ptr.To("OperationRunning"), Status: ptr.To("True")}, | ||
}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "OperationCompleted is True, other conditions exist", | ||
conditions: &[]sgv1.SGDbOpsStatusConditionsItem{ | ||
{Reason: ptr.To("OperationCompleted"), Status: ptr.To("True")}, | ||
{Reason: ptr.To("OperationNotRunning"), Status: ptr.To("True")}, | ||
}, | ||
expected: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := isSuccessful(tt.conditions) | ||
if result != tt.expected { | ||
t.Errorf("isSuccessful() = %v, want %v", result, tt.expected) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.