56 lines
1.0 KiB
Go
56 lines
1.0 KiB
Go
package domain
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestWorkloadValidate(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
w Workload
|
|
want error
|
|
}{
|
|
{
|
|
name: "valid workload",
|
|
w: Workload{
|
|
ID: "workload-1",
|
|
EnvironmentID: "env-1",
|
|
Name: "api",
|
|
Image: "example/api:v1",
|
|
Status: WorkloadStatusPending,
|
|
},
|
|
},
|
|
{
|
|
name: "missing image",
|
|
w: Workload{
|
|
ID: "workload-1",
|
|
EnvironmentID: "env-1",
|
|
Name: "api",
|
|
Status: WorkloadStatusPending,
|
|
},
|
|
want: ErrInvalidArgument,
|
|
},
|
|
{
|
|
name: "invalid status",
|
|
w: Workload{
|
|
ID: "workload-1",
|
|
EnvironmentID: "env-1",
|
|
Name: "api",
|
|
Image: "example/api:v1",
|
|
Status: WorkloadStatus("UNKNOWN"),
|
|
},
|
|
want: ErrInvalidStatus,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
err := tt.w.Validate()
|
|
if !errors.Is(err, tt.want) {
|
|
t.Fatalf("Validate() error = %v, want %v", err, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|