Skip to content

Commit

Permalink
feature: adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinicius Gomes Marinho authored and LucaLanziani committed May 10, 2023
1 parent eb1f803 commit 0d21958
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
44 changes: 34 additions & 10 deletions src/services/project/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@ package project
import (
"testing"
"fmt"

"os"
// _"embed"
"github.com/nearform/k8s-kurated-addons-cli/src/utils/defaults"
)

func TestDetectType(t *testing.T) {
var projects = []map[string]string{
{"name": "node", "directory": "example"},
{"name": "go", "directory": "."},
}

root := defaults.RootDirectoryTests
projs := []map[string]string{
{"name": "node", "directory": "example"},
{"name": "go", "directory": "."},
}
var root = defaults.RootDirectoryTests

for _, value := range projs {
func TestDetectType(t *testing.T) {

for _, value := range projects {
test_proj_type := Project{Name: value["name"],
Directory: fmt.Sprintf("%s%s", root, value["directory"])}
Directory: fmt.Sprintf("%s%s", root, value["directory"])}

proj_type, err := test_proj_type.detectType()

Expand All @@ -28,7 +30,29 @@ func TestDetectType(t *testing.T) {
if proj_type != value["name"] {
t.Fatalf("Error: %s project not found", value["name"])
}
}
}

func TestTemplateFile(t *testing.T){

for _, value := range projects {
if _, err := os.Stat(fmt.Sprintf("%s/assets/docker/Dockerfile.%s.tmpl", root, value["name"])); err != nil {
t.Fatalf("Error: Dockerfile.%s.tmpl template not found", value["name"])
}
}
}

func TestLoadDockerfile(t *testing.T){
for _, value := range projects {
proj_dockerfile := Project{Name: value["name"],
Directory: fmt.Sprintf("%s%s", root, value["directory"]),
Resources: defaults.TemplateFS}
_, err := proj_dockerfile.loadDockerfile()


if err != nil {
fmt.Println(err)
t.Fatalf(fmt.Sprintf("Error: %s", err))
}

}
}
9 changes: 8 additions & 1 deletion src/utils/defaults/defaults.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package defaults

import (
"embed"
)

const ProjectDirectory = "."
const RepoName = "ghcr.io/nearform"
const DockerfileName = "Dockerfile.kka"

const RootDirectoryTests = "../../../"
const RootDirectoryTests = "../../../"

//go:embed assets
var TemplateFS embed.FS

0 comments on commit 0d21958

Please sign in to comment.