Skip to content
Snippets Groups Projects
Commit 1895c0e0876a authored by Florent Aide's avatar Florent Aide
Browse files

tooling: added a linter and fix its complaints

parent 8ff5f76c6269
No related branches found
No related tags found
No related merge requests found
syntax: glob
build
tools/bin
.idea
*.swp
......@@ -12,8 +12,12 @@
vars:
VERSION: 1.0.0
OUTPUT: "build/beaver"
GOLANGCI_LINT_VERSION: v1.44.0
GOLANGCI_LINT_BASE: tools/bin/golangci-lint
GOLANGCI_LINT_BIN: "{{.GOLANGCI_LINT_BASE}}-{{.GOLANGCI_LINT_VERSION}}"
GOLANGCI_LINT_ARGS:
tasks:
default:
cmds:
- task: build
......@@ -15,8 +19,9 @@
tasks:
default:
cmds:
- task: build
build:
desc: build golang project
cmds:
......@@ -28,3 +33,20 @@
main.go
generates:
- "{{.OUTPUT}}"
fetch-golangci-lint:
desc: fetch golangci-lint tool
cmds:
- mkdir -p tools/bin
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b tools/bin {{.GOLANGCI_LINT_VERSION}}
- mv {{.GOLANGCI_LINT_BASE}} {{.GOLANGCI_LINT_BIN}}
status:
- test -x {{.GOLANGCI_LINT_BIN}}
generates:
- "{{.GOLANGCI_LINT_BIN}}"
lint:
desc: lint our golang code to make sure we catch as much errors as possible
deps: [fetch-golangci-lint]
cmds:
- "{{.GOLANGCI_LINT_BIN}} run {{.GOLANGCI_LINT_ARGS}}"
package cmd
import (
"fmt"
"os"
......@@ -4,5 +5,4 @@
"os"
"fmt"
"orus.io/cloudcrane/beaver/runner"
)
......@@ -35,7 +35,11 @@
return fmt.Errorf("failed to create temp dir: %w", err)
}
if !cmd.Args.DryRun {
defer os.RemoveAll(tmpDir)
defer func() {
if err := os.RemoveAll(tmpDir); err != nil {
Logger.Err(err).Str("tempdir", tmpDir).Msg("failed to remove temp dir")
}
}()
}
if err := config.Initialize(tmpDir); err != nil {
......
......@@ -3,6 +3,7 @@
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
......@@ -31,7 +32,10 @@
absConfigDir, err := filepath.Abs("fixtures/")
require.NoError(t, err)
c := NewCmdConfig(tl.Logger(), absConfigDir, testNS, false)
require.NoError(t, c.Initialize())
tmpDir, err := os.MkdirTemp(os.TempDir(), "beaver-")
require.NoError(t, err)
defer assert.NoError(t, os.RemoveAll(tmpDir))
require.NoError(t, c.Initialize(tmpDir))
t.Run("helmCharts", func(t *testing.T) {
pgHelmChart, ok := c.Spec.Charts["postgres"]
......
package runner
import (
"os"
"path/filepath"
"testing"
......@@ -26,5 +27,8 @@
absConfigDir, err := filepath.Abs("fixtures/")
require.NoError(t, err)
c := NewCmdConfig(tl.Logger(), absConfigDir, testNS, false)
require.NoError(t, c.Initialize())
tmpDir, err := os.MkdirTemp(os.TempDir(), "beaver-")
require.NoError(t, err)
defer assert.NoError(t, os.RemoveAll(tmpDir))
require.NoError(t, c.Initialize(tmpDir))
......@@ -30,6 +34,5 @@
args, err := c.Spec.Ytt.BuildArgs(testNS, []string{"/tmp/postgres.1234.yaml", "/tmp/odoo.5678.yaml"})
require.NoError(t, err)
args := c.Spec.Ytt.BuildArgs(testNS, []string{"/tmp/postgres.1234.yaml", "/tmp/odoo.5678.yaml"})
assert.Equal(
t,
args,
......
......@@ -23,7 +23,7 @@
func (r *Runner) Build(tmpDir string) error {
// create helm commands
// create ytt chart commands
var cmds map[string]*cmd.Cmd
cmds := make(map[string]*cmd.Cmd)
for name, chart := range r.config.Spec.Charts {
args, err := chart.BuildArgs(name, r.config.Namespace)
if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment