-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pivoted to a registry based framework
- Loading branch information
1 parent
619f14d
commit 779963a
Showing
4 changed files
with
124 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package scenarios | ||
|
||
import "fmt" | ||
|
||
type scenarioName string | ||
|
||
type registry struct { | ||
scenarios map[scenarioName]ScenarioRegistration | ||
} | ||
|
||
func NewScenarioRegistry() ScenarioRegistry { | ||
return ®istry{ | ||
scenarios: make(map[scenarioName]ScenarioRegistration), | ||
} | ||
} | ||
|
||
func (s *registry) Register(reg ScenarioRegistration) error { | ||
if _, ok := s.scenarios[scenarioName(reg.Name)]; ok { | ||
return fmt.Errorf("scenario %s already registered", reg.Name) | ||
} | ||
|
||
s.scenarios[scenarioName(reg.Name)] = reg | ||
return nil | ||
} | ||
|
||
func (s *registry) Retrieve(name string) (ScenarioRegistration, error) { | ||
scenario, ok := s.scenarios[scenarioName(name)] | ||
if !ok { | ||
return ScenarioRegistration{}, fmt.Errorf("scenario %s is not registered", name) | ||
} | ||
|
||
return scenario, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters