Files
matchbox/api/store_test.go
Dalton Hubble ccd3c7a839 api: Associate machines' attribute labels to specs by group matchers
* Use YAML group config to match machine labels to groups of zero or
more machines sharing a Specification
* Discontinue using machine.json resources representations which are
repetitive, don't support groups, and don't allow label matching
* Previous "default" special case now handled by a Group with an empty
matcher
2016-01-07 23:24:05 -08:00

69 lines
1.6 KiB
Go

package api
import (
"fmt"
ignition "github.com/coreos/ignition/src/config"
)
// fixedStore provides fixed Group, Spec, and config resources for testing
// purposes.
type fixedStore struct {
Groups []Group
Specs map[string]*Spec
CloudConfigs map[string]*CloudConfig
IgnitionConfigs map[string]*ignition.Config
}
func (s *fixedStore) Spec(id string) (*Spec, error) {
if spec, present := s.Specs[id]; present {
return spec, nil
}
return nil, fmt.Errorf("no spec %s", id)
}
func (s *fixedStore) BootstrapGroups(groups []Group) error {
s.Groups = groups
return nil
}
func (s *fixedStore) ListGroups() ([]Group, error) {
return s.Groups, nil
}
func (s *fixedStore) CloudConfig(id string) (*CloudConfig, error) {
if config, present := s.CloudConfigs[id]; present {
return config, nil
}
return nil, fmt.Errorf("no cloud config %s", id)
}
func (s *fixedStore) IgnitionConfig(id string) (*ignition.Config, error) {
if config, present := s.IgnitionConfigs[id]; present {
return config, nil
}
return nil, fmt.Errorf("no ignition config %s", id)
}
type emptyStore struct{}
func (s *emptyStore) Spec(id string) (*Spec, error) {
return nil, fmt.Errorf("no group config %s", id)
}
func (s *emptyStore) BootstrapGroups(groups []Group) error {
return nil
}
func (s *emptyStore) ListGroups() (groups []Group, err error) {
return groups, nil
}
func (s emptyStore) CloudConfig(id string) (*CloudConfig, error) {
return nil, fmt.Errorf("no cloud config %s", id)
}
func (s emptyStore) IgnitionConfig(id string) (*ignition.Config, error) {
return nil, fmt.Errorf("no ignition config %s", id)
}