Files
mixer-tools/builder/bundle_validate.go
T
Rodrigo Chiossi 01e6ca3e43 lint: Fix errors identified by golangci-lint
golangci-lint identified a couple errors that were not found by
gometalinter. This patch fixes the detected errors.

Signed-off-by: Rodrigo Chiossi <rodrigo.chiossi@intel.com>
2019-09-19 16:57:37 +02:00

55 lines
1.6 KiB
Go

// Copyright © 2018 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package builder
import (
"fmt"
"path/filepath"
"github.com/clearlinux/mixer-tools/helpers"
"github.com/pkg/errors"
)
// ValidateLocalBundles runs bundle parsing validation on all local bundles.
func (b *Builder) ValidateLocalBundles(lvl ValidationLevel) error {
files, err := helpers.ListVisibleFiles(b.Config.Mixer.LocalBundleDir)
if err != nil {
return errors.Wrap(err, "Failed to read local-bundles")
}
return b.ValidateBundles(files, lvl)
}
// ValidateBundles runs bundle parsing validation on a list of local bundles. In
// addition to parsing errors, errors are generated if the bundle is not found
// in local-bundles.
func (b *Builder) ValidateBundles(bundles []string, lvl ValidationLevel) error {
invalid := false
for _, bundle := range bundles {
path := filepath.Join(b.Config.Mixer.LocalBundleDir, bundle)
if err := validateBundleFile(path, lvl); err != nil {
invalid = true
fmt.Printf("Invalid: %q:\n%s\n\n", bundle, err)
}
}
if invalid {
return errors.New("Invalid bundles found")
}
return nil
}