Extract publication recovery observation
This commit is contained in:
59
internal/publish/reconcile_test.go
Normal file
59
internal/publish/reconcile_test.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package publish
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"go.maximumdirect.net/releasekit/internal/git"
|
||||
)
|
||||
|
||||
func TestClassifyPublicationObservation(t *testing.T) {
|
||||
tagObject, commit := strings.Repeat("a", 40), strings.Repeat("b", 40)
|
||||
base := Evidence{Endpoint: "file:///remote.git", Tag: "v1.2.3", TagObject: tagObject, CandidateCommit: commit}
|
||||
tests := []struct {
|
||||
name string
|
||||
evidence Evidence
|
||||
ref git.RemoteRef
|
||||
want State
|
||||
wantKind string
|
||||
}{
|
||||
{"absent with partial identity", Evidence{Endpoint: base.Endpoint, Tag: base.Tag}, git.RemoteRef{State: git.RefAbsent}, NotPublished, ""},
|
||||
{"matching tag without peel", base, git.RemoteRef{State: git.RefPresent, Object: tagObject}, Published, ""},
|
||||
{"matching tag and commit", base, git.RemoteRef{State: git.RefPresent, Object: strings.ToUpper(tagObject), Peeled: strings.ToUpper(commit)}, Published, ""},
|
||||
{"tag conflict", base, git.RemoteRef{State: git.RefPresent, Object: strings.Repeat("c", 40), Peeled: commit}, Conflict, ""},
|
||||
{"commit conflict", base, git.RemoteRef{State: git.RefPresent, Object: tagObject, Peeled: strings.Repeat("c", 40)}, Conflict, ""},
|
||||
{"missing tag object", Evidence{Endpoint: base.Endpoint, Tag: base.Tag}, git.RemoteRef{State: git.RefPresent, Object: tagObject}, Unknown, "missing_evidence"},
|
||||
{"missing commit with peel", Evidence{Endpoint: base.Endpoint, Tag: base.Tag, TagObject: tagObject}, git.RemoteRef{State: git.RefPresent, Object: tagObject, Peeled: commit}, Unknown, "missing_evidence"},
|
||||
{"unreadable", base, git.RemoteRef{State: git.RefUnreadable}, Unknown, "inconsistent_observation"},
|
||||
{"inconsistent", base, git.RemoteRef{State: git.RefConflict}, Unknown, "inconsistent_observation"},
|
||||
{"missing endpoint", Evidence{Tag: base.Tag}, git.RemoteRef{State: git.RefAbsent}, Unknown, "missing_evidence"},
|
||||
{"missing tag", Evidence{Endpoint: base.Endpoint}, git.RemoteRef{State: git.RefAbsent}, Unknown, "missing_evidence"},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got, err := classify(test.evidence, test.ref)
|
||||
if got.State != test.want {
|
||||
t.Fatalf("state=%q want %q", got.State, test.want)
|
||||
}
|
||||
var recovery *RecoveryError
|
||||
if test.wantKind == "" {
|
||||
if err != nil {
|
||||
t.Fatalf("error=%v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if !errors.As(err, &recovery) || recovery.Kind != test.wantKind {
|
||||
t.Fatalf("error=%v want kind %q", err, test.wantKind)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestClassifyReportsAllMissingIdentityFields(t *testing.T) {
|
||||
_, err := classify(Evidence{}, git.RemoteRef{State: git.RefPresent})
|
||||
var recovery *RecoveryError
|
||||
if !errors.As(err, &recovery) || strings.Join(recovery.MissingFields, ",") != "endpoint,tag" {
|
||||
t.Fatalf("classification error = %#v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user