Skip to content

Commit

Permalink
chore: use common test util to skip integration test when needed (#162)
Browse files Browse the repository at this point in the history
* chore: support using Go generate to generate proto code

* chore: use common test util to skip integration test when needed

* tidy
  • Loading branch information
yolocs authored and verbanicm committed Jan 6, 2023
1 parent 0ef93a5 commit 2ba9d16
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:

- name: 'Run integration tests'
env:
TEST_JVS_INTEGRATION: 'true'
TEST_INTEGRATION: 'true'
TEST_JVS_KMS_KEY_RING: 'projects/${{ env.PROJECT_ID }}/locations/global/keyRings/ci-keyring'
run: |-
go test \
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
cloud.google.com/go/kms v1.4.0
github.com/abcxyz/pkg v0.0.0-20221010190357-4e20e092316a
github.com/abcxyz/pkg v0.1.2-0.20230106203017-d05e75ed64fa
github.com/golang/protobuf v1.5.2
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/abcxyz/pkg v0.0.0-20221010190357-4e20e092316a h1:qibheUlonMxv3rMhBnarccQiUwiZivW8TUQiNn4+aG4=
github.com/abcxyz/pkg v0.0.0-20221010190357-4e20e092316a/go.mod h1:vzO7x3uKaRbxbCCrQZvgxrglkVhMbf/1FlDgU/DJoxA=
github.com/abcxyz/pkg v0.1.2-0.20230106203017-d05e75ed64fa h1:RfAkfbvZ+LOIwTgfyDV4vi3wiVCNDqvtI2FroCQ6QDI=
github.com/abcxyz/pkg v0.1.2-0.20230106203017-d05e75ed64fa/go.mod h1:vzO7x3uKaRbxbCCrQZvgxrglkVhMbf/1FlDgU/DJoxA=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
Expand Down
53 changes: 9 additions & 44 deletions test/integ/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,9 @@ import (

func TestJVS(t *testing.T) {
t.Parallel()

if !testIsIntegration(t) {
// Not an integ test, don't run anything.
t.Skip("Not an integration test, skipping...")
return
}
testutil.SkipIfNotIntegration(t)

ctx := context.Background()

keyRing := os.Getenv("TEST_JVS_KMS_KEY_RING")
if keyRing == "" {
t.Fatal("Key ring must be provided using TEST_JVS_KMS_KEY_RING env variable.")
Expand Down Expand Up @@ -310,13 +304,9 @@ func TestJVS(t *testing.T) {
//nolint:tparallel
func TestRotator(t *testing.T) {
t.Parallel()
ctx := context.Background()
if !testIsIntegration(t) {
// Not an integ test, don't run anything.
t.Skip("Not an integration test, skipping...")
return
}
testutil.SkipIfNotIntegration(t)

ctx := context.Background()
kmsClient, keyName := testSetupRotator(ctx, t)

cfg := &config.CryptoConfig{
Expand Down Expand Up @@ -401,13 +391,9 @@ func TestRotator(t *testing.T) {
//nolint:tparallel // Subtests need to run in sequence. To parallelize this, but we'd need separate keys from the above (more cruft).
func TestRotator_EdgeCases(t *testing.T) {
t.Parallel()
ctx := context.Background()
if !testIsIntegration(t) {
// Not an integ test, don't run anything.
t.Skip("Not an integration test, skipping...")
return
}
testutil.SkipIfNotIntegration(t)

ctx := context.Background()
kmsClient, keyName := testSetupRotator(ctx, t)

cfg := &config.CryptoConfig{
Expand Down Expand Up @@ -463,13 +449,9 @@ func TestRotator_EdgeCases(t *testing.T) {

func TestPublicKeys(t *testing.T) {
t.Parallel()
ctx := context.Background()
if !testIsIntegration(t) {
// Not an integ test, don't run anything.
t.Skip("Not an integration test, skipping...")
return
}
testutil.SkipIfNotIntegration(t)

ctx := context.Background()
kmsClient, err := kms.NewKeyManagementClient(ctx)
if err != nil {
t.Fatalf("failed to setup kms client: %s", err)
Expand Down Expand Up @@ -529,13 +511,9 @@ func TestPublicKeys(t *testing.T) {
//nolint:tparallel
func TestCertActions(t *testing.T) {
t.Parallel()
ctx := context.Background()
if !testIsIntegration(t) {
// Not an integ test, don't run anything.
t.Skip("Not an integration test, skipping...")
return
}
testutil.SkipIfNotIntegration(t)

ctx := context.Background()
kmsClient, keyName := testSetupRotator(ctx, t)

cfg := &config.CryptoConfig{
Expand Down Expand Up @@ -786,19 +764,6 @@ func testValidateKeyVersionState(ctx context.Context, tb testing.TB, kmsClient *
}
}

func testIsIntegration(tb testing.TB) bool {
tb.Helper()
integVal := os.Getenv("TEST_JVS_INTEGRATION")
if integVal == "" {
return false
}
isInteg, err := strconv.ParseBool(integVal)
if err != nil {
tb.Fatalf("Unable to parse TEST_JVS_INTEGRATION flag %s: %s", integVal, err)
}
return isInteg
}

// Create an asymmetric signing key for use with integration tests.
func testCreateKey(ctx context.Context, tb testing.TB, kmsClient *kms.KeyManagementClient, keyRing, primaryKeyVersion string) string {
tb.Helper()
Expand Down

0 comments on commit 2ba9d16

Please sign in to comment.