Self-hosted email delivery platform that enables applications to send emails via HTTP APIs while handling SMTP delivery, templates, storage, security, and analytics. Fully self-hostable alternative to services like SendGrid or Mailgun.
Go email-relayemail-routinghttp-to-smtpmail-deliverymailchimp-alternativemailgun-alternativemailsendermailservermailtemplatemailtestpostmark-alternativesend-emailsendgrid-alternativesendmailtransactional-emailtransactional-outbox
// Copyright (c) 2026 Jonas Kaninda.
//
// This file is part of Posta.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: AGPL-3.0-or-later
package upgrade
import "testing"
func TestRegistryIDsAreUniqueAndOrdered(t *testing.T) {
steps := Registry()
seen := make(map[string]bool, len(steps))
prev := ""
for i, s := range steps {
if s.ID == "" {
t.Fatalf("step %d has an empty id", i)
}
if s.Apply == nil {
t.Fatalf("step %q has no Apply func", s.ID)
}
if seen[s.ID] {
t.Fatalf("step %q is registered twice; applied steps are keyed by id", s.ID)
}
seen[s.ID] = true
// Only the date prefix must not go backwards. Steps sharing a date run in
// dependency order, which is rarely alphabetical: 2026-08-28-system-workspace
// has to precede the steps that read workspaces.system.
date := s.ID
if len(date) > 10 {
date = date[:10]
}
if prev != "" && date < prev {
t.Fatalf("step %q is dated before %q; the registry is append-only", s.ID, prev)
}
prev = date
}
}
func TestRegistryIsACopy(t *testing.T) {
a := Registry()
if len(a) == 0 {
t.Fatal("registry is empty")
}
a[0].ID = "mutated"
if Registry()[0].ID == "mutated" {
t.Fatal("Registry must hand out a copy; a caller mutated the in-tree registry")
}
}
func TestWorkspaceTypeStepsAreRegistered(t *testing.T) {
want := []string{
"2026-08-28-system-workspace",
"2026-08-28-personal-to-normal",
"2026-08-28-default-workspace",
}
got := make(map[string]bool)
for _, s := range Registry() {
got[s.ID] = true
}
for _, id := range want {
if !got[id] {
t.Fatalf("upgrade step %q is not registered", id)
}
}
}