forked from mtusi2026/mtusi2026lab6
feat: add bounded observability and verified SLO incident alerts
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package memory
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab6/internal/config"
|
||||
"gitea.privcloud.tech/vlad_marlo/mtusi2026lab6/internal/model/dto"
|
||||
)
|
||||
|
||||
// TestStore_New rejects missing capacity settings.
|
||||
func TestStore_New(t *testing.T) {
|
||||
// Arrange.
|
||||
var cfg *config.Memory
|
||||
|
||||
// Act.
|
||||
repo, err := New(cfg)
|
||||
|
||||
// Assert.
|
||||
if err == nil || repo != nil {
|
||||
t.Fatalf("missing configuration accepted: %v, %v", repo, err)
|
||||
}
|
||||
}
|
||||
|
||||
// newTestStore creates independent storage for one scenario.
|
||||
func newTestStore(t *testing.T, cfg *config.Memory) *Store {
|
||||
t.Helper()
|
||||
repo, err := New(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return repo
|
||||
}
|
||||
|
||||
// seedUser creates a fixture user and checks preparation errors.
|
||||
func seedUser(t *testing.T, repo *Store, username string) dto.UserDTO {
|
||||
t.Helper()
|
||||
user, err := repo.CreateUser(t.Context(), dto.UserDTO{ID: uuid.New(), Username: username})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return user
|
||||
}
|
||||
|
||||
// seedChat creates a fixture chat for an existing member.
|
||||
func seedChat(t *testing.T, repo *Store, member uuid.UUID) dto.ChatDTO {
|
||||
t.Helper()
|
||||
chat, err := repo.CreateChat(t.Context(), dto.ChatDTO{ID: uuid.New(), Title: "Fixture", MemberIDs: []uuid.UUID{member}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return chat
|
||||
}
|
||||
|
||||
// seedMessage creates an acknowledged fixture message.
|
||||
func seedMessage(t *testing.T, repo *Store, chat dto.ChatDTO, text string) dto.MessageDTO {
|
||||
t.Helper()
|
||||
message, err := repo.CreateMessage(t.Context(), dto.MessageDTO{ID: uuid.New(), ChatID: chat.ID, SenderID: chat.MemberIDs[0], Text: text})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return message
|
||||
}
|
||||
Reference in New Issue
Block a user