diff --git a/.gitignore b/.gitignore index 9887811..55f91a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ vendor c.out +.env diff --git a/go.mod b/go.mod index be2ce61..5d204ad 100644 --- a/go.mod +++ b/go.mod @@ -3,3 +3,5 @@ module github.com/teamwork/vat/v3 go 1.21 require github.com/golang/mock v1.6.0 + +require github.com/joho/godotenv v1.5.1 // indirect diff --git a/go.sum b/go.sum index d067127..79eaa87 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= diff --git a/uk_vat_service_test.go b/uk_vat_service_test.go index de6d5fa..13a4ae5 100644 --- a/uk_vat_service_test.go +++ b/uk_vat_service_test.go @@ -5,8 +5,11 @@ package vat import ( "errors" + "os" "testing" "time" + + "github.com/joho/godotenv" ) // test numbers to use with the UK VAT service API in their sandbox environment: @@ -25,11 +28,21 @@ var ukTests = []struct { // TestUKVATService tests the UK VAT service. Just meant to be a quick way to check that this service is working. // Makes external calls that sometimes might fail. Do not include them in CI/CD. func TestUKVATService(t *testing.T) { + // Load environment variables from .env file + if err := godotenv.Load(); err != nil { + t.Fatalf("Error loading .env file: %v", err) + } + opts := ValidatorOpts{ - UKClientID: "yourClientID", // insert your own client ID and secret here. Do not commit real values. - UKClientSecret: "yourClientSecret", + UKClientID: os.Getenv("CLIENT_ID"), + UKClientSecret: os.Getenv("SECRET"), IsUKTest: true, } + + if opts.UKClientID == "" || opts.UKClientSecret == "" { + t.Fatal("CLIENT_ID and SECRET must be set in .env file") + } + token, err := GenerateUKAccessToken(opts) if err != nil { t.Fatal(err) diff --git a/vies_service_test.go b/vies_service_test.go index 0468e14..2c343cd 100644 --- a/vies_service_test.go +++ b/vies_service_test.go @@ -6,6 +6,7 @@ package vat import ( "errors" "testing" + "time" ) var viesTests = []struct { @@ -26,5 +27,6 @@ func TestViesService(t *testing.T) { if !errors.Is(err, test.expectedError) { t.Errorf("Expected <%v> for %v, got <%v>", test.expectedError, test.vatNumber, err) } + time.Sleep(time.Second * 2) // delay to prevent rate limiting } }