Skip to content

Commit

Permalink
Merge pull request #1234 from godaddy/godog-test-flags
Browse files Browse the repository at this point in the history
[go cltf] add support for godog commandline flags
  • Loading branch information
aka-bo authored Feb 18, 2025
2 parents c0ab028 + 5b09aec commit 5eeb9fa
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
6 changes: 1 addition & 5 deletions tests/cross-language/go/decrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,7 @@ func decryptedDataShouldBeEqualTo(payload string) error {
}

func TestDecryptFeatures(t *testing.T) {
opts := godog.Options{
Paths: []string{"../features/decrypt.feature"},
Format: "pretty",
TestingT: t,
}
opts := godogOptsWithDefaults(t, "../features/decrypt.feature")

status := godog.TestSuite{
Name: "decrypt",
Expand Down
33 changes: 28 additions & 5 deletions tests/cross-language/go/encrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"encoding/base64"
"encoding/json"
"flag"
"fmt"
"os"
"testing"
Expand All @@ -22,8 +23,13 @@ var (
payloadString string
encryptedPayloadString string
connection *sql.DB
godogOpts godog.Options
)

func init() {
godog.BindFlags("godog.", flag.CommandLine, &godogOpts)
}

func iHave(payload string) error {
payloadString = payload

Expand Down Expand Up @@ -146,13 +152,25 @@ func connectSQL() error {
return nil
}

func TestEncryptFeatures(t *testing.T) {
opts := godog.Options{
Paths: []string{"../features/encrypt.feature"},
Format: "pretty",
TestingT: t,
func godogOptsWithDefaults(t *testing.T, defaultPath string) (opts godog.Options) {
opts = godogOpts

opts.TestingT = t

if opts.Paths == nil {
opts.Paths = []string{defaultPath}
}

if opts.Format == "" {
opts.Format = "pretty"
}

return
}

func TestEncryptFeatures(t *testing.T) {
opts := godogOptsWithDefaults(t, "../features/encrypt.feature")

status := godog.TestSuite{
Name: "encrypt",
TestSuiteInitializer: InitializeTestSuite,
Expand All @@ -164,3 +182,8 @@ func TestEncryptFeatures(t *testing.T) {
t.Fatal("Non-zero status returned")
}
}

func TestMain(m *testing.M) {
flag.Parse()
os.Exit(m.Run())
}
2 changes: 1 addition & 1 deletion tests/cross-language/scripts/decrypt_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cd ..

cd go
echo "----------------------Decrypting data using Go--------------------------"
go test -v -test.run '^TestDecryptFeatures$'
go test -v -test.run '^TestDecryptFeatures$' -godog.paths=../features/decrypt.feature
cd ..

cd sidecar
Expand Down
2 changes: 1 addition & 1 deletion tests/cross-language/scripts/encrypt_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cd ..

cd go
echo "----------------------Encrypting payload using Go-----------------------"
go test -v -test.run '^TestEncryptFeatures$'
go test -v -test.run '^TestEncryptFeatures$' -godog.paths=../features/encrypt.feature
cd ..

cd sidecar
Expand Down

0 comments on commit 5eeb9fa

Please sign in to comment.