app/product: block products to be initialized with the feature flag (#21875)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
33b59e0e96
Коммит
e58b6ffa3e
@@ -17,6 +17,9 @@ func (s *Server) initializeProducts(
|
||||
// create a product map to consume
|
||||
pmap := make(map[string]struct{})
|
||||
for name := range productMap {
|
||||
if !s.shouldStart(name) {
|
||||
continue
|
||||
}
|
||||
pmap[name] = struct{}{}
|
||||
}
|
||||
|
||||
@@ -64,3 +67,11 @@ func (s *Server) initializeProducts(
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) shouldStart(product string) bool {
|
||||
if !s.Config().FeatureFlags.BoardsProduct && product == "boards" {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ package app
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app/platform"
|
||||
"github.com/mattermost/mattermost-server/v6/config"
|
||||
"github.com/mattermost/mattermost-server/v6/product"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -36,6 +38,9 @@ func (p *productB) Start() error { return nil }
|
||||
func (p *productB) Stop() error { return nil }
|
||||
|
||||
func TestInitializeProducts(t *testing.T) {
|
||||
ps, err := platform.New(platform.ServiceConfig{ConfigStore: config.NewTestMemoryStore()})
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("2 products and no circular dependency", func(t *testing.T) {
|
||||
serviceMap := map[product.ServiceKey]any{
|
||||
product.ConfigKey: nil,
|
||||
@@ -64,11 +69,13 @@ func TestInitializeProducts(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
server := &Server{
|
||||
products: make(map[string]product.Product),
|
||||
platform: ps,
|
||||
}
|
||||
|
||||
err := server.initializeProducts(products, serviceMap)
|
||||
err = server.initializeProducts(products, serviceMap)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, server.products, 2)
|
||||
})
|
||||
@@ -104,6 +111,7 @@ func TestInitializeProducts(t *testing.T) {
|
||||
}
|
||||
server := &Server{
|
||||
products: make(map[string]product.Product),
|
||||
platform: ps,
|
||||
}
|
||||
|
||||
err := server.initializeProducts(products, serviceMap)
|
||||
@@ -132,10 +140,31 @@ func TestInitializeProducts(t *testing.T) {
|
||||
}
|
||||
server := &Server{
|
||||
products: make(map[string]product.Product),
|
||||
platform: ps,
|
||||
}
|
||||
|
||||
err := server.initializeProducts(products, serviceMap)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, server.products, 2)
|
||||
})
|
||||
|
||||
t.Run("boards product to be blocked", func(t *testing.T) {
|
||||
products := map[string]product.Manifest{
|
||||
"productA": {
|
||||
Initializer: newProductA,
|
||||
},
|
||||
"boards": {
|
||||
Initializer: newProductB,
|
||||
},
|
||||
}
|
||||
|
||||
server := &Server{
|
||||
products: make(map[string]product.Product),
|
||||
platform: ps,
|
||||
}
|
||||
|
||||
err := server.initializeProducts(products, map[product.ServiceKey]any{})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, server.products, 1)
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user