distro: the distro constructors cannot fail
Simplify the code by dropping the potential error return. The constructor simply instantiates some maps, this cannot fail. Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
1345ca77fd
commit
08ff8ab81b
11 changed files with 24 additions and 73 deletions
|
|
@ -78,29 +78,9 @@ func NewRegistry(distros ...Distro) (*Registry, error) {
|
|||
return reg, nil
|
||||
}
|
||||
|
||||
// Create a new Registry containing all known distros.
|
||||
// NewDefaultRegistry creates a new Registry containing all known distros.
|
||||
func NewDefaultRegistry() (*Registry, error) {
|
||||
f30, err := fedora30.New()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error loading fedora30: %v", err)
|
||||
}
|
||||
f31, err := fedora31.New()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error loading fedora31: %v", err)
|
||||
}
|
||||
f32, err := fedora32.New()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error loading fedora32: %v", err)
|
||||
}
|
||||
el81, err := rhel81.New()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error loading rhel81: %v", err)
|
||||
}
|
||||
el82, err := rhel82.New()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error loading rhel82: %v", err)
|
||||
}
|
||||
return NewRegistry(f30, f31, f32, el81, el82)
|
||||
return NewRegistry(fedora30.New(), fedora31.New(), fedora32.New(), rhel81.New(), rhel82.New())
|
||||
}
|
||||
|
||||
func (r *Registry) GetDistro(name string) Distro {
|
||||
|
|
@ -116,7 +96,7 @@ func (r *Registry) GetDistro(name string) Distro {
|
|||
return distro
|
||||
}
|
||||
|
||||
// Returns the names of all distros in a Registry, sorted alphabetically.
|
||||
// List returns the names of all distros in a Registry, sorted alphabetically.
|
||||
func (r *Registry) List() []string {
|
||||
list := []string{}
|
||||
for _, distro := range r.distros {
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ type output struct {
|
|||
const Distro = common.Fedora30
|
||||
const ModulePlatformID = "platform:f30"
|
||||
|
||||
func New() (*Fedora30, error) {
|
||||
func New() *Fedora30 {
|
||||
const GigaByte = 1024 * 1024 * 1024
|
||||
|
||||
r := Fedora30{
|
||||
|
|
@ -286,7 +286,7 @@ func New() (*Fedora30, error) {
|
|||
},
|
||||
}
|
||||
|
||||
return &r, nil
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r *Fedora30) Name() string {
|
||||
|
|
|
|||
|
|
@ -19,10 +19,7 @@ func TestListOutputFormats(t *testing.T) {
|
|||
"vmdk",
|
||||
}
|
||||
|
||||
f30, err := fedora30.New()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f30 := fedora30.New()
|
||||
|
||||
if got := f30.ListOutputFormats(); !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("ListOutputFormats() = %v, want %v", got, want)
|
||||
|
|
@ -96,10 +93,7 @@ func TestFilenameFromType(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
f30, err := fedora30.New()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f30 := fedora30.New()
|
||||
got, got1, err := f30.FilenameFromType(tt.args.outputFormat)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("FilenameFromType() error = %v, wantErr %v", err, tt.wantErr)
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ type output struct {
|
|||
const Distro = common.Fedora31
|
||||
const ModulePlatformID = "platform:f31"
|
||||
|
||||
func New() (*Fedora31, error) {
|
||||
func New() *Fedora31 {
|
||||
const GigaByte = 1024 * 1024 * 1024
|
||||
|
||||
r := Fedora31{
|
||||
|
|
@ -286,7 +286,7 @@ func New() (*Fedora31, error) {
|
|||
},
|
||||
}
|
||||
|
||||
return &r, nil
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r *Fedora31) Name() string {
|
||||
|
|
|
|||
|
|
@ -19,10 +19,7 @@ func TestListOutputFormats(t *testing.T) {
|
|||
"vmdk",
|
||||
}
|
||||
|
||||
f31, err := fedora31.New()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f31 := fedora31.New()
|
||||
|
||||
if got := f31.ListOutputFormats(); !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("ListOutputFormats() = %v, want %v", got, want)
|
||||
|
|
@ -96,10 +93,7 @@ func TestFilenameFromType(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
f31, err := fedora31.New()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f31 := fedora31.New()
|
||||
got, got1, err := f31.FilenameFromType(tt.args.outputFormat)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("FilenameFromType() error = %v, wantErr %v", err, tt.wantErr)
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ type output struct {
|
|||
const Distro = common.Fedora32
|
||||
const ModulePlatformID = "platform:f32"
|
||||
|
||||
func New() (*Fedora32, error) {
|
||||
func New() *Fedora32 {
|
||||
const GigaByte = 1024 * 1024 * 1024
|
||||
|
||||
r := Fedora32{
|
||||
|
|
@ -286,7 +286,7 @@ func New() (*Fedora32, error) {
|
|||
},
|
||||
}
|
||||
|
||||
return &r, nil
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r *Fedora32) Name() string {
|
||||
|
|
|
|||
|
|
@ -19,10 +19,7 @@ func TestListOutputFormats(t *testing.T) {
|
|||
"vmdk",
|
||||
}
|
||||
|
||||
f32, err := fedora32.New()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f32 := fedora32.New()
|
||||
|
||||
if got := f32.ListOutputFormats(); !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("ListOutputFormats() = %v, want %v", got, want)
|
||||
|
|
@ -96,10 +93,8 @@ func TestFilenameFromType(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
f32, err := fedora32.New()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f32 := fedora32.New()
|
||||
|
||||
got, got1, err := f32.FilenameFromType(tt.args.outputFormat)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("FilenameFromType() error = %v, wantErr %v", err, tt.wantErr)
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ type output struct {
|
|||
const Distro = common.RHEL81
|
||||
const ModulePlatformID = "platform:el8"
|
||||
|
||||
func New() (*RHEL81, error) {
|
||||
func New() *RHEL81 {
|
||||
const GigaByte = 1024 * 1024 * 1024
|
||||
|
||||
r := RHEL81{
|
||||
|
|
@ -425,7 +425,7 @@ func New() (*RHEL81, error) {
|
|||
},
|
||||
}
|
||||
|
||||
return &r, nil
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r *RHEL81) Name() string {
|
||||
|
|
|
|||
|
|
@ -19,10 +19,7 @@ func TestListOutputFormats(t *testing.T) {
|
|||
"vmdk",
|
||||
}
|
||||
|
||||
el81, err := rhel81.New()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
el81 := rhel81.New()
|
||||
|
||||
if got := el81.ListOutputFormats(); !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("ListOutputFormats() = %v, want %v", got, want)
|
||||
|
|
@ -96,10 +93,7 @@ func TestFilenameFromType(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
el81, err := rhel81.New()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
el81 := rhel81.New()
|
||||
got, got1, err := el81.FilenameFromType(tt.args.outputFormat)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("FilenameFromType() error = %v, wantErr %v", err, tt.wantErr)
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ type output struct {
|
|||
const Distro = common.RHEL82
|
||||
const ModulePlatformID = "platform:el8"
|
||||
|
||||
func New() (*RHEL82, error) {
|
||||
func New() *RHEL82 {
|
||||
const GigaByte = 1024 * 1024 * 1024
|
||||
|
||||
r := RHEL82{
|
||||
|
|
@ -425,7 +425,7 @@ func New() (*RHEL82, error) {
|
|||
},
|
||||
}
|
||||
|
||||
return &r, nil
|
||||
return &r
|
||||
}
|
||||
|
||||
func (r *RHEL82) Name() string {
|
||||
|
|
|
|||
|
|
@ -19,10 +19,7 @@ func TestListOutputFormats(t *testing.T) {
|
|||
"vmdk",
|
||||
}
|
||||
|
||||
el82, err := rhel82.New()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
el82 := rhel82.New()
|
||||
|
||||
if got := el82.ListOutputFormats(); !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("ListOutputFormats() = %v, want %v", got, want)
|
||||
|
|
@ -96,10 +93,7 @@ func TestFilenameFromType(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
el82, err := rhel82.New()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
el82 := rhel82.New()
|
||||
got, got1, err := el82.FilenameFromType(tt.args.outputFormat)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("FilenameFromType() error = %v, wantErr %v", err, tt.wantErr)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue