Skip to content

Commit

Permalink
feat: add native lib path function (#376)
Browse files Browse the repository at this point in the history
feat: add native lib path function
  • Loading branch information
becheran authored Feb 13, 2024
1 parent 59a586d commit f893818
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ import (
"github.com/spf13/afero"
)

// NativeLibPath returns the absolute path to the go package used to link to the native rust library
func NativeLibPath() string {
_, file, _, ok := runtime.Caller(0)
if !ok {
return ""
}
pactRoot := filepath.Dir(filepath.Dir(file))
return filepath.Join(pactRoot, "internal", "native")
}

// Installer is used to check the Pact Go installation is setup correctly, and can automatically install
// packages if required
type Installer struct {
Expand Down
11 changes: 11 additions & 0 deletions installer/installer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@ package installer

import (
"fmt"
"os"
"path/filepath"
"testing"

"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
)

func TestNativeLibPath(t *testing.T) {
lib := NativeLibPath()

libFilePath := filepath.Join(lib, "lib.go")
file, err := os.ReadFile(libFilePath)
assert.NoError(t, err)
assert.Contains(t, string(file), "-lpact_ffi")
}

// 1. Be able to specify the path of the binary in advance
// 2. Check if the correct versions of the libs are present???
// 3. Download the appropriate libs
Expand Down

0 comments on commit f893818

Please sign in to comment.