nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: k1LoW/tbls
Pull request #466 (2023-04-07 07:15:45)

Add a NamingStrategy to map Post.user_id → User.user_id style detected relation
I encountered a niche case where primary keys are named `tablename_id`, and wanted tbls to be able to detect the relation.

This PR adds:
* `identical` and `identicalSingularTableName` NamingStrategy which detects `user_id` → `user_id` relations
* checks to prevent making relation to the table itself

My concern about this is that other NamingStrategy's can be introduced and the combination will blow up. If that's the case, separating the NamingStrategy config into two parts and letting ParentTableNamer and ParentColumnNamer be specified separately might be good maybe??


Patch:
diff --git a/config/config.go b/config/config.go
index f004bcc..705a8b1 100644
--- a/config/config.go
+++ b/config/config.go
@@ -723,6 +723,7 @@ func mergeDetectedRelations(s *schema.Schema, strategy *NamingStrategy) {
 	var (
 		err          error
 		parentColumn *schema.Column
+		parentTable  *schema.Table
 	)
 
 	for _, t := range s.Tables {
@@ -733,9 +734,16 @@ func mergeDetectedRelations(s *schema.Schema, strategy *NamingStrategy) {
 				Table:   t,
 			}
 
-			if relation.ParentTable, err = s.FindTableByName(strategy.ParentTableName(c.Name)); err != nil {
+			if parentTable, err = s.FindTableByName(strategy.ParentTableName(c.Name)); err != nil {
 				continue
 			}
+
+			if parentTable == t {
+				continue
+			}
+
+			relation.ParentTable = parentTable
+
 			if parentColumn, err = relation.ParentTable.FindColumnByName(strategy.ParentColumnName(c.Name)); err != nil {
 				continue
 			}
diff --git a/config/naming.go b/config/naming.go
index d69fefc..86eb7d7 100644
--- a/config/naming.go
+++ b/config/naming.go
@@ -36,6 +36,18 @@ func SelectNamingStrategy(name string) (*NamingStrategy, error) {
 			ParentColumn: singularTableParentColumnNamer,
 		}, nil
 
+	case "identical":
+		return &NamingStrategy{
+			ParentTable:  defaultParentTableNamer,
+			ParentColumn: identicalParentColumnNamer,
+		}, nil
+
+	case "identicalSingularTableName":
+		return &NamingStrategy{
+			ParentTable:  singularTableParentTableNamer,
+			ParentColumn: identicalParentColumnNamer,
+		}, nil
+
 	default:
 		return nil, fmt.Errorf("Naming strategy does not exist. strategy: %s\n", name)
 	}
@@ -76,3 +88,7 @@ func singularTableParentTableNamer(name string) string {
 func singularTableParentColumnNamer(name string) string {
 	return "id"
 }
+
+func identicalParentColumnNamer(name string) string {
+	return name
+}


Test patch:
diff --git a/config/naming_test.go b/config/naming_test.go
index 5ecf2bf..41f6774 100644
--- a/config/naming_test.go
+++ b/config/naming_test.go
@@ -36,3 +36,21 @@ func TestSingularTableParentColumnNamer(t *testing.T) {
 		}
 	}
 }
+
+func TestIdenticalParentColumnNamer(t *testing.T) {
+	tests := []struct {
+		name string
+		want string
+	}{
+		// normal
+		{"user_id", "user_id"},
+	}
+
+	for _, tt := range tests {
+		got := identicalParentColumnNamer(tt.name)
+
+		if got != tt.want {
+			t.Errorf("name %v\ngot %v\nwant %v", tt.name, got, tt.want)
+		}
+	}
+}
Repository: k1LoW/tbls
Pull request #470 (2023-04-10 00:58:01)

Support wildcards ( `*` ) in `--label` option


Patch:
diff --git a/config/config.go b/config/config.go
index 705a8b1..ae979e0 100644
--- a/config/config.go
+++ b/config/config.go
@@ -851,7 +851,7 @@ func detectPKFK(s *schema.Schema) error {
 func matchLabels(il []string, l schema.Labels) bool {
 	for _, ll := range l {
 		for _, ill := range il {
-			if ll.Name == ill {
+			if wildcard.MatchSimple(ill, ll.Name) {
 				return true
 			}
 		}


Test patch:
diff --git a/config/config_test.go b/config/config_test.go
index 65b9abc..a6c2930 100644
--- a/config/config_test.go
+++ b/config/config_test.go
@@ -217,6 +217,8 @@ func TestFilterTables(t *testing.T) {
 		{[]string{}, []string{"users"}, []string{"private"}, 0, 1, 0},
 		{[]string{}, []string{"user*"}, []string{"option"}, 0, 1, 0},
 		{[]string{"users"}, []string{}, []string{"private"}, 0, 2, 1},
+		{[]string{}, []string{}, []string{"p*"}, 0, 4, 3},
+		{[]string{"users"}, []string{}, []string{"pri*"}, 0, 2, 1},
 	}
 	for i, tt := range tests {
 		t.Run(fmt.Sprintf("%d.%v%v%v", i, tt.include, tt.exclude, tt.labels), func(t *testing.T) {
Repository: k1LoW/tbls
Pull request #666 (2025-03-04 16:14:07)

Add support for '.yaml' extension to default configuration
Many programs use YAML files for settings. They often use both `.yml` and `.yaml` file names.
To improve the user experience, I added support for `.yaml` extension as a default configuration file.

## Changes
- Added `.tbls.yaml` and `tbls.yaml` to the default configuration file search paths
- Changed the logic for checking multiple configuration files
- Modified to display all detected configuration file paths

## Testing
- Updated test cases for duplicate configuration file checks
- Added `.tbls.yaml` and `tbls.yaml` sample files as test data


Patch:
diff --git a/config/config.go b/config/config.go
index 464e43e..b27ac6e 100644
--- a/config/config.go
+++ b/config/config.go
@@ -20,7 +20,7 @@ import (
 
 const DefaultDocPath = "dbdoc"
 
-var DefaultConfigFilePaths = []string{".tbls.yml", "tbls.yml"}
+var DefaultConfigFilePaths = []string{".tbls.yml", "tbls.yml", ".tbls.yaml", "tbls.yaml"}
 
 // DefaultERFormat is the default ER diagram format
 const DefaultERFormat = "svg"
@@ -361,15 +361,21 @@ func (c *Config) LoadConfigFile(path string) (err error) {
 		err = errors.WithStack(err)
 	}()
 	if path == "" && os.Getenv("TBLS_DSN") == "" {
+		var paths []string
 		for _, p := range DefaultConfigFilePaths {
 			if f, err := os.Stat(filepath.Join(c.root, p)); err == nil && !f.IsDir() {
-				if path != "" {
-					return fmt.Errorf("duplicate config file [%s, %s]", path, p)
-				}
-				path = p
+				paths = append(paths, p)
 			}
 		}
+		if len(paths) == 0 {
+			return nil
+		} else if len(paths) > 1 {
+			return fmt.Errorf("duplicate config file [%s]", strings.Join(paths, ", "))
+		} else {
+			path = paths[0]
+		}
 	}
+
 	if path == "" {
 		return nil
 	}


Test patch:
diff --git a/config/config_test.go b/config/config_test.go
index e9efb2d..7714077 100644
--- a/config/config_test.go
+++ b/config/config_test.go
@@ -69,7 +69,7 @@ func TestDuplicateConfigFile(t *testing.T) {
 		root: filepath.Join(testdataDir(), "config"),
 	}
 	got := config.LoadConfigFile("")
-	want := "duplicate config file [.tbls.yml, tbls.yml]"
+	want := "duplicate config file [.tbls.yml, tbls.yml, .tbls.yaml, tbls.yaml]"
 	if fmt.Sprintf("%v", got) != want {
 		t.Errorf("got %v\nwant %v", got, want)
 	}
diff --git a/testdata/config/.tbls.yaml b/testdata/config/.tbls.yaml
new file mode 100644
index 0000000..ed97d53
--- /dev/null
+++ b/testdata/config/.tbls.yaml
@@ -0,0 +1,1 @@
+---
diff --git a/testdata/config/tbls.yaml b/testdata/config/tbls.yaml
new file mode 100644
index 0000000..ed97d53
--- /dev/null
+++ b/testdata/config/tbls.yaml
@@ -0,0 +1,1 @@
+---
Repository: hetznercloud/hcloud-go
Pull request #63 (2018-01-19 17:05:23)

Add Image property to server
Closes #63.


Patch:
diff --git a/hcloud/schema.go b/hcloud/schema.go
index 90f9bd4..39a69a9 100644
--- a/hcloud/schema.go
+++ b/hcloud/schema.go
@@ -119,6 +119,9 @@ func ServerFromSchema(s schema.Server) *Server {
 		Datacenter:      DatacenterFromSchema(s.Datacenter),
 		Locked:          s.Locked,
 	}
+	if s.Image != nil {
+		server.Image = ImageFromSchema(*s.Image)
+	}
 	if s.BackupWindow != nil {
 		server.BackupWindow = *s.BackupWindow
 	}
diff --git a/hcloud/schema/server.go b/hcloud/schema/server.go
index 55c60d9..3a59e22 100644
--- a/hcloud/schema/server.go
+++ b/hcloud/schema/server.go
@@ -18,6 +18,7 @@ type Server struct {
 	ISO             *ISO            `json:"iso"`
 	Locked          bool            `json:"locked"`
 	Datacenter      Datacenter      `json:"datacenter"`
+	Image           *Image          `json:"image"`
 }
 
 // ServerPublicNet defines the schema of a server's
diff --git a/hcloud/server.go b/hcloud/server.go
index 1031f78..b5e3323 100644
--- a/hcloud/server.go
+++ b/hcloud/server.go
@@ -30,6 +30,7 @@ type Server struct {
 	RescueEnabled   bool
 	Locked          bool
 	ISO             *ISO
+	Image           *Image
 }
 
 // ServerStatus specifies a server's status.


Test patch:
diff --git a/hcloud/schema_test.go b/hcloud/schema_test.go
index 352cf00..d95c788 100644
--- a/hcloud/schema_test.go
+++ b/hcloud/schema_test.go
@@ -290,6 +290,24 @@ func TestServerFromSchema(t *testing.T) {
 		"included_traffic": 654321,
 		"backup_window": "22-02",
 		"rescue_enabled": true,
+		"image": {
+			"id": 4711,
+			"type": "system",
+			"status": "available",
+			"name": "ubuntu16.04-standard-x64",
+			"description": "Ubuntu 16.04 Standard 64 bit",
+			"image_size": 2.3,
+			"disk_size": 10,
+			"created": "2017-08-16T17:29:14+00:00",
+			"created_from": {
+				"id": 1,
+				"name": "Server"
+			},
+			"bound_to": 1,
+			"os_flavor": "ubuntu",
+			"os_version": "16.04",
+			"rapid_deploy": false
+		},
 		"iso": {
 			"id": 4711,
 			"name": "FreeBSD-11.0-RELEASE-amd64-dvd1",
@@ -352,6 +370,9 @@ func TestServerFromSchema(t *testing.T) {
 	if !server.RescueEnabled {
 		t.Errorf("unexpected rescue enabled state: %v", server.RescueEnabled)
 	}
+	if server.Image == nil || server.Image.ID != 4711 {
+		t.Errorf("unexpected Image: %v", server.Image)
+	}
 	if server.ISO == nil || server.ISO.ID != 4711 {
 		t.Errorf("unexpected ISO: %v", server.ISO)
 	}
Repository: hetznercloud/hcloud-go
Pull request #71 (2018-01-25 11:06:32)

Support passing user data on server creation #70


Patch:
diff --git a/CHANGES.md b/CHANGES.md
index bb5655e..83a3403 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -2,6 +2,7 @@
 
 ## master
 
+* Support passing user data on server creation ([issue #70](https://github.com/hetznercloud/hcloud-go/issues/70))
 * Fix leaking response body by not closing it ([issue #68](https://github.com/hetznercloud/hcloud-go/issues/68))
 
 ## v1.2.0
diff --git a/hcloud/schema/server.go b/hcloud/schema/server.go
index 3a59e22..92deb61 100644
--- a/hcloud/schema/server.go
+++ b/hcloud/schema/server.go
@@ -73,6 +73,7 @@ type ServerCreateRequest struct {
 	SSHKeys    []int       `json:"ssh_keys,omitempty"`
 	Location   string      `json:"location,omitempty"`
 	Datacenter string      `json:"datacenter,omitempty"`
+	UserData   string      `json:"user_data,omitempty"`
 }
 
 // ServerCreateResponse defines the schema of the response when
diff --git a/hcloud/server.go b/hcloud/server.go
index b5e3323..b173aec 100644
--- a/hcloud/server.go
+++ b/hcloud/server.go
@@ -191,6 +191,7 @@ type ServerCreateOpts struct {
 	SSHKeys    []*SSHKey
 	Location   *Location
 	Datacenter *Datacenter
+	UserData   string
 }
 
 // Validate checks if options are valid.
@@ -224,6 +225,7 @@ func (c *ServerClient) Create(ctx context.Context, opts ServerCreateOpts) (Serve
 	}
 
 	var reqBody schema.ServerCreateRequest
+	reqBody.UserData = opts.UserData
 	reqBody.Name = opts.Name
 	if opts.ServerType.ID != 0 {
 		reqBody.ServerType = opts.ServerType.ID


Test patch:
diff --git a/hcloud/server_test.go b/hcloud/server_test.go
index 59543ad..6f13073 100644
--- a/hcloud/server_test.go
+++ b/hcloud/server_test.go
@@ -429,6 +429,40 @@ func TestServersCreateWithLocationName(t *testing.T) {
 	}
 }
 
+func TestServersCreateWithUserData(t *testing.T) {
+	env := newTestEnv()
+	defer env.Teardown()
+
+	env.Mux.HandleFunc("/servers", func(w http.ResponseWriter, r *http.Request) {
+		var reqBody schema.ServerCreateRequest
+		if err := json.NewDecoder(r.Body).Decode(&reqBody); err != nil {
+			t.Fatal(err)
+		}
+		if reqBody.UserData != "---user data---" {
+			t.Errorf("unexpected userdata: %v", reqBody.UserData)
+		}
+		json.NewEncoder(w).Encode(schema.ServerCreateResponse{
+			Server: schema.Server{
+				ID: 1,
+			},
+		})
+	})
+
+	ctx := context.Background()
+	result, _, err := env.Client.Server.Create(ctx, ServerCreateOpts{
+		Name:       "test",
+		ServerType: &ServerType{ID: 1},
+		Image:      &Image{ID: 2},
+		UserData:   "---user data---",
+	})
+	if err != nil {
+		t.Fatal(err)
+	}
+	if result.Server == nil {
+		t.Fatal("no server")
+	}
+}
+
 func TestServersDelete(t *testing.T) {
 	env := newTestEnv()
 	defer env.Teardown()
Repository: hetznercloud/hcloud-go
Pull request #91 (2018-08-07 06:37:52)

Add CPU Type to Server Type 


Patch:
diff --git a/CHANGES.md b/CHANGES.md
index 1428732..6b476a4 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -4,6 +4,7 @@
 
 * Add `WatchProgressInterval()` to `ActionClient` which allows to specify the polling interval
   ([issue #90](https://github.com/hetznercloud/hcloud-go/issues/90))
+* Add `CPUType` field to `ServerType` ([issue #91](https://github.com/hetznercloud/hcloud-go/pull/91))
 
 ## v1.7.0
 
diff --git a/hcloud/schema.go b/hcloud/schema.go
index 8d98024..1c5fa39 100644
--- a/hcloud/schema.go
+++ b/hcloud/schema.go
@@ -192,6 +192,7 @@ func ServerTypeFromSchema(s schema.ServerType) *ServerType {
 		Memory:      s.Memory,
 		Disk:        s.Disk,
 		StorageType: StorageType(s.StorageType),
+		CPUType:     CPUType(s.CPUType),
 	}
 	for _, price := range s.Prices {
 		st.Pricings = append(st.Pricings, ServerTypeLocationPricing{
diff --git a/hcloud/schema/server_type.go b/hcloud/schema/server_type.go
index 272726f..5d4f10b 100644
--- a/hcloud/schema/server_type.go
+++ b/hcloud/schema/server_type.go
@@ -9,6 +9,7 @@ type ServerType struct {
 	Memory      float32                  `json:"memory"`
 	Disk        int                      `json:"disk"`
 	StorageType string                   `json:"storage_type"`
+	CPUType     string                   `json:"cpu_type"`
 	Prices      []PricingServerTypePrice `json:"prices"`
 }
 
diff --git a/hcloud/server_type.go b/hcloud/server_type.go
index 85e5612..8f4166c 100644
--- a/hcloud/server_type.go
+++ b/hcloud/server_type.go
@@ -18,6 +18,7 @@ type ServerType struct {
 	Memory      float32
 	Disk        int
 	StorageType StorageType
+	CPUType     CPUType
 	Pricings    []ServerTypeLocationPricing
 }
 
@@ -32,6 +33,17 @@ const (
 	StorageTypeCeph StorageType = "ceph"
 )
 
+// CPUType specifies the type of the CPU.
+type CPUType string
+
+const (
+	// CPUTypeShared is the type for shared CPU.
+	CPUTypeShared CPUType = "shared"
+
+	//CPUTypeDedicated is the type for dedicated CPU.
+	CPUTypeDedicated CPUType = "dedicated"
+)
+
 // ServerTypeClient is a client for the server types API.
 type ServerTypeClient struct {
 	client *Client


Test patch:
diff --git a/hcloud/schema_test.go b/hcloud/schema_test.go
index 65ec375..8ea1e50 100644
--- a/hcloud/schema_test.go
+++ b/hcloud/schema_test.go
@@ -534,6 +534,7 @@ func TestServerTypeFromSchema(t *testing.T) {
 		"memory": 1.0,
 		"disk": 20,
 		"storage_type": "local",
+		"cpu_type": "shared",
 		"prices": [
 			{
 				"location": "fsn1",
@@ -576,6 +577,9 @@ func TestServerTypeFromSchema(t *testing.T) {
 	if serverType.StorageType != StorageTypeLocal {
 		t.Errorf("unexpected storage type: %q", serverType.StorageType)
 	}
+	if serverType.CPUType != CPUTypeShared {
+		t.Errorf("unexpected cpu type: %q", serverType.CPUType)
+	}
 	if len(serverType.Pricings) != 1 {
 		t.Errorf("unexpected number of pricings: %d", len(serverType.Pricings))
 	} else {
Repository: hetznercloud/hcloud-go
Pull request #116 (2019-07-22 13:03:59)

Rename `MacAddress` to `MACAddress`


Patch:
diff --git a/CHANGES.md b/CHANGES.md
index e3d6b08..2ea14ed 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,5 +1,9 @@
 # Changes
 
+## master
+
+* Rename `MacAddress` to `MACAddress` on `ServerPrivateNet`
+
 ## v1.15.0
 
 * Add `MacAddress` field to `ServerPrivateNet`
diff --git a/hcloud/schema.go b/hcloud/schema.go
index e368709..2b69605 100644
--- a/hcloud/schema.go
+++ b/hcloud/schema.go
@@ -212,7 +212,7 @@ func ServerPrivateNetFromSchema(s schema.ServerPrivateNet) ServerPrivateNet {
 	n := ServerPrivateNet{
 		Network:    &Network{ID: s.Network},
 		IP:         net.ParseIP(s.IP),
-		MacAddress: s.MacAddress,
+		MACAddress: s.MACAddress,
 	}
 	for _, ip := range s.AliasIPs {
 		n.Aliases = append(n.Aliases, net.ParseIP(ip))
diff --git a/hcloud/schema/server.go b/hcloud/schema/server.go
index 99255ad..32cd00f 100644
--- a/hcloud/schema/server.go
+++ b/hcloud/schema/server.go
@@ -67,7 +67,7 @@ type ServerPrivateNet struct {
 	Network    int      `json:"network"`
 	IP         string   `json:"ip"`
 	AliasIPs   []string `json:"alias_ips"`
-	MacAddress string   `json:"mac_address"`
+	MACAddress string   `json:"mac_address"`
 }
 
 // ServerGetResponse defines the schema of the response when
diff --git a/hcloud/server.go b/hcloud/server.go
index 0b8ab5b..9653a25 100644
--- a/hcloud/server.go
+++ b/hcloud/server.go
@@ -101,7 +101,7 @@ type ServerPrivateNet struct {
 	Network    *Network
 	IP         net.IP
 	Aliases    []net.IP
-	MacAddress string
+	MACAddress string
 }
 
 // DNSPtrForIP returns the reverse dns pointer of the ip address.


Test patch:
diff --git a/hcloud/schema_test.go b/hcloud/schema_test.go
index 3792a3f..55e1582 100644
--- a/hcloud/schema_test.go
+++ b/hcloud/schema_test.go
@@ -661,8 +661,8 @@ func TestServerPrivateNetFromSchema(t *testing.T) {
 	if privateNet.Aliases[0].String() != "10.0.1.2" {
 		t.Errorf("unexpected alias IP: %v", privateNet.Aliases[0])
 	}
-	if privateNet.MacAddress != "86:00:ff:2a:7d:e1" {
-		t.Errorf("unexpected mac address: %v", privateNet.MacAddress)
+	if privateNet.MACAddress != "86:00:ff:2a:7d:e1" {
+		t.Errorf("unexpected mac address: %v", privateNet.MACAddress)
 	}
 }
Repository: hetznercloud/hcloud-go
Pull request #118 (2019-08-27 05:03:13)

The ip range on add subnet to network should be optional


Patch:
diff --git a/CHANGES.md b/CHANGES.md
index 0152524..4179eb5 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,5 +1,9 @@
 # Changes
 
+## master
+
+* Make IP range optional when adding a subnet to a network
+
 ## v1.15.1
 
 * Rename `MacAddress` to `MACAddress` on `ServerPrivateNet`
diff --git a/hcloud/network.go b/hcloud/network.go
index 1f703d5..db76bb0 100644
--- a/hcloud/network.go
+++ b/hcloud/network.go
@@ -304,9 +304,11 @@ type NetworkAddSubnetOpts struct {
 func (c *NetworkClient) AddSubnet(ctx context.Context, network *Network, opts NetworkAddSubnetOpts) (*Action, *Response, error) {
 	reqBody := schema.NetworkActionAddSubnetRequest{
 		Type:        string(opts.Subnet.Type),
-		IPRange:     opts.Subnet.IPRange.String(),
 		NetworkZone: string(opts.Subnet.NetworkZone),
 	}
+	if opts.Subnet.IPRange != nil {
+		reqBody.IPRange = opts.Subnet.IPRange.String()
+	}
 	reqBodyData, err := json.Marshal(reqBody)
 	if err != nil {
 		return nil, nil, err


Test patch:
diff --git a/hcloud/network_test.go b/hcloud/network_test.go
index 5519243..1da1a35 100644
--- a/hcloud/network_test.go
+++ b/hcloud/network_test.go
@@ -363,7 +363,7 @@ func TestNetworkClientChangeIPRange(t *testing.T) {
 }
 
 func TestNetworkClientAddSubnet(t *testing.T) {
-	t.Run("type server", func(t *testing.T) {
+	t.Run("type server with ip range", func(t *testing.T) {
 		env := newTestEnv()
 		defer env.Teardown()
 
@@ -405,6 +405,47 @@ func TestNetworkClientAddSubnet(t *testing.T) {
 			t.Errorf("unexpected action ID: %d", action.ID)
 		}
 	})
+
+	t.Run("type server without ip range", func(t *testing.T) {
+		env := newTestEnv()
+		defer env.Teardown()
+
+		env.Mux.HandleFunc("/networks/1/actions/add_subnet", func(w http.ResponseWriter, r *http.Request) {
+			var reqBody schema.NetworkActionAddSubnetRequest
+			if err := json.NewDecoder(r.Body).Decode(&reqBody); err != nil {
+				t.Fatal(err)
+			}
+			if reqBody.Type != "server" {
+				t.Errorf("unexpected Type: %v", reqBody.Type)
+			}
+			if reqBody.IPRange != "" {
+				t.Errorf("unexpected IPRange: %v", reqBody.IPRange)
+			}
+			if reqBody.NetworkZone != "eu-central" {
+				t.Errorf("unexpected NetworkZone: %v", reqBody.NetworkZone)
+			}
+			json.NewEncoder(w).Encode(schema.NetworkActionAddSubnetResponse{
+				Action: schema.Action{
+					ID: 1,
+				},
+			})
+		})
+
+		ctx := context.Background()
+		opts := NetworkAddSubnetOpts{
+			Subnet: NetworkSubnet{
+				Type:        NetworkSubnetTypeServer,
+				NetworkZone: NetworkZoneEUCentral,
+			},
+		}
+		action, _, err := env.Client.Network.AddSubnet(ctx, &Network{ID: 1}, opts)
+		if err != nil {
+			t.Fatal(err)
+		}
+		if action.ID != 1 {
+			t.Errorf("unexpected action ID: %d", action.ID)
+		}
+	})
 }
 
 func TestNetworkClientDeleteSubnet(t *testing.T) {
Repository: hetznercloud/hcloud-go
Pull request #131 (2020-04-28 15:26:18)

Add subnet type cloud

thcyron: Please add a changelog line.

Patch:
diff --git a/CHANGES.md b/CHANGES.md
index 44007d9..5bed830 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -3,6 +3,7 @@
 ## master
 
 * Add `Status` field to `Volume`
+* Add subnet type `cloud`
 
 ## v1.17.0
 
diff --git a/hcloud/network.go b/hcloud/network.go
index db76bb0..fb5e64b 100644
--- a/hcloud/network.go
+++ b/hcloud/network.go
@@ -27,6 +27,7 @@ type NetworkSubnetType string
 
 // List of available network subnet types.
 const (
+	NetworkSubnetTypeCloud  NetworkSubnetType = "cloud"
 	NetworkSubnetTypeServer NetworkSubnetType = "server"
 )
 


Test patch:
diff --git a/hcloud/network_test.go b/hcloud/network_test.go
index 1da1a35..3548dc3 100644
--- a/hcloud/network_test.go
+++ b/hcloud/network_test.go
@@ -372,7 +372,7 @@ func TestNetworkClientAddSubnet(t *testing.T) {
 			if err := json.NewDecoder(r.Body).Decode(&reqBody); err != nil {
 				t.Fatal(err)
 			}
-			if reqBody.Type != "server" {
+			if reqBody.Type != "cloud" {
 				t.Errorf("unexpected Type: %v", reqBody.Type)
 			}
 			if reqBody.IPRange != "10.0.1.0/24" {
@@ -392,7 +392,7 @@ func TestNetworkClientAddSubnet(t *testing.T) {
 		_, ipRange, _ := net.ParseCIDR("10.0.1.0/24")
 		opts := NetworkAddSubnetOpts{
 			Subnet: NetworkSubnet{
-				Type:        NetworkSubnetTypeServer,
+				Type:        NetworkSubnetTypeCloud,
 				IPRange:     ipRange,
 				NetworkZone: NetworkZoneEUCentral,
 			},
@@ -415,7 +415,7 @@ func TestNetworkClientAddSubnet(t *testing.T) {
 			if err := json.NewDecoder(r.Body).Decode(&reqBody); err != nil {
 				t.Fatal(err)
 			}
-			if reqBody.Type != "server" {
+			if reqBody.Type != "cloud" {
 				t.Errorf("unexpected Type: %v", reqBody.Type)
 			}
 			if reqBody.IPRange != "" {
@@ -434,7 +434,7 @@ func TestNetworkClientAddSubnet(t *testing.T) {
 		ctx := context.Background()
 		opts := NetworkAddSubnetOpts{
 			Subnet: NetworkSubnet{
-				Type:        NetworkSubnetTypeServer,
+				Type:        NetworkSubnetTypeCloud,
 				NetworkZone: NetworkZoneEUCentral,
 			},
 		}