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

IZE-680 test dir restructure boilerplate template test-e2e #526

Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/run.e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:

- name: Run Tests
run: |
go test -v --timeout 0 --tags="e2e ecs_apps" ./test-e2e
go test -v --timeout 0 --tags="e2e ecs_apps" ./tests/e2e

- name: Cleanup Infra
if: ${{ always() }}
Expand Down Expand Up @@ -167,7 +167,7 @@ jobs:

- name: Run Tests
run: |
go test -v --timeout 0 --tags="e2e bastion_tunnel" ./test-e2e
go test -v --timeout 0 --tags="e2e bastion_tunnel" ./tests/e2e

- name: Cleanup Infra
if: ${{ always() }}
Expand Down Expand Up @@ -232,4 +232,4 @@ jobs:

- name: Run Tests
run: |
go test -v --timeout 0 --tags="e2e terraform" ./test-e2e
go test -v --timeout 0 --tags="e2e terraform" ./tests/e2e
7 changes: 4 additions & 3 deletions internal/commands/ci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package commands

import (
_ "embed"
"github.com/hazelops/ize/internal/config"
"github.com/hazelops/ize/internal/generate"
"os"
"path/filepath"
"testing"
"text/template"

"github.com/hazelops/ize/internal/config"
"github.com/hazelops/ize/tests/data"
)

func TestTemplate_Execute(t *testing.T) {
tempDir, _ := os.MkdirTemp("", "test")
_, err := generate.GenerateFiles("boilerplate-template", filepath.Join(tempDir, "template"))
err := copyEmbedData(data.TestData, "boilerplate-template", filepath.Join(tempDir, "template"))
if err != nil {
t.Error(err)
return
Expand Down
37 changes: 36 additions & 1 deletion internal/commands/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"embed"
"encoding/pem"
"golang.org/x/crypto/ssh"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
"testing"

"golang.org/x/crypto/ssh"
)

func setConfigFile(path, data string, t *testing.T) {
Expand Down Expand Up @@ -66,3 +69,35 @@ func resetEnv(environ []string) {
os.Setenv(kv[0], kv[1])
}
}

func copyEmbedData(fsys embed.FS, sourceDir string, targetDir string) error {
subdirs, err := fsys.ReadDir(sourceDir)
if err != nil {
return err
}
for _, d := range subdirs {
sourcePath := path.Join(sourceDir, d.Name())
if d.IsDir() {
err = copyEmbedData(fsys, path.Join(sourceDir, d.Name()), path.Join(targetDir, d.Name()))
if err != nil {
return err
}
} else {
localPath := filepath.Join(targetDir, d.Name())

content, err := fsys.ReadFile(sourcePath)
if err != nil {
return err
}
err = os.MkdirAll(filepath.Dir(localPath), 0755)
if err != nil {
return err
}
err = os.WriteFile(localPath, content, 0755)
if err != nil {
return err
}
}
}
return nil
}
8 changes: 8 additions & 0 deletions tests/data/embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package data

import "embed"

var (
//go:embed */*
TestData embed.FS
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.