102 lines
2.2 KiB
Go
102 lines
2.2 KiB
Go
package ports
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"galaxy/gamemaster/internal/domain/engineversion"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// fixedNow returns a stable wall-clock used by the input-validation
|
|
// fixtures. Adapters use the value verbatim to refresh the `updated_at`
|
|
// column.
|
|
func fixedNow() time.Time {
|
|
return time.Date(2026, time.April, 27, 12, 0, 0, 0, time.UTC)
|
|
}
|
|
|
|
func TestUpdateEngineVersionInputValidateHappy(t *testing.T) {
|
|
imageRef := "ghcr.io/galaxy/game:v1.2.4"
|
|
input := UpdateEngineVersionInput{
|
|
Version: "v1.2.3",
|
|
ImageRef: &imageRef,
|
|
Now: fixedNow(),
|
|
}
|
|
require.NoError(t, input.Validate())
|
|
}
|
|
|
|
func TestUpdateEngineVersionInputValidateAcceptsStatusOnly(t *testing.T) {
|
|
status := engineversion.StatusDeprecated
|
|
input := UpdateEngineVersionInput{
|
|
Version: "v1.2.3",
|
|
Status: &status,
|
|
Now: fixedNow(),
|
|
}
|
|
assert.NoError(t, input.Validate())
|
|
}
|
|
|
|
func TestUpdateEngineVersionInputValidateAcceptsOptionsOnly(t *testing.T) {
|
|
options := []byte(`{"max_planets":120}`)
|
|
input := UpdateEngineVersionInput{
|
|
Version: "v1.2.3",
|
|
Options: &options,
|
|
Now: fixedNow(),
|
|
}
|
|
assert.NoError(t, input.Validate())
|
|
}
|
|
|
|
func TestUpdateEngineVersionInputValidateRejects(t *testing.T) {
|
|
emptyImage := ""
|
|
imageRef := "ghcr.io/galaxy/game:v1.2.4"
|
|
unknownStatus := engineversion.Status("exotic")
|
|
|
|
tests := []struct {
|
|
name string
|
|
input UpdateEngineVersionInput
|
|
}{
|
|
{
|
|
name: "empty version",
|
|
input: UpdateEngineVersionInput{
|
|
Version: "",
|
|
ImageRef: &imageRef,
|
|
Now: fixedNow(),
|
|
},
|
|
},
|
|
{
|
|
name: "no fields set",
|
|
input: UpdateEngineVersionInput{Version: "v1.2.3", Now: fixedNow()},
|
|
},
|
|
{
|
|
name: "empty image ref pointer",
|
|
input: UpdateEngineVersionInput{
|
|
Version: "v1.2.3",
|
|
ImageRef: &emptyImage,
|
|
Now: fixedNow(),
|
|
},
|
|
},
|
|
{
|
|
name: "unknown status pointer",
|
|
input: UpdateEngineVersionInput{
|
|
Version: "v1.2.3",
|
|
Status: &unknownStatus,
|
|
Now: fixedNow(),
|
|
},
|
|
},
|
|
{
|
|
name: "zero now",
|
|
input: UpdateEngineVersionInput{
|
|
Version: "v1.2.3",
|
|
ImageRef: &imageRef,
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert.Error(t, tt.input.Validate())
|
|
})
|
|
}
|
|
}
|