diff --git a/src/services/project/project_test.go b/src/services/project/project_test.go index 75b6159..85b6e68 100644 --- a/src/services/project/project_test.go +++ b/src/services/project/project_test.go @@ -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() @@ -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)) + } + + } } \ No newline at end of file diff --git a/src/utils/defaults/defaults.go b/src/utils/defaults/defaults.go index 000237e..ea3ac72 100644 --- a/src/utils/defaults/defaults.go +++ b/src/utils/defaults/defaults.go @@ -1,7 +1,14 @@ package defaults +import ( + "embed" +) + const ProjectDirectory = "." const RepoName = "ghcr.io/nearform" const DockerfileName = "Dockerfile.kka" -const RootDirectoryTests = "../../../" \ No newline at end of file +const RootDirectoryTests = "../../../" + +//go:embed assets +var TemplateFS embed.FS \ No newline at end of file