Skip to content

Commit

Permalink
Get available versions by checking previous directory
Browse files Browse the repository at this point in the history
Signed-off-by: joshvanl <[email protected]>
  • Loading branch information
JoshVanL committed Apr 2, 2024
1 parent 22f5768 commit 1a256bd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
42 changes: 30 additions & 12 deletions tests/integration/framework/binary/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,48 @@ func BuildLocal(t *testing.T, name string) {
func BuildPrevious(t *testing.T, name string) {
t.Helper()

var wg sync.WaitGroup
defer wg.Wait()

_, tfile, _, ok := runtime.Caller(0)
require.True(t, ok)
prevPath := filepath.Join(tfile, "../previous")
dir, err := os.ReadDir(prevPath)
require.NoError(t, err)

var wg sync.WaitGroup
defer wg.Wait()

wg.Add(len(dir))
for _, entry := range dir {
go func(entry os.DirEntry) {
versions := PreviousVersions(t)
wg.Add(len(versions))
for _, v := range versions {
go func(v string) {
defer wg.Done()

t.Logf("Building previous binary: [%q] %q", entry.Name(), name)
rootDir := filepath.Join(prevPath, entry.Name())
t.Logf("Building previous binary: [%q] %q", v, name)
rootDir := filepath.Join(prevPath, v)
buildBin(t, buildReq{
name: name,
rootDir: rootDir,
mainLocation: name,
outputBinPath: filepath.Join(os.TempDir(), "dapr_integration_tests/"+name+"-"+entry.Name()),
outputBinPath: filepath.Join(os.TempDir(), "dapr_integration_tests/"+name+"-"+v),
})
}(entry)
}(v)
}
}

func PreviousVersions(t *testing.T) []string {
_, tfile, _, ok := runtime.Caller(0)
require.True(t, ok)
prevPath := filepath.Join(tfile, "../previous")

dir, err := os.ReadDir(prevPath)
require.NoError(t, err)

versions := make([]string, 0, len(dir)-1)
for _, d := range dir {
if !d.IsDir() {
continue
}
versions = append(versions, d.Name())
}

return versions
}

type buildReq struct {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/framework/process/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func New(t *testing.T, binPath string, args []string, fopts ...Option) *exec {
}

if opts.version != nil {
binPath += "-v" + *opts.version
binPath += "-" + *opts.version
}

return &exec{
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/framework/process/exec/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"testing"

"github.com/stretchr/testify/require"

"github.com/dapr/dapr/tests/integration/framework/binary"
)

type options struct {
Expand Down Expand Up @@ -69,7 +71,7 @@ func WithEnvVars(t *testing.T, envs ...string) Option {
}

func WithVersion(t *testing.T, version string) Option {
require.Contains(t, []string{"", "1.13"}, version)
require.Contains(t, append(binary.PreviousVersions(t), ""), version)
return func(o *options) {
o.version = &version
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (s *skew) Setup(t *testing.T) []framework.Option {
s.daprd2 = daprd.New(t,
daprd.WithAppProtocol("grpc"),
daprd.WithAppPort(srv2.Port(t)),
daprd.WithExecOptions(exec.WithVersion(t, "1.13")),
daprd.WithExecOptions(exec.WithVersion(t, "v1.13")),
)

return []framework.Option{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (s *skew) Setup(t *testing.T) []framework.Option {
s.daprd1 = daprd.New(t, daprd.WithAppPort(srv.Port()))
s.daprd2 = daprd.New(t,
daprd.WithAppPort(srv.Port()),
daprd.WithExecOptions(exec.WithVersion(t, "1.13")),
daprd.WithExecOptions(exec.WithVersion(t, "v1.13")),
)

return []framework.Option{
Expand Down

0 comments on commit 1a256bd

Please sign in to comment.