Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Commit

Permalink
Fix eventarc test template (#6066) (#723)
Browse files Browse the repository at this point in the history
* Fix eventarc test template

* Update steps

* Final one

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored May 25, 2022
1 parent 408cb47 commit 8784c53
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 231 deletions.
14 changes: 12 additions & 2 deletions converters/google/resources/getconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ package google

import (
"context"
"fmt"
"os"

"github.com/pkg/errors"

"github.com/GoogleCloudPlatform/terraform-validator/version"
)

// Return the value of the private userAgent field
func (c *Config) UserAgent() string {
return c.userAgent
}

func GetConfig(ctx context.Context, project string, offline bool, userAgent string) (*Config, error) {
func GetConfig(ctx context.Context, project string, offline bool) (*Config, error) {
cfg := &Config{
Project: project,
userAgent: userAgent,
userAgent: fmt.Sprintf("config-validator-tf/%s", version.BuildVersion()),
}

// Search for default credentials
Expand Down Expand Up @@ -44,6 +48,12 @@ func GetConfig(ctx context.Context, project string, offline bool, userAgent stri
"CLOUDSDK_COMPUTE_REGION",
})

// opt in extension for adding to the User-Agent header
if ext := os.Getenv("GOOGLE_TERRAFORM_VALIDATOR_USERAGENT_EXTENSION"); ext != "" {
ua := cfg.userAgent
cfg.userAgent = fmt.Sprintf("%s %s", ua, ext)
}

if !offline {
ConfigureBasePaths(cfg)
if err := cfg.LoadAndValidate(ctx); err != nil {
Expand Down
38 changes: 8 additions & 30 deletions converters/google/resources/getconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ func TestGetConfigExtractsEnvVars(t *testing.T) {
expected: "whatever",
getConfigValue: getRegionValue,
},
{
name: "GOOGLE_TERRAFORM_VALIDATOR_USERAGENT_EXTENSION",
envKey: "GOOGLE_TERRAFORM_VALIDATOR_USERAGENT_EXTENSION",
envValue: "whatever",
expected: "config-validator-tf/dev whatever",
getConfigValue: getUserAgent,
},
}

for _, c := range cases {
Expand All @@ -126,7 +133,7 @@ func TestGetConfigExtractsEnvVars(t *testing.T) {
t.Fatalf("error setting env var %s=%s: %s", c.envKey, c.envValue, err)
}

cfg, err := GetConfig(ctx, "project", offline, "")
cfg, err := GetConfig(ctx, "project", offline)
if err != nil {
t.Fatalf("error building converter: %s", err)
}
Expand All @@ -147,32 +154,3 @@ func TestGetConfigExtractsEnvVars(t *testing.T) {
})
}
}

func TestGetConfigUserAgent(t *testing.T) {
ctx := context.Background()
offline := true
cases := []struct {
userAgent string
expected string
}{
{
userAgent: "",
expected: "",
},
{
userAgent: "whatever",
expected: "whatever",
},
}

for _, c := range cases {
t.Run(c.userAgent, func(t *testing.T) {
cfg, err := GetConfig(ctx, "project", offline, c.userAgent)
if err != nil {
t.Fatalf("error building converter: %s", err)
}

assert.Equal(t, c.expected, getUserAgent(cfg))
})
}
}
2 changes: 1 addition & 1 deletion test/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestReadPlannedAssetsCoverage(t *testing.T) {
ancestryCache := map[string]string{
data.Provider["project"]: data.Ancestry,
}
got, err := tfgcv.ReadPlannedAssets(ctx, planfile, data.Provider["project"], ancestryCache, true, false, zaptest.NewLogger(t), "")
got, err := tfgcv.ReadPlannedAssets(ctx, planfile, data.Provider["project"], ancestryCache, true, false, zaptest.NewLogger(t))
if err != nil {
t.Fatalf("ReadPlannedAssets(%s, %s, %s, %t): %v", planfile, data.Provider["project"], ancestryCache, true, err)
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 8784c53

Please sign in to comment.