mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
The server module named github.com/hanzoai/team/server/v8 — a path that resolves to the retired workspace's repository, not this one — while server/public still published github.com/mattermost/mattermost/server/public. Both are github.com/hanzoteam/server/... now, which is where this code actually lives. That second half is what made the binary unbootable. Upstream's public path stayed claimed by upstream, mattermost-plugin-ai imported it, and the build linked public/model twice; public/plugin's gob.Register then ran twice under one name and panicked at init, before main. Reverting the rename traded the brand for a working binary. Rebranding the plugin alongside it needs no such trade: the agents fork is github.com/hanzoteam/agents/v2 against our public module, so no module named mattermost/mattermost is in the graph at all. Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and it is ours.
85 lines
2.6 KiB
Go
85 lines
2.6 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package properties
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hanzoteam/server/server/public/model"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestFieldLimitHook(t *testing.T) {
|
|
th := Setup(t)
|
|
|
|
group, err := th.service.RegisterPropertyGroup(&model.PropertyGroup{Name: "test_field_limit", Version: model.PropertyGroupVersionV2})
|
|
require.NoError(t, err)
|
|
|
|
hook := NewFieldLimitHook(th.service)
|
|
hook.AddGroupLimit(group.ID, &FieldLimitConfig{
|
|
PerObjectType: map[string]int64{
|
|
"user": 3,
|
|
},
|
|
GlobalLimit: 5,
|
|
})
|
|
th.service.AddHook(hook)
|
|
|
|
makeField := func(objectType string) *model.PropertyField {
|
|
return &model.PropertyField{
|
|
GroupID: group.ID,
|
|
Name: "field_" + model.NewId(),
|
|
Type: model.PropertyFieldTypeText,
|
|
TargetType: "system",
|
|
ObjectType: objectType,
|
|
}
|
|
}
|
|
|
|
t.Run("allows fields up to per-object-type limit", func(t *testing.T) {
|
|
for range 3 {
|
|
_, createErr := th.service.CreatePropertyField(th.Context, makeField("user"))
|
|
require.NoError(t, createErr)
|
|
}
|
|
})
|
|
|
|
t.Run("rejects field at per-object-type limit", func(t *testing.T) {
|
|
_, createErr := th.service.CreatePropertyField(th.Context, makeField("user"))
|
|
require.Error(t, createErr)
|
|
assert.Contains(t, createErr.Error(), "limit_reached")
|
|
})
|
|
|
|
t.Run("allows fields for different object type", func(t *testing.T) {
|
|
_, createErr := th.service.CreatePropertyField(th.Context, makeField("post"))
|
|
require.NoError(t, createErr)
|
|
})
|
|
|
|
t.Run("rejects at global limit", func(t *testing.T) {
|
|
// We have 3 user + 1 post = 4 fields. One more should succeed.
|
|
_, createErr := th.service.CreatePropertyField(th.Context, makeField("post"))
|
|
require.NoError(t, createErr)
|
|
|
|
// Now at 5, should hit global limit
|
|
_, createErr = th.service.CreatePropertyField(th.Context, makeField("post"))
|
|
require.Error(t, createErr)
|
|
assert.Contains(t, createErr.Error(), "group_limit_reached")
|
|
})
|
|
|
|
t.Run("skips limit check for unregistered groups", func(t *testing.T) {
|
|
otherGroup, groupErr := th.service.RegisterPropertyGroup(&model.PropertyGroup{Name: "test_no_limits", Version: model.PropertyGroupVersionV2})
|
|
require.NoError(t, groupErr)
|
|
|
|
for range 10 {
|
|
field := &model.PropertyField{
|
|
GroupID: otherGroup.ID,
|
|
Name: "field_" + model.NewId(),
|
|
Type: model.PropertyFieldTypeText,
|
|
TargetType: "system",
|
|
ObjectType: "user",
|
|
}
|
|
_, createErr := th.service.CreatePropertyField(th.Context, field)
|
|
require.NoError(t, createErr)
|
|
}
|
|
})
|
|
}
|