mattermost-community-enterp.../public/model/shared_channel_test.go
Claude ec1f89217a Merge: Complete Mattermost Server with Community Enterprise
Full Mattermost server source with integrated Community Enterprise features.
Includes vendor directory for offline/air-gapped builds.

Structure:
- enterprise-impl/: Enterprise feature implementations
- enterprise-community/: Init files that register implementations
- enterprise/: Bridge imports (community_imports.go)
- vendor/: All dependencies for offline builds

Build (online):
  go build ./cmd/mattermost

Build (offline/air-gapped):
  go build -mod=vendor ./cmd/mattermost

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-17 23:59:07 +09:00

67 lines
2.2 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package model
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSharedChannelIsValid(t *testing.T) {
id := NewId()
now := GetMillis()
data := []struct {
name string
sc *SharedChannel
valid bool
}{
{name: "Zero value", sc: &SharedChannel{}, valid: false},
{name: "Missing team_id", sc: &SharedChannel{ChannelId: id}, valid: false},
{name: "Missing create_at", sc: &SharedChannel{ChannelId: id, TeamId: id}, valid: false},
{name: "Missing update_at", sc: &SharedChannel{ChannelId: id, TeamId: id, CreateAt: now}, valid: false},
{name: "Missing share_name", sc: &SharedChannel{ChannelId: id, TeamId: id, CreateAt: now, UpdateAt: now}, valid: false},
{name: "Invalid share_name", sc: &SharedChannel{ChannelId: id, TeamId: id, CreateAt: now, UpdateAt: now,
ShareName: "@test@"}, valid: false},
{name: "Too long share_name", sc: &SharedChannel{ChannelId: id, TeamId: id, CreateAt: now, UpdateAt: now,
ShareName: strings.Repeat("01234567890", 100)}, valid: false},
{name: "Missing creator_id", sc: &SharedChannel{ChannelId: id, TeamId: id, CreateAt: now, UpdateAt: now,
ShareName: "test"}, valid: false},
{name: "Missing remote_id", sc: &SharedChannel{ChannelId: id, TeamId: id, CreateAt: now, UpdateAt: now,
ShareName: "test", CreatorId: id}, valid: false},
{name: "Valid shared channel", sc: &SharedChannel{ChannelId: id, TeamId: id, CreateAt: now, UpdateAt: now,
ShareName: "test", CreatorId: id, RemoteId: id}, valid: true},
}
for _, item := range data {
appErr := item.sc.IsValid()
if item.valid {
assert.Nil(t, appErr, item.name)
} else {
assert.NotNil(t, appErr, item.name)
}
}
}
func TestSharedChannelPreSave(t *testing.T) {
now := GetMillis()
o := SharedChannel{ChannelId: NewId(), ShareName: "test"}
o.PreSave()
require.GreaterOrEqual(t, o.CreateAt, now)
require.GreaterOrEqual(t, o.UpdateAt, now)
}
func TestSharedChannelPreUpdate(t *testing.T) {
now := GetMillis()
o := SharedChannel{ChannelId: NewId(), ShareName: "test"}
o.PreUpdate()
require.GreaterOrEqual(t, o.UpdateAt, now)
}