Skip to content

Commit

Permalink
Merge pull request #526 from hazelops/IZE-680-test-dir-restructure-bo…
Browse files Browse the repository at this point in the history
…ilerplate-template-test-e-2-e

IZE-680 test dir restructure boilerplate template test-e2e
  • Loading branch information
psihachina authored Nov 5, 2022
2 parents a6eb711 + c96c5be commit 4fc06e8
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 7 deletions.
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
}
File renamed without changes.
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.

0 comments on commit 4fc06e8

Please sign in to comment.