Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update circleci docker #546

Merged
merged 10 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/golang:1.11.5
- image: circleci/golang:1.13.3

environment:
- DEP_VERSION: 0.5.4
Expand Down
25 changes: 25 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
run:
deadline: 5m

linters:
disable-all: true
enable:
- deadcode
- errcheck
- unused
- gosimple
- structcheck
- varcheck
- typecheck
- govet
- staticcheck
- ineffassign
- deadcode
- stylecheck
- interfacer
- unconvert
- goconst
- misspell
- maligned
- gocyclo
- gofmt
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ all:format clean dir gen build-linux build-darwin build-windows copy test

GOCMD=go
GOBUILD=$(GOCMD) build
GOLANGCI_VERSION = 1.21.0

# Binary names
BINARY_NAME=mbt
Expand All @@ -19,13 +20,17 @@ format :
go fmt ./...

tools:
curl -L https://git.io/vp6lP | bash -s -- -b $(GOPATH)/bin/ v3.0.0
gometalinter --version
tools:
@echo "download golangci-lint"
curl -sLO https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_VERSION}/golangci-lint-${GOLANGCI_VERSION}-linux-amd64.tar.gz
tar -xzvf golangci-lint-${GOLANGCI_VERSION}-linux-amd64.tar.gz
cp golangci-lint-${GOLANGCI_VERSION}-linux-amd64/golangci-lint $(GOPATH)/bin
@echo "done"

lint:
@echo "Start project linting"
gometalinter --config=gometalinter.json ./...
@echo "Done"
golangci-lint run --config .golangci.yml
@echo "done linting"

# execute general tests
test:
Expand Down
16 changes: 13 additions & 3 deletions cmd/init_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package commands

import (
"fmt"
"os"

. "github.com/onsi/ginkgo"
Expand All @@ -10,7 +11,10 @@ import (
var _ = Describe("Init", func() {

BeforeEach(func() {
os.Mkdir(getTestPath("result"), os.ModePerm)
err := os.Mkdir(getTestPath("result"), os.ModePerm)
if err != nil {
fmt.Println("error occurred during dir creation")
}
})
AfterEach(func() {
os.RemoveAll(getTestPath("result"))
Expand All @@ -26,10 +30,16 @@ var _ = Describe("Init", func() {
var _ = Describe("Build", func() {

BeforeEach(func() {
os.Mkdir(getTestPath("result"), os.ModePerm)
err := os.Mkdir(getTestPath("result"), os.ModePerm)
if err != nil {
fmt.Println("error occurred during dir creation")
}
})
AfterEach(func() {
os.RemoveAll(getTestPath("result"))
err := os.RemoveAll(getTestPath("result"))
if err != nil {
fmt.Println("error occurred during dir cleanup")
}
})
It("Failure - wrong platform", func() {
buildProjectCmdSrc = getTestPath("mta")
Expand Down
6 changes: 5 additions & 1 deletion cmd/root_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package commands

import (
"fmt"
"os"
"path/filepath"

Expand Down Expand Up @@ -38,7 +39,10 @@ var _ = Describe("Root", func() {
Describe("Execute", func() {
It("Sanity", func() {
out := executeAndProvideOutput(func() {
Execute()
e := Execute()
if e != nil {
fmt.Println("error occurred during execute cmd process")
}
})
Ω(out).Should(ContainSubstring("help"))
Ω(out).Should(ContainSubstring("version"))
Expand Down
15 changes: 12 additions & 3 deletions internal/archive/fsops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ var _ = Describe("FSOPS", func() {
Entry("DirectoryExists", getFullPath("testdata", "level2", "level3")),
)
It("Fails because file with the same name exists", func() {
CreateDirIfNotExist(getFullPath("testdata", "level2", "result"))
err := CreateDirIfNotExist(getFullPath("testdata", "level2", "result"))
if err != nil {
fmt.Println("error occurred during directory creation")
}
file, _ := os.Create(getFullPath("testdata", "level2", "result", "file"))
file.Close()
Ω(CreateDirIfNotExist(getFullPath("testdata", "level2", "result", "file"))).Should(HaveOccurred())
Expand Down Expand Up @@ -325,7 +328,10 @@ var _ = Describe("FSOPS", func() {
It("Sanity", func() {
sourcePath := getFullPath("testdata", "level2", "level3")
targetPath := getFullPath("testdata", "result")
CreateDirIfNotExist(targetPath)
err := CreateDirIfNotExist(targetPath)
if err != nil {
fmt.Println("error occurred during dir creation")
}
files, _ := ioutil.ReadDir(sourcePath)
// Files wrapped to overwrite their methods
var filesWrapped []os.FileInfo
Expand All @@ -340,7 +346,10 @@ var _ = Describe("FSOPS", func() {
It("Sanity - copy in parallel", func() {
sourcePath := getFullPath("testdata", "level2", "level3")
targetPath := getFullPath("testdata", "result")
CreateDirIfNotExist(targetPath)
err := CreateDirIfNotExist(targetPath)
if err != nil {
fmt.Println("error occurred during dir creation")
}
files, _ := ioutil.ReadDir(sourcePath)
// Files wrapped to overwrite their methods
var filesWrapped []os.FileInfo
Expand Down
7 changes: 5 additions & 2 deletions internal/artifacts/assembly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package artifacts
import (
"archive/zip"
"fmt"
"io"
"io/ioutil"
"os"
"strings"
Expand Down Expand Up @@ -64,10 +65,11 @@ func getFileContentFromZip(path string, filename string) ([]byte, error) {
return nil, err
}
defer zipFile.Close()
var fc io.ReadCloser
for _, file := range zipFile.File {
if strings.Contains(file.Name, filename) {
fc, err := file.Open()
defer fc.Close()
fc, err = file.Open()

if err != nil {
return nil, err
}
Expand All @@ -78,5 +80,6 @@ func getFileContentFromZip(path string, filename string) ([]byte, error) {
return c, nil
}
}
fc.Close()
return nil, fmt.Errorf(`file "%s" not found`, filename)
}
9 changes: 7 additions & 2 deletions internal/artifacts/cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ package artifacts

import (
"errors"
dir "github.com/SAP/cloud-mta-build-tool/internal/archive"
"fmt"
"os"

dir "github.com/SAP/cloud-mta-build-tool/internal/archive"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("Cleanup", func() {

BeforeEach(func() {
dir.CreateDirIfNotExist(getTestPath("result", ".mtahtml5_mta_build_tmp"))
err := dir.CreateDirIfNotExist(getTestPath("result", ".mtahtml5_mta_build_tmp"))
if err != nil {
fmt.Println("error occurred during directory creation")
}
})

AfterEach(func() {
Expand Down
4 changes: 2 additions & 2 deletions internal/artifacts/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@ func createMtahtml5TmpFolder() {
func compareMTAContent(expectedFileName string, actualFileName string) {
actual, err := ioutil.ReadFile(expectedFileName)
Ω(err).Should(Succeed())
actualMta, err := mta.Unmarshal([]byte(actual))
actualMta, err := mta.Unmarshal(actual)
Ω(err).Should(Succeed())
expected, err := ioutil.ReadFile(actualFileName)
Ω(err).Should(Succeed())
expectedMta, err := mta.Unmarshal([]byte(expected))
expectedMta, err := mta.Unmarshal(expected)
Ω(err).Should(Succeed())
Ω(actualMta).Should(Equal(expectedMta))
}
55 changes: 44 additions & 11 deletions internal/artifacts/module_arch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,10 @@ module-types:
createFileInGivenPath(filepath.Join(source, defaultDeploymentDescriptorName))
mta := generateTestMta(source, 2, 0, map[string]string{}, map[string]string{"test-module-0": "zip", "test-module-1": "folder"})
mtaBytes, _ := yaml.Marshal(mta)
ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm)
e := ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm)
if e != nil {
fmt.Println("error occurred during file creation")
}
err := CopyMtaContent(source, source, nil, true, os.Getwd)
Ω(err).Should(Succeed())
info, _ := os.Stat(source)
Expand All @@ -482,7 +485,10 @@ module-types:
createFileInGivenPath(filepath.Join(source, defaultDeploymentDescriptorName))
mta := generateTestMta(source, 1, 1, map[string]string{}, map[string]string{"test-resource-0": "zip", "test-module-0": "folder"})
mtaBytes, _ := yaml.Marshal(mta)
ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm)
e := ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm)
if e != nil {
fmt.Println("error occurred during file creation")
}
err := CopyMtaContent(source, source, nil, true, os.Getwd)
Ω(err).Should(Succeed())
info, _ := os.Stat(source)
Expand All @@ -493,7 +499,10 @@ module-types:
createFileInGivenPath(filepath.Join(source, defaultDeploymentDescriptorName))
mta := generateTestMta(source, 0, 2, map[string]string{}, map[string]string{"test-resource-0": "zip", "test-resource-1": "folder"})
mtaBytes, _ := yaml.Marshal(mta)
ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm)
e := ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm)
if e != nil {
fmt.Println("error occurred during file creation")
}
err := CopyMtaContent(source, source, nil, true, os.Getwd)
Ω(err).Should(Succeed())
info, _ := os.Stat(source)
Expand All @@ -504,7 +513,10 @@ module-types:
createFileInGivenPath(filepath.Join(source, defaultDeploymentDescriptorName))
mta := generateTestMta(source, 2, 2, map[string]string{}, map[string]string{"test-resource-0": "zip", "test-resource-1": "zip", "test-module-0": "zip", "test-module-1": "zip"})
mtaBytes, _ := yaml.Marshal(mta)
ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm)
e := ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm)
if e != nil {
fmt.Println("error occurred during file write process")
}
err := CopyMtaContent(source, source, nil, false, os.Getwd)
Ω(err).Should(Succeed())
info, _ := os.Stat(source)
Expand All @@ -516,7 +528,10 @@ module-types:
createFileInGivenPath(filepath.Join(source, defaultDeploymentDescriptorName))
mta := generateTestMta(source, 1, 0, map[string]string{"test-module-0": "test-required"}, map[string]string{"test-module-0": "folder", "test-required": "zip"})
mtaBytes, _ := yaml.Marshal(mta)
ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm)
e := ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm)
if e != nil {
fmt.Println("error occurred during file write process")
}
err := CopyMtaContent(source, source, nil, false, os.Getwd)
Ω(err).Should(Succeed())
info, _ := os.Stat(source)
Expand All @@ -528,7 +543,10 @@ module-types:
mta := generateTestMta(source, 1, 0, map[string]string{"test-module-0": "test-required"}, map[string]string{"test-module-0": "folder", "test-required": "zip"})
mta.Modules[0].Requires[0].Parameters["path"] = "zip1"
mtaBytes, _ := yaml.Marshal(mta)
ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm)
e := ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm)
if e != nil {
fmt.Println("error occurred during file write process")
}
err := CopyMtaContent(source, source, nil, true, os.Getwd)
Ω(err).Should(HaveOccurred())
})
Expand All @@ -537,7 +555,10 @@ module-types:
createFileInGivenPath(filepath.Join(source, defaultDeploymentDescriptorName))
mta := generateTestMta(source, 1, 0, map[string]string{}, map[string]string{"test-module-0": "not-existing-contet"})
mtaBytes, _ := yaml.Marshal(mta)
ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm)
e := ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm)
if e != nil {
fmt.Println("error occurred during file write process")
}
err := CopyMtaContent(source, source, nil, false, os.Getwd)
checkError(err, pathNotExistsMsg, "not-existing-content")
info, _ := os.Stat(source)
Expand All @@ -549,7 +570,10 @@ module-types:
createFileInGivenPath(filepath.Join(source, defaultDeploymentDescriptorName))
mta := generateTestMta(source, 2, 0, map[string]string{}, map[string]string{"test-module-0": "not-existing-contet", "test-module-1": "zip"})
mtaBytes, _ := yaml.Marshal(mta)
ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm)
e := ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm)
if e != nil {
fmt.Println("error occurred during file write process")
}
err := CopyMtaContent(source, source, nil, false, os.Getwd)
checkError(err, pathNotExistsMsg, "not-existing-content")
info, _ := os.Stat(source)
Expand All @@ -565,7 +589,10 @@ module-types:
}
mta := generateTestMta(source, 10, 0, map[string]string{}, modulesWithSameContent)
mtaBytes, _ := yaml.Marshal(mta)
ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm)
e := ioutil.WriteFile(filepath.Join(source, defaultDeploymentDescriptorName), mtaBytes, os.ModePerm)
if e != nil {
fmt.Println("error occurred during file write process")
}
err := CopyMtaContent(source, source, nil, false, os.Getwd)
Ω(err).Should(Succeed())
info, _ := os.Stat(source)
Expand Down Expand Up @@ -668,12 +695,18 @@ func generateTestModule(moduleName, contentType, source string) *mta.Module {

func getContentPath(contentType, source string) string {
if contentType == "zip" {
dir.CopyFile(getTestPath("mta_content_copy_test", "test.zip"), filepath.Join(source, "test.zip"))
e := dir.CopyFile(getTestPath("mta_content_copy_test", "test.zip"), filepath.Join(source, "test.zip"))
if e != nil {
fmt.Println("error occurred during file copy process")
}
return "test.zip"
}
if contentType == "folder" {
dir.CopyDir(getTestPath("mta_content_copy_test", "test-content"),
e := dir.CopyDir(getTestPath("mta_content_copy_test", "test-content"),
filepath.Join(source, "test-content"), true, dir.CopyEntries)
if e != nil {
fmt.Println("error occurred during copy dir process")
}
return "test-content"
}

Expand Down
11 changes: 9 additions & 2 deletions internal/artifacts/mtad_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package artifacts

import (
"fmt"
"os"

"github.com/SAP/cloud-mta/mta"
Expand All @@ -17,7 +18,10 @@ import (
var _ = Describe("Mtad", func() {

BeforeEach(func() {
dir.CreateDirIfNotExist(getTestPath("result"))
e := dir.CreateDirIfNotExist(getTestPath("result"))
if e != nil {
fmt.Println("error occurred during dir creation process")
}
})

AfterEach(func() {
Expand Down Expand Up @@ -67,7 +71,10 @@ var _ = Describe("Mtad", func() {
ep := dir.Loc{SourcePath: getTestPath("mta"), TargetPath: getTestPath("result")}
metaPath := ep.GetMetaPath()
tmpDir := ep.GetTargetTmpDir()
dir.CreateDirIfNotExist(tmpDir)
e := dir.CreateDirIfNotExist(tmpDir)
if e != nil {
fmt.Println("error occurred during dir creation process")
}
file, err := os.Create(metaPath)
Ω(err).Should(Succeed())
mtaBytes, err := dir.Read(&ep)
Expand Down
Loading