Skip to content

Commit

Permalink
Create symlinks in test helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
redbaron committed Aug 29, 2017
1 parent a8161f9 commit 346654e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
3 changes: 1 addition & 2 deletions core/controlplane/config/encrypted_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ func (r *RawAssetsOnMemory) WriteToDir(dirname string, includeCAKey bool) error
}

for _, sl := range symlinks {
from := filepath.Join(dirname, sl.from)
to := filepath.Join(dirname, sl.to)

if _, err := os.Lstat(to); err == nil {
Expand All @@ -460,7 +459,7 @@ func (r *RawAssetsOnMemory) WriteToDir(dirname string, includeCAKey bool) error
}
}

if err := os.Symlink(from, to); err != nil {
if err := os.Symlink(sl.from, to); err != nil {
return err
}
}
Expand Down
25 changes: 25 additions & 0 deletions test/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
)

func WithTempDir(fn func(dir string)) {
Expand Down Expand Up @@ -44,5 +45,29 @@ func WithDummyCredentials(fn func(dir string)) {
defer os.Remove(keyFile)
}

symlinks := []struct {
from string
to string
}{
{"ca.pem", "worker-ca.pem"},
{"ca.pem", "etcd-trusted-ca.pem"},
{"ca-key.pem", "worker-ca-key.pem"},
}

for _, sl := range symlinks {
to := filepath.Join(dir, sl.to)

if _, err := os.Lstat(to); err == nil {
if err := os.Remove(to); err != nil {
panic(err)
}
}

if err := os.Symlink(sl.from, to); err != nil {
panic(err)
}
defer os.Remove(to)
}

fn(dir)
}

0 comments on commit 346654e

Please sign in to comment.