Phase Validation: pkg/phase change to add Phase validation sub command
Related To #330 Change-Id: I649f0ed487d3469e5a51dac0a9fd234f686c4373
This commit is contained in:
parent
90c0116b7f
commit
e41a63ac8d
@ -274,3 +274,35 @@ func (c *ClusterListCommand) RunE() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateFlags options for phase validate command
|
||||
type ValidateFlags struct {
|
||||
PhaseID ifc.ID
|
||||
}
|
||||
|
||||
// ValidateCommand phase validate command
|
||||
type ValidateCommand struct {
|
||||
Options ValidateFlags
|
||||
Factory config.Factory
|
||||
}
|
||||
|
||||
// RunE runs the phase validate command
|
||||
func (c *ValidateCommand) RunE() error {
|
||||
cfg, err := c.Factory()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
helper, err := NewHelper(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client := NewClient(helper)
|
||||
|
||||
phase, err := client.PhaseByID(c.Options.PhaseID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return phase.Validate()
|
||||
}
|
||||
|
@ -437,3 +437,99 @@ func TestClusterListCommand_RunE(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateCommand(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
errContains string
|
||||
flags phase.ValidateFlags
|
||||
factory config.Factory
|
||||
}{
|
||||
{
|
||||
name: "Error config factory",
|
||||
factory: func() (*config.Config, error) {
|
||||
return nil, fmt.Errorf(testFactoryErr)
|
||||
},
|
||||
errContains: testFactoryErr,
|
||||
},
|
||||
{
|
||||
name: "Error new helper",
|
||||
factory: func() (*config.Config, error) {
|
||||
return &config.Config{
|
||||
CurrentContext: "does not exist",
|
||||
Contexts: make(map[string]*config.Context),
|
||||
}, nil
|
||||
},
|
||||
errContains: testNewHelperErr,
|
||||
},
|
||||
{
|
||||
name: "Error phase by id",
|
||||
factory: func() (*config.Config, error) {
|
||||
conf := config.NewConfig()
|
||||
conf.Manifests = map[string]*config.Manifest{
|
||||
"manifest": {
|
||||
MetadataPath: "broken_metadata.yaml",
|
||||
TargetPath: "testdata",
|
||||
PhaseRepositoryName: config.DefaultTestPhaseRepo,
|
||||
Repositories: map[string]*config.Repository{
|
||||
config.DefaultTestPhaseRepo: {
|
||||
URLString: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
conf.CurrentContext = defaultCurrentContext
|
||||
conf.Contexts = map[string]*config.Context{
|
||||
"context": {
|
||||
Manifest: "manifest",
|
||||
},
|
||||
}
|
||||
return conf, nil
|
||||
},
|
||||
errContains: testNoBundlePath,
|
||||
},
|
||||
{
|
||||
name: "success",
|
||||
// flags: phase.ValidateFlags{PhaseID: }
|
||||
factory: func() (*config.Config, error) {
|
||||
conf := config.NewConfig()
|
||||
conf.Manifests = map[string]*config.Manifest{
|
||||
"manifest": {
|
||||
MetadataPath: "metadata.yaml",
|
||||
TargetPath: "testdata",
|
||||
PhaseRepositoryName: config.DefaultTestPhaseRepo,
|
||||
Repositories: map[string]*config.Repository{
|
||||
config.DefaultTestPhaseRepo: {
|
||||
URLString: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
conf.CurrentContext = defaultCurrentContext
|
||||
conf.Contexts = map[string]*config.Context{
|
||||
"context": {
|
||||
Manifest: "manifest",
|
||||
},
|
||||
}
|
||||
return conf, nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
command := phase.ValidateCommand{
|
||||
Options: tt.flags,
|
||||
Factory: tt.factory,
|
||||
}
|
||||
err := command.RunE()
|
||||
if tt.errContains != "" {
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), tt.errContains)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user