From 402bb0c37c3d0f27f632b89e6097520b63217861 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Wed, 3 Jul 2024 22:00:17 +0100 Subject: [PATCH] feat: Update CheckVersion to accept a libDir in case of non-std install --- examples/protobuf-message/protobuf_provider_test.go | 2 +- internal/checker/checker.go | 6 ++++-- version/version.go | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/protobuf-message/protobuf_provider_test.go b/examples/protobuf-message/protobuf_provider_test.go index 94770cf51..263a99883 100644 --- a/examples/protobuf-message/protobuf_provider_test.go +++ b/examples/protobuf-message/protobuf_provider_test.go @@ -26,7 +26,7 @@ func TestPluginMessageProvider(t *testing.T) { err := pactlog.SetLogLevel("TRACE") assert.NoError(t, err) - pactversion.CheckVersion() + pactversion.CheckVersion("/tmp") verifier := provider.NewVerifier() diff --git a/internal/checker/checker.go b/internal/checker/checker.go index 9e7bf2bf5..483eaf4e1 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -5,7 +5,7 @@ import ( "github.com/pact-foundation/pact-go/v2/internal/native" ) -func CheckInstall() error { +func CheckInstall(libDir string) error { // initialised the lib registry. It just needs one of the main lib interfaces Version() here installer.LibRegistry[installer.FFIPackage] = &native.MockServer{} @@ -13,6 +13,8 @@ func CheckInstall() error { if err != nil { return err } - + if libDir != "" { + i.SetLibDir(libDir) + } return i.CheckInstallation() } diff --git a/version/version.go b/version/version.go index 4efaba7e2..b5666d553 100644 --- a/version/version.go +++ b/version/version.go @@ -9,8 +9,8 @@ import ( // CheckVersion checks if the currently installed version is within semver range // and will attempt to download the files to the default or configured directory if // incorrect -func CheckVersion() { - if err := checker.CheckInstall(); err != nil { +func CheckVersion(libDir string) { + if err := checker.CheckInstall(libDir); err != nil { log.Fatal("check version failed:", err) }