Gitea to Forgejo host migration — update Go module path and all import references. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
144 lines
3.4 KiB
Go
144 lines
3.4 KiB
Go
package cli
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"code.t-juice.club/torjus/homelab-deploy/internal/messages"
|
|
)
|
|
|
|
func TestDeployResult_AllSucceeded(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
responses []*messages.DeployResponse
|
|
errors []error
|
|
want bool
|
|
}{
|
|
{
|
|
name: "all completed",
|
|
responses: []*messages.DeployResponse{
|
|
{Hostname: "host1", Status: messages.StatusCompleted},
|
|
{Hostname: "host2", Status: messages.StatusCompleted},
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "one failed",
|
|
responses: []*messages.DeployResponse{
|
|
{Hostname: "host1", Status: messages.StatusCompleted},
|
|
{Hostname: "host2", Status: messages.StatusFailed},
|
|
},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "one rejected",
|
|
responses: []*messages.DeployResponse{
|
|
{Hostname: "host1", Status: messages.StatusRejected},
|
|
},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "no responses",
|
|
responses: []*messages.DeployResponse{},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "has errors",
|
|
responses: []*messages.DeployResponse{
|
|
{Hostname: "host1", Status: messages.StatusCompleted},
|
|
},
|
|
errors: []error{nil}, // placeholder error
|
|
want: false,
|
|
},
|
|
{
|
|
name: "with intermediate responses - success",
|
|
responses: []*messages.DeployResponse{
|
|
{Hostname: "host1", Status: messages.StatusStarted},
|
|
{Hostname: "host1", Status: messages.StatusCompleted},
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "with intermediate responses - failure",
|
|
responses: []*messages.DeployResponse{
|
|
{Hostname: "host1", Status: messages.StatusStarted},
|
|
{Hostname: "host1", Status: messages.StatusFailed},
|
|
},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "multiple hosts with intermediate responses",
|
|
responses: []*messages.DeployResponse{
|
|
{Hostname: "host1", Status: messages.StatusStarted},
|
|
{Hostname: "host2", Status: messages.StatusStarted},
|
|
{Hostname: "host1", Status: messages.StatusCompleted},
|
|
{Hostname: "host2", Status: messages.StatusCompleted},
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "only intermediate responses - no final",
|
|
responses: []*messages.DeployResponse{
|
|
{Hostname: "host1", Status: messages.StatusStarted},
|
|
{Hostname: "host1", Status: messages.StatusAccepted},
|
|
},
|
|
want: false,
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
r := &DeployResult{
|
|
Responses: tc.responses,
|
|
Errors: tc.errors,
|
|
}
|
|
got := r.AllSucceeded()
|
|
if got != tc.want {
|
|
t.Errorf("AllSucceeded() = %v, want %v", got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestDeployResult_HostCount(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
responses []*messages.DeployResponse
|
|
want int
|
|
}{
|
|
{
|
|
name: "no responses",
|
|
responses: []*messages.DeployResponse{},
|
|
want: 0,
|
|
},
|
|
{
|
|
name: "unique hosts",
|
|
responses: []*messages.DeployResponse{
|
|
{Hostname: "host1"},
|
|
{Hostname: "host2"},
|
|
{Hostname: "host3"},
|
|
},
|
|
want: 3,
|
|
},
|
|
{
|
|
name: "duplicate hosts",
|
|
responses: []*messages.DeployResponse{
|
|
{Hostname: "host1", Status: messages.StatusStarted},
|
|
{Hostname: "host1", Status: messages.StatusCompleted},
|
|
{Hostname: "host2", Status: messages.StatusStarted},
|
|
{Hostname: "host2", Status: messages.StatusCompleted},
|
|
},
|
|
want: 2,
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
r := &DeployResult{Responses: tc.responses}
|
|
got := r.HostCount()
|
|
if got != tc.want {
|
|
t.Errorf("HostCount() = %d, want %d", got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|