Skip to content

Commit

Permalink
Fix linter errors
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot committed Sep 30, 2019
1 parent 473f73a commit bb475d3
Show file tree
Hide file tree
Showing 27 changed files with 91 additions and 157 deletions.
2 changes: 1 addition & 1 deletion acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ func waitForResponse(t *testing.T, port string, timeout time.Duration) string {
for {
select {
case <-ticker.C:
resp, err := h.HttpGetE("http://localhost:"+port, map[string]string{})
resp, err := h.HTTPGetE("http://localhost:"+port, map[string]string{})
if err != nil {
break
}
Expand Down
2 changes: 1 addition & 1 deletion blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (b blob) Open() (r io.ReadCloser, err error) {
return rc, nil
}

func isGZip(file *os.File) (bool, error) {
func isGZip(file io.ReadSeeker) (bool, error) {
b := make([]byte, 3)
if _, err := file.Seek(0, 0); err != nil {
return false, err
Expand Down
37 changes: 17 additions & 20 deletions blob/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,51 +29,48 @@ type downloader struct {
baseCacheDir string
}

func NewDownloader(logger logging.Logger, baseCacheDir string) *downloader {
func NewDownloader(logger logging.Logger, baseCacheDir string) *downloader { //nolint:golint,gosimple
return &downloader{
logger: logger,
baseCacheDir: baseCacheDir,
}
}

func (d *downloader) Download(ctx context.Context, pathOrUri string) (Blob, error) {
if paths.IsURI(pathOrUri) {
parsedUrl, err := url.Parse(pathOrUri)
func (d *downloader) Download(ctx context.Context, pathOrURI string) (Blob, error) {
if paths.IsURI(pathOrURI) {
parsedURL, err := url.Parse(pathOrURI)
if err != nil {
return nil, errors.Wrapf(err, "parsing path/uri %s", style.Symbol(pathOrUri))
return nil, errors.Wrapf(err, "parsing path/uri %s", style.Symbol(pathOrURI))
}

var path string
switch parsedUrl.Scheme {
switch parsedURL.Scheme {
case "file":
path, err = paths.UriToFilePath(pathOrUri)
path, err = paths.URIToFilePath(pathOrURI)
case "http", "https":
path, err = d.handleHTTP(ctx, pathOrUri)
path, err = d.handleHTTP(ctx, pathOrURI)
default:
err = fmt.Errorf("unsupported protocol %s in URI %s", style.Symbol(parsedUrl.Scheme), style.Symbol(pathOrUri))
err = fmt.Errorf("unsupported protocol %s in URI %s", style.Symbol(parsedURL.Scheme), style.Symbol(pathOrURI))
}
if err != nil {
return nil, err
}

return &blob{path: path}, nil
} else {
path, err := d.handleFile(pathOrUri)
if err != nil {
return nil, err
}

return &blob{path: path}, nil
}

path := d.handleFile(pathOrURI)

return &blob{path: path}, nil
}

func (d *downloader) handleFile(path string) (string, error) {
func (d *downloader) handleFile(path string) string {
path, err := filepath.Abs(path)
if err != nil {
return "", nil
return ""
}

return path, nil
return path
}

func (d *downloader) handleHTTP(ctx context.Context, uri string) (string, error) {
Expand Down Expand Up @@ -137,7 +134,7 @@ func (d *downloader) downloadAsStream(ctx context.Context, uri string, etag stri
req.Header.Set("If-None-Match", etag)
}

resp, err := (&http.Client{}).Do(req)
resp, err := (&http.Client{}).Do(req) //nolint:bodyclose
if err != nil {
return nil, "", err
}
Expand Down
2 changes: 1 addition & 1 deletion blob/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func testDownloader(t *testing.T, when spec.G, it spec.S) {
absPath, err := filepath.Abs(relPath)
h.AssertNil(t, err)

uri, err := paths.FilePathToUri(absPath)
uri, err := paths.FilePathToURI(absPath)
h.AssertNil(t, err)

b, err := subject.Download(context.TODO(), uri)
Expand Down
10 changes: 4 additions & 6 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,10 @@ func (c *Client) Build(ctx context.Context, opts BuildOptions) error {
defer c.docker.ImageRemove(context.Background(), ephemeralBuilder.Name(), types.ImageRemoveOptions{Force: true})

descriptor := ephemeralBuilder.GetLifecycleDescriptor()
lifecycleVersion := descriptor.Info.Version
if lifecycleVersion == nil {
if descriptor.Info.Version == nil {
c.logger.Warnf("lifecycle version unknown, assuming %s", style.Symbol(builder.AssumedLifecycleVersion))
lifecycleVersion = builder.VersionMustParse(builder.AssumedLifecycleVersion)
} else {
c.logger.Debugf("Executing lifecycle version %s", style.Symbol(lifecycleVersion.String()))
c.logger.Debugf("Executing lifecycle version %s", style.Symbol(descriptor.Info.Version.String()))
}

lcPlatformAPIVersion := api.MustParse(builder.AssumedPlatformAPIVersion)
Expand Down Expand Up @@ -168,7 +166,7 @@ func (c *Client) validateRunImage(context context.Context, name string, noPull b

func (c *Client) processAppPath(appPath string) (string, error) {
var (
resolvedAppPath = appPath
resolvedAppPath string
err error
)

Expand Down Expand Up @@ -294,7 +292,7 @@ func ensureBPSupport(bpPath string) (err error) {
}

if u.Scheme == "file" {
p, err = paths.UriToFilePath(bpPath)
p, err = paths.URIToFilePath(bpPath)
if err != nil {
return err
}
Expand Down
6 changes: 2 additions & 4 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,8 @@ func (l *Lifecycle) Execute(ctx context.Context, opts LifecycleOptions) error {
l.logger.Info(style.Step("RESTORING"))
if opts.ClearCache {
l.logger.Info("Skipping 'restore' due to clearing cache")
} else {
if err := l.Restore(ctx, buildCache.Name()); err != nil {
return err
}
} else if err := l.Restore(ctx, buildCache.Name()); err != nil {
return err
}

l.logger.Info(style.Step("ANALYZING"))
Expand Down
16 changes: 7 additions & 9 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ func constructBuilder(img imgutil.Image, newName string, metadata Metadata) (*Bu
lifecycleVersion = metadata.Lifecycle.Version
}

buildpackApiVersion := api.MustParse(AssumedBuildpackAPIVersion)
buildpackAPIVersion := api.MustParse(AssumedBuildpackAPIVersion)
if metadata.Lifecycle.API.BuildpackVersion != nil {
buildpackApiVersion = metadata.Lifecycle.API.BuildpackVersion
buildpackAPIVersion = metadata.Lifecycle.API.BuildpackVersion
}

platformApiVersion := api.MustParse(AssumedPlatformAPIVersion)
platformAPIVersion := api.MustParse(AssumedPlatformAPIVersion)
if metadata.Lifecycle.API.PlatformVersion != nil {
platformApiVersion = metadata.Lifecycle.API.PlatformVersion
platformAPIVersion = metadata.Lifecycle.API.PlatformVersion
}

var order Order
Expand All @@ -146,8 +146,8 @@ func constructBuilder(img imgutil.Image, newName string, metadata Metadata) (*Bu
Version: lifecycleVersion,
},
API: LifecycleAPI{
PlatformVersion: platformApiVersion,
BuildpackVersion: buildpackApiVersion,
PlatformVersion: platformAPIVersion,
BuildpackVersion: buildpackAPIVersion,
},
},
env: map[string]string{},
Expand Down Expand Up @@ -224,9 +224,7 @@ func (b *Builder) Save(logger logging.Logger) error {
}

b.metadata.Groups = resolvedOrder.ToV1Order()
if err := processMetadata(&b.metadata); err != nil {
return errors.Wrap(err, "processing metadata")
}
processMetadata(&b.metadata)

tmpDir, err := ioutil.TempDir("", "create-builder-scratch")
if err != nil {
Expand Down
10 changes: 3 additions & 7 deletions builder/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ func (o V1Order) ToOrder() Order {
var order Order
for _, gp := range o {
var buildpacks []BuildpackRef
for _, bp := range gp.Buildpacks {
buildpacks = append(buildpacks, bp)
}
buildpacks = append(buildpacks, gp.Buildpacks...)

order = append(order, OrderEntry{
Group: buildpacks,
Expand All @@ -50,12 +48,10 @@ func (o V1Order) ToOrder() Order {
}

func (o Order) ToV1Order() V1Order {
var order V1Order
var order V1Order //nolint:prealloc
for _, gp := range o {
var buildpacks []BuildpackRef
for _, bp := range gp.Group {
buildpacks = append(buildpacks, bp)
}
buildpacks = append(buildpacks, gp.Group...)

order = append(order, V1Group{
Buildpacks: buildpacks,
Expand Down
2 changes: 1 addition & 1 deletion builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func transformRelativePath(uri, relativeTo string) (string, error) {
if parsed.Scheme == "" {
if !filepath.IsAbs(parsed.Path) {
absPath := filepath.Join(relativeTo, parsed.Path)
return paths.FilePathToUri(absPath)
return paths.FilePathToURI(absPath)
}
}

Expand Down
4 changes: 1 addition & 3 deletions builder/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type RunImageMetadata struct {
Mirrors []string `json:"mirrors" toml:"mirrors"`
}

func processMetadata(md *Metadata) error {
func processMetadata(md *Metadata) {
for i, bp := range md.Buildpacks {
var matchingBps []BuildpackInfo
for _, bp2 := range md.Buildpacks {
Expand All @@ -56,6 +56,4 @@ func processMetadata(md *Metadata) error {
md.Buildpacks[i].Latest = true
}
}

return nil
}
2 changes: 1 addition & 1 deletion commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func parseEnv(envFiles []string, envVars []string) (map[string]string, error) {
}

func parseEnvFile(filename string) (map[string]string, error) {
out := make(map[string]string, 0)
out := make(map[string]string)
f, err := ioutil.ReadFile(filename)
if err != nil {
return nil, errors.Wrapf(err, "open %s", filename)
Expand Down
12 changes: 3 additions & 9 deletions commands/inspect_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,7 @@ Detection Order:
{{ end }}`,
))

var (
bps = ""
order = ""
runImgs = ""
)

bps, err = buildpacksOutput(info.Buildpacks)
bps, err := buildpacksOutput(info.Buildpacks)
if err != nil {
return nil, err
}
Expand All @@ -151,7 +145,7 @@ Detection Order:
warnings = append(warnings, "Users must supply buildpacks from the host machine")
}

order, err = detectionOrderOutput(info.Groups)
order, err := detectionOrderOutput(info.Groups)
if err != nil {
return nil, err
}
Expand All @@ -161,7 +155,7 @@ Detection Order:
warnings = append(warnings, "Users must build with explicitly specified buildpacks")
}

runImgs, err = runImagesOutput(info.RunImage, info.RunImageMirrors, cfg)
runImgs, err := runImagesOutput(info.RunImage, info.RunImageMirrors, cfg)
if err != nil {
return nil, err
}
Expand Down
8 changes: 5 additions & 3 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ func (c *Client) resolveRunImage(runImage, targetRegistry string, stackInfo buil
stackInfo.RunImage.Mirrors,
additionalMirrors[stackInfo.RunImage.Image],
)
if runImageName == stackInfo.RunImage.Image {

switch {
case runImageName == stackInfo.RunImage.Image:
c.logger.Debugf("Selected run image %s", style.Symbol(runImageName))
} else if contains(stackInfo.RunImage.Mirrors, runImageName) {
case contains(stackInfo.RunImage.Mirrors, runImageName):
c.logger.Debugf("Selected run image mirror %s", style.Symbol(runImageName))
} else {
default:
c.logger.Debugf("Selected run image mirror %s from local config", style.Symbol(runImageName))
}
return runImageName
Expand Down
7 changes: 4 additions & 3 deletions create_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,17 @@ func (c *Client) fetchLifecycle(ctx context.Context, config builder.LifecycleCon
}

var uri string
if config.Version != "" {
switch {
case config.Version != "":
v, err := semver.NewVersion(config.Version)
if err != nil {
return nil, errors.Wrapf(err, "%s must be a valid semver", style.Symbol("lifecycle.version"))
}

uri = uriFromLifecycleVersion(*v)
} else if config.URI != "" {
case config.URI != "":
uri = config.URI
} else {
default:
uri = uriFromLifecycleVersion(*semver.MustParse(builder.DefaultLifecycleVersion))
}

Expand Down
2 changes: 1 addition & 1 deletion interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ type ImageFetcher interface {
//go:generate mockgen -package testmocks -destination testmocks/mock_downloader.go github.com/buildpack/pack Downloader

type Downloader interface {
Download(ctx context.Context, pathOrUri string) (blob.Blob, error)
Download(ctx context.Context, pathOrURI string) (blob.Blob, error)
}
2 changes: 1 addition & 1 deletion internal/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func finalizeHeader(header *tar.Header, uid, gid int, mode int64) {
header.Gname = ""
}

func IsZip(file *os.File) (bool, error) {
func IsZip(file io.Reader) (bool, error) {
b := make([]byte, 4)
_, err := file.Read(b)
if err != nil && err != io.EOF {
Expand Down
2 changes: 1 addition & 1 deletion internal/archive/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (v *tarVerifier) nextFile(name, expectedFileContents string, expectedFileMo
v.t.Fatalf(`expected %s to have gid %d but, got: %d`, header.Name, v.gid, header.Gid)
}

fileContents := make([]byte, header.Size, header.Size)
fileContents := make([]byte, header.Size)
v.tr.Read(fileContents)
if string(fileContents) != expectedFileContents {
v.t.Fatalf(`expected to some-file.txt to have %s got %s`, expectedFileContents, string(fileContents))
Expand Down
47 changes: 0 additions & 47 deletions internal/fakes/fake_buildpack_blob.go

This file was deleted.

Loading

0 comments on commit bb475d3

Please sign in to comment.