nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: GoogleCloudPlatform/cloud-sql-proxy-operator
Pull request #454 (2023-10-03 20:52:36)

fix: Correct the name of the quit url envvar CSQL_PROXY_QUIT_URLS.
All proxy and operator-related environment variables need to use the prefix CSQL_PROXY_ for consistency. 

Related to #361 


Patch:
diff --git a/internal/workload/podspec_updates.go b/internal/workload/podspec_updates.go
index 16a6e5f..b8d6a23 100644
--- a/internal/workload/podspec_updates.go
+++ b/internal/workload/podspec_updates.go
@@ -408,7 +408,7 @@ func (s *updateState) addQuitEnvVar() {
 
 	s.addEnvVar(nil, managedEnvVar{
 		OperatorManagedValue: corev1.EnvVar{
-			Name:  "CSQL_QUIT_URLS",
+			Name:  "CSQL_PROXY_QUIT_URLS",
 			Value: v,
 		}})
 }


Test patch:
diff --git a/internal/testhelpers/resources.go b/internal/testhelpers/resources.go
index b4b18e1..3ff18b4 100644
--- a/internal/testhelpers/resources.go
+++ b/internal/testhelpers/resources.go
@@ -297,7 +297,7 @@ func BuildJob(name types.NamespacedName, appLabel string) *batchv1.Job {
 	job.Spec.Template.Spec.RestartPolicy = corev1.RestartPolicyNever
 	podCmd := fmt.Sprintf("echo Container 1 is Running \n"+
 		"sleep %d \n"+
-		"for url in $CSQL_QUIT_URLS ; do \n"+
+		"for url in $CSQL_PROXY_QUIT_URLS ; do \n"+
 		"   wget --post-data '' $url \n"+
 		"done", 30)
 	job.Spec.Template.Spec.Containers[0].Command = []string{"sh", "-c", podCmd}
@@ -331,7 +331,7 @@ func BuildCronJob(name types.NamespacedName, appLabel string) *batchv1.CronJob {
 	job.Spec.JobTemplate.Spec.Template.Spec.RestartPolicy = corev1.RestartPolicyNever
 	podCmd := fmt.Sprintf("echo Container 1 is Running \n"+
 		"sleep %d \n"+
-		"for url in $CSQL_QUIT_URLS ; do \n"+
+		"for url in $CSQL_PROXY_QUIT_URLS ; do \n"+
 		"   wget --post-data '' $url \n"+
 		"done", 30)
 	job.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Command = []string{"sh", "-c", podCmd}
diff --git a/internal/workload/podspec_updates_test.go b/internal/workload/podspec_updates_test.go
index 30a2e26..937332c 100644
--- a/internal/workload/podspec_updates_test.go
+++ b/internal/workload/podspec_updates_test.go
@@ -1015,7 +1015,7 @@ func TestQuitURLEnvVar(t *testing.T) {
 	}
 
 	// test that envvar was set
-	ev, err := findEnvVar(wl, "busybox", "CSQL_QUIT_URLS")
+	ev, err := findEnvVar(wl, "busybox", "CSQL_PROXY_QUIT_URLS")
 	if err != nil {
 		t.Fatal("can't find env var", err)
 	}
Repository: GoogleCloudPlatform/terraform-validator
Pull request #6 (2019-04-01 21:36:53)

Implement .Id() in TerraformResourceData
`.Id()` can be used to check whether a resource has already been created.

**Use Case**
This is useful for converting `google_project` into multiple CAI resources (Project & ProjectBillingInfo)... If the project already exists, its billing info can be looked up. Otherwise, the converter will need to perform a best-attempt building of billing account by referencing optional fields such as `google_project.billing_account`.


Patch:
diff --git a/converters/google/convert.go b/converters/google/convert.go
index 434b48b7..ee4130e9 100644
--- a/converters/google/convert.go
+++ b/converters/google/convert.go
@@ -33,6 +33,7 @@ var ErrDuplicateAsset = errors.New("duplicate asset")
 // TerraformResource represents the required methods needed to convert a terraform
 // resource into an Asset type.
 type TerraformResource interface {
+	Id() string
 	Kind() string
 	Get(string) interface{}
 	GetOk(string) (interface{}, bool)
@@ -47,7 +48,6 @@ type nonImplementedResourceData struct{}
 func (nonImplementedResourceData) HasChange(string) bool         { return false }
 func (nonImplementedResourceData) Set(string, interface{}) error { return nil }
 func (nonImplementedResourceData) SetId(string)                  {}
-func (nonImplementedResourceData) Id() string                    { return "" }
 
 // Asset contains the resource data and metadata in the same format as
 // Google CAI (Cloud Asset Inventory).
diff --git a/tfplan/fields.go b/tfplan/fields.go
index a0dc8ab8..1b286162 100644
--- a/tfplan/fields.go
+++ b/tfplan/fields.go
@@ -55,6 +55,7 @@ func newFieldGetter(sch map[string]*schema.Schema, state *terraform.InstanceStat
 	return &fieldGetter{
 		rdr:    rdr,
 		schema: sch,
+		state:  state,
 	}
 }
 
@@ -63,6 +64,15 @@ func newFieldGetter(sch map[string]*schema.Schema, state *terraform.InstanceStat
 type fieldGetter struct {
 	rdr    schema.FieldReader
 	schema map[string]*schema.Schema
+	state  *terraform.InstanceState
+}
+
+// Id returns the ID of the resource from state.
+func (g *fieldGetter) Id() string {
+	if g.state != nil {
+		return g.state.ID
+	}
+	return ""
 }
 
 // Get reads a single field by key.


Test patch:
diff --git a/tfplan/plan_test.go b/tfplan/plan_test.go
index 603e69d3..fb01b553 100644
--- a/tfplan/plan_test.go
+++ b/tfplan/plan_test.go
@@ -31,6 +31,7 @@ func TestComposeResources(t *testing.T) {
 					Resources: map[string]*terraform.ResourceState{
 						"google_test_resource.test": &terraform.ResourceState{
 							Primary: &terraform.InstanceState{
+								ID: "my-id",
 								Attributes: map[string]string{
 									"my_number": "42",
 								},
@@ -71,4 +72,5 @@ func TestComposeResources(t *testing.T) {
 	resources := ComposeResources(plan, schemas)
 	require.Len(t, resources, 1)
 	require.Equal(t, 42, resources[0].Get("my_number"))
+	require.Equal(t, "my-id", resources[0].Id())
 }
Repository: GoogleCloudPlatform/terraform-validator
Pull request #9 (2019-04-03 22:05:53)

Fix Sort(byName())
Sorting by name was actually just swapping names around. Added test case.


Patch:
diff --git a/converters/google/convert.go b/converters/google/convert.go
index 18c0105f..3b5a9efd 100644
--- a/converters/google/convert.go
+++ b/converters/google/convert.go
@@ -207,7 +207,7 @@ type byName []Asset
 
 func (s byName) Len() int           { return len(s) }
 func (s byName) Less(i, j int) bool { return s[i].Name < s[j].Name }
-func (s byName) Swap(i, j int)      { s[i].Name, s[j].Name = s[j].Name, s[i].Name }
+func (s byName) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
 
 // Assets lists all converted assets previously added by calls to AddResource.
 func (c *Converter) Assets() []Asset {


Test patch:
diff --git a/converters/google/convert_test.go b/converters/google/convert_test.go
index e31174c5..75da383e 100644
--- a/converters/google/convert_test.go
+++ b/converters/google/convert_test.go
@@ -15,8 +15,10 @@
 package google
 
 import (
+	"sort"
 	"testing"
 
+	"github.com/stretchr/testify/assert"
 	"google.golang.org/api/cloudresourcemanager/v1"
 )
 
@@ -60,3 +62,30 @@ func TestAncestryPath(t *testing.T) {
 		})
 	}
 }
+
+func TestSortByName(t *testing.T) {
+	cases := []struct {
+		name           string
+		unsorted       []Asset
+		expectedSorted []Asset
+	}{
+		{
+			name:           "Empty",
+			unsorted:       []Asset{},
+			expectedSorted: []Asset{},
+		},
+		{
+			name:           "BCAtoABC",
+			unsorted:       []Asset{{Name: "b", Type: "b-type"}, {Name: "c", Type: "c-type"}, {Name: "a", Type: "a-type"}},
+			expectedSorted: []Asset{{Name: "a", Type: "a-type"}, {Name: "b", Type: "b-type"}, {Name: "c", Type: "c-type"}},
+		},
+	}
+
+	for _, c := range cases {
+		t.Run(c.name, func(t *testing.T) {
+			assets := c.unsorted
+			sort.Sort(byName(assets))
+			assert.EqualValues(t, c.expectedSorted, assets)
+		})
+	}
+}
Repository: GoogleCloudPlatform/terraform-validator
Pull request #87 (2019-11-04 07:15:18)

ancestrymanager should take ancestry without the project
The logic on adding project name onto the ancestry value taken from command line flag is missing.

The original logic before ancestrymanager is introduced can be found here: https://github.com/GoogleCloudPlatform/terraform-validator/commit/a4c08567f77608a33d09ed1dee0b16600f3304b3#diff-747eeb1f3694357a501140221061b33eR114

```
if ancestry != "" {
	ancestryCache[project] = fmt.Sprintf("%s/project/%s", ancestry, project)
}
```


Patch:
diff --git a/ancestrymanager/ancestrymanager.go b/ancestrymanager/ancestrymanager.go
index 1431a095..d4270734 100644
--- a/ancestrymanager/ancestrymanager.go
+++ b/ancestrymanager/ancestrymanager.go
@@ -63,6 +63,9 @@ func (m *offlineAncestryManager) GetAncestry(project string) (string, error) {
 
 // New returns AncestryManager that can be used to fetch ancestry information for a project.
 func New(ctx context.Context, project, ancestry string, offline bool, opts ...option.ClientOption) (AncestryManager, error) {
+	if ancestry != "" {
+		ancestry = fmt.Sprintf("%s/project/%s", ancestry, project)
+	}
 	if offline {
 		return &offlineAncestryManager{project: project, ancestry: ancestry}, nil
 	}


Test patch:
diff --git a/ancestrymanager/ancestrymanager_test.go b/ancestrymanager/ancestrymanager_test.go
index 80d9b6a6..382c8ba5 100644
--- a/ancestrymanager/ancestrymanager_test.go
+++ b/ancestrymanager/ancestrymanager_test.go
@@ -55,7 +55,8 @@ func TestAncestryPath(t *testing.T) {
 func TestGetAncestry(t *testing.T) {
 	ctx := context.Background()
 	ownerProject := "foo"
-	ownerAncestry := "organization/qux/folder/bar/project/foo"
+	ownerAncestry := "organization/qux/folder/bar"
+	ownerAncestryPath := "organization/qux/folder/bar/project/foo"
 	anotherProject := "foo2"
 
 	// Setup a simple test server to mock the response of resource manager.
@@ -90,8 +91,8 @@ func TestGetAncestry(t *testing.T) {
 		wantError bool
 		want      string
 	}{
-		{name: "owner_project_online", target: amOnline, query: ownerProject, want: ownerAncestry},
-		{name: "owner_project_offline", target: amOffline, query: ownerProject, want: ownerAncestry},
+		{name: "owner_project_online", target: amOnline, query: ownerProject, want: ownerAncestryPath},
+		{name: "owner_project_offline", target: amOffline, query: ownerProject, want: ownerAncestryPath},
 		{name: "another_project_online", target: amOnline, query: anotherProject, want: "organization/qux2/folder/bar2/project/foo2"},
 		{name: "another_project_offline", target: amOffline, query: anotherProject, wantError: true},
 		{name: "missed_project_online", target: amOnline, query: "notexist", wantError: true},