Add noop implementation of each source type

pull/5028/head
Michael Desa 2017-10-31 18:07:42 -04:00
parent d7b981987c
commit e111038816
7 changed files with 204 additions and 6 deletions

33
noop/dashboards.go Normal file
View File

@ -0,0 +1,33 @@
package noop
import (
"context"
"fmt"
"github.com/influxdata/chronograf"
)
// ensure DashboardsStore implements chronograf.DashboardsStore
var _ chronograf.DashboardsStore = &DashboardsStore{}
type DashboardsStore struct{}
func (s *DashboardsStore) All(context.Context) ([]chronograf.Dashboard, error) {
return nil, fmt.Errorf("no dashboards found")
}
func (s *DashboardsStore) Add(context.Context, chronograf.Dashboard) (chronograf.Dashboard, error) {
return chronograf.Dashboard{}, fmt.Errorf("failed to add dashboard")
}
func (s *DashboardsStore) Delete(context.Context, chronograf.Dashboard) error {
return fmt.Errorf("failed to delete dashboard")
}
func (s *DashboardsStore) Get(ctx context.Context, ID chronograf.DashboardID) (chronograf.Dashboard, error) {
return chronograf.Dashboard{}, chronograf.ErrDashboardNotFound
}
func (s *DashboardsStore) Update(context.Context, chronograf.Dashboard) error {
return fmt.Errorf("failed to update dashboard")
}

33
noop/layouts.go Normal file
View File

@ -0,0 +1,33 @@
package noop
import (
"context"
"fmt"
"github.com/influxdata/chronograf"
)
// ensure LayoutsStore implements chronograf.LayoutsStore
var _ chronograf.LayoutsStore = &LayoutsStore{}
type LayoutsStore struct{}
func (s *LayoutsStore) All(context.Context) ([]chronograf.Layout, error) {
return nil, fmt.Errorf("no layouts found")
}
func (s *LayoutsStore) Add(context.Context, chronograf.Layout) (chronograf.Layout, error) {
return chronograf.Layout{}, fmt.Errorf("failed to add layout")
}
func (s *LayoutsStore) Delete(context.Context, chronograf.Layout) error {
return fmt.Errorf("failed to delete layout")
}
func (s *LayoutsStore) Get(ctx context.Context, ID string) (chronograf.Layout, error) {
return chronograf.Layout{}, chronograf.ErrLayoutNotFound
}
func (s *LayoutsStore) Update(context.Context, chronograf.Layout) error {
return fmt.Errorf("failed to update layout")
}

33
noop/organizations.go Normal file
View File

@ -0,0 +1,33 @@
package noop
import (
"context"
"fmt"
"github.com/influxdata/chronograf"
)
// ensure OrganizationsStore implements chronograf.OrganizationsStore
var _ chronograf.OrganizationsStore = &OrganizationsStore{}
type OrganizationsStore struct{}
func (s *OrganizationsStore) All(context.Context) ([]chronograf.Organization, error) {
return nil, fmt.Errorf("no organizations found")
}
func (s *OrganizationsStore) Add(context.Context, *chronograf.Organization) (*chronograf.Organization, error) {
return nil, fmt.Errorf("failed to add organization")
}
func (s *OrganizationsStore) Delete(context.Context, *chronograf.Organization) error {
return fmt.Errorf("failed to delete organization")
}
func (s *OrganizationsStore) Get(ctx context.Context, q chronograf.OrganizationQuery) (*chronograf.Organization, error) {
return nil, chronograf.ErrOrganizationNotFound
}
func (s *OrganizationsStore) Update(context.Context, *chronograf.Organization) error {
return fmt.Errorf("failed to update organization")
}

33
noop/servers.go Normal file
View File

@ -0,0 +1,33 @@
package noop
import (
"context"
"fmt"
"github.com/influxdata/chronograf"
)
// ensure ServersStore implements chronograf.ServersStore
var _ chronograf.ServersStore = &ServersStore{}
type ServersStore struct{}
func (s *ServersStore) All(context.Context) ([]chronograf.Server, error) {
return nil, fmt.Errorf("no servers found")
}
func (s *ServersStore) Add(context.Context, chronograf.Server) (chronograf.Server, error) {
return chronograf.Server{}, fmt.Errorf("failed to add server")
}
func (s *ServersStore) Delete(context.Context, chronograf.Server) error {
return fmt.Errorf("failed to delete server")
}
func (s *ServersStore) Get(ctx context.Context, ID int) (chronograf.Server, error) {
return chronograf.Server{}, chronograf.ErrServerNotFound
}
func (s *ServersStore) Update(context.Context, chronograf.Server) error {
return fmt.Errorf("failed to update server")
}

33
noop/sources.go Normal file
View File

@ -0,0 +1,33 @@
package noop
import (
"context"
"fmt"
"github.com/influxdata/chronograf"
)
// ensure SourcesStore implements chronograf.SourcesStore
var _ chronograf.SourcesStore = &SourcesStore{}
type SourcesStore struct{}
func (s *SourcesStore) All(context.Context) ([]chronograf.Source, error) {
return nil, fmt.Errorf("no sources found")
}
func (s *SourcesStore) Add(context.Context, chronograf.Source) (chronograf.Source, error) {
return chronograf.Source{}, fmt.Errorf("failed to add source")
}
func (s *SourcesStore) Delete(context.Context, chronograf.Source) error {
return fmt.Errorf("failed to delete source")
}
func (s *SourcesStore) Get(ctx context.Context, ID int) (chronograf.Source, error) {
return chronograf.Source{}, chronograf.ErrSourceNotFound
}
func (s *SourcesStore) Update(context.Context, chronograf.Source) error {
return fmt.Errorf("failed to update source")
}

33
noop/users.go Normal file
View File

@ -0,0 +1,33 @@
package noop
import (
"context"
"fmt"
"github.com/influxdata/chronograf"
)
// ensure UsersStore implements chronograf.UsersStore
var _ chronograf.UsersStore = &UsersStore{}
type UsersStore struct{}
func (s *UsersStore) All(context.Context) ([]chronograf.User, error) {
return nil, fmt.Errorf("no users found")
}
func (s *UsersStore) Add(context.Context, *chronograf.User) (*chronograf.User, error) {
return nil, fmt.Errorf("failed to add user")
}
func (s *UsersStore) Delete(context.Context, *chronograf.User) error {
return fmt.Errorf("failed to delete user")
}
func (s *UsersStore) Get(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
return nil, chronograf.ErrUserNotFound
}
func (s *UsersStore) Update(context.Context, *chronograf.User) error {
return fmt.Errorf("failed to update user")
}

View File

@ -4,6 +4,7 @@ import (
"context"
"github.com/influxdata/chronograf"
"github.com/influxdata/chronograf/noop"
"github.com/influxdata/chronograf/organizations"
)
@ -70,7 +71,7 @@ func (s *Store) Sources(ctx context.Context) chronograf.SourcesStore {
return organizations.NewSourcesStore(s.SourcesStore, org)
}
return s.SourcesStore
return &noop.SourcesStore{}
}
func (s *Store) Servers(ctx context.Context) chronograf.ServersStore {
@ -78,7 +79,7 @@ func (s *Store) Servers(ctx context.Context) chronograf.ServersStore {
return organizations.NewServersStore(s.ServersStore, org)
}
return s.ServersStore
return &noop.ServersStore{}
}
func (s *Store) Layouts(ctx context.Context) chronograf.LayoutsStore {
@ -86,7 +87,7 @@ func (s *Store) Layouts(ctx context.Context) chronograf.LayoutsStore {
return organizations.NewLayoutsStore(s.LayoutsStore, org)
}
return s.LayoutsStore
return &noop.LayoutsStore{}
}
func (s *Store) Users(ctx context.Context) chronograf.UsersStore {
@ -97,8 +98,7 @@ func (s *Store) Users(ctx context.Context) chronograf.UsersStore {
return organizations.NewUsersStore(s.UsersStore, org)
}
// TODO: eventually have NoOpUserstore
return organizations.NewUsersStore(s.UsersStore, "")
return &noop.UsersStore{}
}
func (s *Store) Dashboards(ctx context.Context) chronograf.DashboardsStore {
@ -106,7 +106,7 @@ func (s *Store) Dashboards(ctx context.Context) chronograf.DashboardsStore {
return organizations.NewDashboardsStore(s.DashboardsStore, org)
}
return s.DashboardsStore
return &noop.DashboardsStore{}
}
func (s *Store) Organizations(ctx context.Context) chronograf.OrganizationsStore {