mirror of
https://github.com/restic/restic.git
synced 2025-10-27 03:49:13 +00:00
Update vendored library cloud.google.com/go
This commit is contained in:
92
vendor/cloud.google.com/go/profiler/profiler_test.go
generated
vendored
92
vendor/cloud.google.com/go/profiler/profiler_test.go
generated
vendored
@@ -345,35 +345,53 @@ func TestInitializeAgent(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
config Config
|
||||
enableMutex bool
|
||||
wantProfileTypes []pb.ProfileType
|
||||
wantDeploymentLabels map[string]string
|
||||
wantProfileLabels map[string]string
|
||||
}{
|
||||
{
|
||||
config: Config{ServiceVersion: testSvcVersion, zone: testZone},
|
||||
wantProfileTypes: []pb.ProfileType{pb.ProfileType_CPU, pb.ProfileType_HEAP, pb.ProfileType_THREADS},
|
||||
wantDeploymentLabels: map[string]string{zoneNameLabel: testZone, versionLabel: testSvcVersion},
|
||||
wantProfileLabels: map[string]string{},
|
||||
},
|
||||
{
|
||||
config: Config{zone: testZone},
|
||||
wantProfileTypes: []pb.ProfileType{pb.ProfileType_CPU, pb.ProfileType_HEAP, pb.ProfileType_THREADS},
|
||||
wantDeploymentLabels: map[string]string{zoneNameLabel: testZone},
|
||||
wantProfileLabels: map[string]string{},
|
||||
},
|
||||
{
|
||||
config: Config{ServiceVersion: testSvcVersion},
|
||||
wantProfileTypes: []pb.ProfileType{pb.ProfileType_CPU, pb.ProfileType_HEAP, pb.ProfileType_THREADS},
|
||||
wantDeploymentLabels: map[string]string{versionLabel: testSvcVersion},
|
||||
wantProfileLabels: map[string]string{},
|
||||
},
|
||||
{
|
||||
config: Config{instance: testInstance},
|
||||
wantProfileTypes: []pb.ProfileType{pb.ProfileType_CPU, pb.ProfileType_HEAP, pb.ProfileType_THREADS},
|
||||
wantDeploymentLabels: map[string]string{},
|
||||
wantProfileLabels: map[string]string{instanceLabel: testInstance},
|
||||
},
|
||||
{
|
||||
config: Config{instance: testInstance},
|
||||
enableMutex: true,
|
||||
wantProfileTypes: []pb.ProfileType{pb.ProfileType_CPU, pb.ProfileType_HEAP, pb.ProfileType_THREADS, pb.ProfileType_CONTENTION},
|
||||
wantDeploymentLabels: map[string]string{},
|
||||
wantProfileLabels: map[string]string{instanceLabel: testInstance},
|
||||
},
|
||||
{
|
||||
config: Config{NoHeapProfiling: true},
|
||||
wantProfileTypes: []pb.ProfileType{pb.ProfileType_CPU, pb.ProfileType_THREADS},
|
||||
wantDeploymentLabels: map[string]string{},
|
||||
wantProfileLabels: map[string]string{},
|
||||
},
|
||||
{
|
||||
config: Config{NoHeapProfiling: true, NoGoroutineProfiling: true},
|
||||
wantProfileTypes: []pb.ProfileType{pb.ProfileType_CPU},
|
||||
wantDeploymentLabels: map[string]string{},
|
||||
wantProfileLabels: map[string]string{},
|
||||
},
|
||||
} {
|
||||
|
||||
config = tt.config
|
||||
@@ -390,24 +408,17 @@ func TestInitializeAgent(t *testing.T) {
|
||||
if !testutil.Equal(a.deployment, wantDeployment) {
|
||||
t.Errorf("initializeAgent() got deployment: %v, want %v", a.deployment, wantDeployment)
|
||||
}
|
||||
|
||||
if !testutil.Equal(a.profileLabels, tt.wantProfileLabels) {
|
||||
t.Errorf("initializeAgent() got profile labels: %v, want %v", a.profileLabels, tt.wantProfileLabels)
|
||||
}
|
||||
|
||||
wantProfileTypes := []pb.ProfileType{pb.ProfileType_CPU, pb.ProfileType_HEAP, pb.ProfileType_THREADS}
|
||||
if tt.enableMutex {
|
||||
wantProfileTypes = append(wantProfileTypes, pb.ProfileType_CONTENTION)
|
||||
if !testutil.Equal(a.profileTypes, tt.wantProfileTypes) {
|
||||
t.Errorf("initializeAgent() got profile types: %v, want %v", a.profileTypes, tt.wantProfileTypes)
|
||||
}
|
||||
if !testutil.Equal(a.profileTypes, wantProfileTypes) {
|
||||
t.Errorf("initializeAgent() got profile types: %v, want %v", a.profileTypes, wantProfileTypes)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func TestInitializeConfig(t *testing.T) {
|
||||
oldConfig, oldService, oldVersion, oldGetProjectID, oldGetInstanceName, oldGetZone, oldOnGCE := config, os.Getenv("GAE_SERVICE"), os.Getenv("GAE_VERSION"), getProjectID, getInstanceName, getZone, onGCE
|
||||
oldConfig, oldService, oldVersion, oldEnvProjectID, oldGetProjectID, oldGetInstanceName, oldGetZone, oldOnGCE := config, os.Getenv("GAE_SERVICE"), os.Getenv("GAE_VERSION"), os.Getenv("GOOGLE_CLOUD_PROJECT"), getProjectID, getInstanceName, getZone, onGCE
|
||||
defer func() {
|
||||
config, getProjectID, getInstanceName, getZone, onGCE = oldConfig, oldGetProjectID, oldGetInstanceName, oldGetZone, oldOnGCE
|
||||
if err := os.Setenv("GAE_SERVICE", oldService); err != nil {
|
||||
@@ -416,88 +427,135 @@ func TestInitializeConfig(t *testing.T) {
|
||||
if err := os.Setenv("GAE_VERSION", oldVersion); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Setenv("GOOGLE_CLOUD_PROJECT", oldEnvProjectID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
testGAEService := "test-gae-service"
|
||||
testGAEVersion := "test-gae-version"
|
||||
testGCEProjectID := "test-gce-project-id"
|
||||
const (
|
||||
testGAEService = "test-gae-service"
|
||||
testGAEVersion = "test-gae-version"
|
||||
testGCEProjectID = "test-gce-project-id"
|
||||
testEnvProjectID = "test-env-project-id"
|
||||
)
|
||||
for _, tt := range []struct {
|
||||
desc string
|
||||
config Config
|
||||
wantConfig Config
|
||||
wantErrorString string
|
||||
onGAE bool
|
||||
onGCE bool
|
||||
envProjectID bool
|
||||
}{
|
||||
{
|
||||
"accepts service name",
|
||||
Config{Service: testService},
|
||||
Config{Target: testService, ProjectID: testGCEProjectID, zone: testZone, instance: testInstance},
|
||||
"",
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"accepts target name",
|
||||
Config{Target: testTarget},
|
||||
Config{Target: testTarget, ProjectID: testGCEProjectID, zone: testZone, instance: testInstance},
|
||||
"",
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"env project overrides GCE project",
|
||||
Config{Service: testService},
|
||||
Config{Target: testService, ProjectID: testEnvProjectID, zone: testZone, instance: testInstance},
|
||||
"",
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"requires service name",
|
||||
Config{},
|
||||
Config{},
|
||||
"service name must be specified in the configuration",
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"accepts service name from config and service version from GAE",
|
||||
Config{Service: testService},
|
||||
Config{Target: testService, ServiceVersion: testGAEVersion, ProjectID: testGCEProjectID, zone: testZone, instance: testInstance},
|
||||
"",
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"accepts target name from config and service version from GAE",
|
||||
Config{Target: testTarget},
|
||||
Config{Target: testTarget, ServiceVersion: testGAEVersion, ProjectID: testGCEProjectID, zone: testZone, instance: testInstance},
|
||||
"",
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"reads both service name and version from GAE env vars",
|
||||
Config{},
|
||||
Config{Target: testGAEService, ServiceVersion: testGAEVersion, ProjectID: testGCEProjectID, zone: testZone, instance: testInstance},
|
||||
"",
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"accepts service version from config",
|
||||
Config{Service: testService, ServiceVersion: testSvcVersion},
|
||||
Config{Target: testService, ServiceVersion: testSvcVersion, ProjectID: testGCEProjectID, zone: testZone, instance: testInstance},
|
||||
"",
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"configured version has priority over GAE-provided version",
|
||||
Config{Service: testService, ServiceVersion: testSvcVersion},
|
||||
Config{Target: testService, ServiceVersion: testSvcVersion, ProjectID: testGCEProjectID, zone: testZone, instance: testInstance},
|
||||
"",
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"configured project ID has priority over metadata-provided project ID",
|
||||
Config{Service: testService, ProjectID: testProjectID},
|
||||
Config{Target: testService, ProjectID: testProjectID, zone: testZone, instance: testInstance},
|
||||
"",
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"configured project ID has priority over environment project ID",
|
||||
Config{Service: testService, ProjectID: testProjectID},
|
||||
Config{Target: testService, ProjectID: testProjectID},
|
||||
"",
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"requires project ID if not on GCE",
|
||||
Config{Service: testService},
|
||||
Config{Target: testService},
|
||||
"project ID must be specified in the configuration if running outside of GCP",
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
},
|
||||
} {
|
||||
t.Logf("Running test: %s", tt.desc)
|
||||
envService, envVersion := "", ""
|
||||
if tt.onGAE {
|
||||
envService, envVersion = testGAEService, testGAEVersion
|
||||
@@ -519,6 +577,13 @@ func TestInitializeConfig(t *testing.T) {
|
||||
getZone = func() (string, error) { return "", fmt.Errorf("test get zone error") }
|
||||
getInstanceName = func() (string, error) { return "", fmt.Errorf("test get instance error") }
|
||||
}
|
||||
envProjectID := ""
|
||||
if tt.envProjectID {
|
||||
envProjectID = testEnvProjectID
|
||||
}
|
||||
if err := os.Setenv("GOOGLE_CLOUD_PROJECT", envProjectID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
errorString := ""
|
||||
if err := initializeConfig(tt.config); err != nil {
|
||||
@@ -528,7 +593,6 @@ func TestInitializeConfig(t *testing.T) {
|
||||
if !strings.Contains(errorString, tt.wantErrorString) {
|
||||
t.Errorf("initializeConfig(%v) got error: %v, want contain %v", tt.config, errorString, tt.wantErrorString)
|
||||
}
|
||||
|
||||
if tt.wantErrorString == "" {
|
||||
tt.wantConfig.APIAddr = apiAddress
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user