chore: rename notification banners to announcement banners (#13419)

This commit is contained in:
Kayla Washburn-Love
2024-05-31 10:59:28 -06:00
committed by GitHub
parent de8149fbfd
commit b248f125e1
42 changed files with 355 additions and 349 deletions
@@ -11,12 +11,12 @@ import (
"github.com/coder/coder/v2/codersdk/agentsdk"
)
type NotificationBannerAPI struct {
type AnnouncementBannerAPI struct {
appearanceFetcher *atomic.Pointer[appearance.Fetcher]
}
// Deprecated: GetServiceBanner has been deprecated in favor of GetNotificationBanners.
func (a *NotificationBannerAPI) GetServiceBanner(ctx context.Context, _ *proto.GetServiceBannerRequest) (*proto.ServiceBanner, error) {
// Deprecated: GetServiceBanner has been deprecated in favor of GetAnnouncementBanners.
func (a *AnnouncementBannerAPI) GetServiceBanner(ctx context.Context, _ *proto.GetServiceBannerRequest) (*proto.ServiceBanner, error) {
cfg, err := (*a.appearanceFetcher.Load()).Fetch(ctx)
if err != nil {
return nil, xerrors.Errorf("fetch appearance: %w", err)
@@ -24,16 +24,16 @@ func (a *NotificationBannerAPI) GetServiceBanner(ctx context.Context, _ *proto.G
return agentsdk.ProtoFromServiceBanner(cfg.ServiceBanner), nil
}
func (a *NotificationBannerAPI) GetNotificationBanners(ctx context.Context, _ *proto.GetNotificationBannersRequest) (*proto.GetNotificationBannersResponse, error) {
func (a *AnnouncementBannerAPI) GetAnnouncementBanners(ctx context.Context, _ *proto.GetAnnouncementBannersRequest) (*proto.GetAnnouncementBannersResponse, error) {
cfg, err := (*a.appearanceFetcher.Load()).Fetch(ctx)
if err != nil {
return nil, xerrors.Errorf("fetch appearance: %w", err)
}
banners := make([]*proto.BannerConfig, 0, len(cfg.NotificationBanners))
for _, banner := range cfg.NotificationBanners {
banners := make([]*proto.BannerConfig, 0, len(cfg.AnnouncementBanners))
for _, banner := range cfg.AnnouncementBanners {
banners = append(banners, agentsdk.ProtoFromBannerConfig(banner))
}
return &proto.GetNotificationBannersResponse{
NotificationBanners: banners,
return &proto.GetAnnouncementBannersResponse{
AnnouncementBanners: banners,
}, nil
}
@@ -14,7 +14,7 @@ import (
"github.com/coder/coder/v2/codersdk/agentsdk"
)
func TestGetNotificationBanners(t *testing.T) {
func TestGetAnnouncementBanners(t *testing.T) {
t.Parallel()
t.Run("OK", func(t *testing.T) {
@@ -26,15 +26,15 @@ func TestGetNotificationBanners(t *testing.T) {
BackgroundColor: "#00FF00",
}}
var ff appearance.Fetcher = fakeFetcher{cfg: codersdk.AppearanceConfig{NotificationBanners: cfg}}
var ff appearance.Fetcher = fakeFetcher{cfg: codersdk.AppearanceConfig{AnnouncementBanners: cfg}}
ptr := atomic.Pointer[appearance.Fetcher]{}
ptr.Store(&ff)
api := &NotificationBannerAPI{appearanceFetcher: &ptr}
resp, err := api.GetNotificationBanners(context.Background(), &agentproto.GetNotificationBannersRequest{})
api := &AnnouncementBannerAPI{appearanceFetcher: &ptr}
resp, err := api.GetAnnouncementBanners(context.Background(), &agentproto.GetAnnouncementBannersRequest{})
require.NoError(t, err)
require.Len(t, resp.NotificationBanners, 1)
require.Equal(t, cfg[0], agentsdk.BannerConfigFromProto(resp.NotificationBanners[0]))
require.Len(t, resp.AnnouncementBanners, 1)
require.Equal(t, cfg[0], agentsdk.BannerConfigFromProto(resp.AnnouncementBanners[0]))
})
t.Run("FetchError", func(t *testing.T) {
@@ -45,8 +45,8 @@ func TestGetNotificationBanners(t *testing.T) {
ptr := atomic.Pointer[appearance.Fetcher]{}
ptr.Store(&ff)
api := &NotificationBannerAPI{appearanceFetcher: &ptr}
resp, err := api.GetNotificationBanners(context.Background(), &agentproto.GetNotificationBannersRequest{})
api := &AnnouncementBannerAPI{appearanceFetcher: &ptr}
resp, err := api.GetAnnouncementBanners(context.Background(), &agentproto.GetAnnouncementBannersRequest{})
require.Error(t, err)
require.ErrorIs(t, err, expectedErr)
require.Nil(t, resp)
+2 -2
View File
@@ -36,7 +36,7 @@ import (
type API struct {
opts Options
*ManifestAPI
*NotificationBannerAPI
*AnnouncementBannerAPI
*StatsAPI
*LifecycleAPI
*AppsAPI
@@ -108,7 +108,7 @@ func New(opts Options) *API {
},
}
api.NotificationBannerAPI = &NotificationBannerAPI{
api.AnnouncementBannerAPI = &AnnouncementBannerAPI{
appearanceFetcher: opts.AppearanceFetcher,
}