diff --git a/go.mod b/go.mod index 7e05a933..602a9d36 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/golang/protobuf v1.5.4 github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 - github.com/hetznercloud/hcloud-go/v2 v2.9.0 + github.com/hetznercloud/hcloud-go/v2 v2.10.1 github.com/kubernetes-csi/csi-test/v5 v5.2.0 github.com/prometheus/client_golang v1.19.1 github.com/stretchr/testify v1.9.0 @@ -37,9 +37,9 @@ require ( github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.48.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect - golang.org/x/net v0.25.0 // indirect - golang.org/x/text v0.15.0 // indirect - golang.org/x/tools v0.17.0 // indirect + golang.org/x/net v0.26.0 // indirect + golang.org/x/text v0.16.0 // indirect + golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect google.golang.org/protobuf v1.33.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index dbefb219..736c7670 100644 --- a/go.sum +++ b/go.sum @@ -54,6 +54,8 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92Bcuy github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/hetznercloud/hcloud-go/v2 v2.9.0 h1:s0N6R7Zoi2DPfMtUF5o9VeUBzTtHVY6MIkHOQnfu/AY= github.com/hetznercloud/hcloud-go/v2 v2.9.0/go.mod h1:qtW/TuU7Bs16ibXl/ktJarWqU2LwHr7eGlwoilHxtgg= +github.com/hetznercloud/hcloud-go/v2 v2.10.1 h1:MLfIJJvl7qo79Q+52YmrJ4BOTL5oICJWHjzb0sCtgQI= +github.com/hetznercloud/hcloud-go/v2 v2.10.1/go.mod h1:xQ+8KhIS62W0D78Dpi57jsufWh844gUw1az5OUvaeq8= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= @@ -124,6 +126,8 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= +golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -144,6 +148,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= @@ -155,6 +161,8 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc= golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/internal/api/volume_test.go b/internal/api/volume_test.go index 34d3b839..7e781627 100644 --- a/internal/api/volume_test.go +++ b/internal/api/volume_test.go @@ -10,18 +10,18 @@ import ( "github.com/stretchr/testify/assert" "github.com/hetznercloud/csi-driver/internal/csi" - "github.com/hetznercloud/csi-driver/internal/mocked" "github.com/hetznercloud/csi-driver/internal/volumes" "github.com/hetznercloud/hcloud-go/v2/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud/exp/mockutils" "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) var _ volumes.Service = (*VolumeService)(nil) -func makeTestVolumeService(t *testing.T, requests []mocked.Request) (*VolumeService, func()) { +func makeTestVolumeService(t *testing.T, requests []mockutils.Request) (*VolumeService, func()) { t.Helper() - testServer := httptest.NewServer(mocked.Handler(t, requests)) + testServer := httptest.NewServer(mockutils.Handler(t, requests)) testClient := hcloud.NewClient( hcloud.WithEndpoint(testServer.URL), @@ -37,7 +37,7 @@ func makeTestVolumeService(t *testing.T, requests []mocked.Request) (*VolumeServ func TestResize(t *testing.T) { t.Run("ErrVolumeSizeAlreadyReached", func(t *testing.T) { t.Run("happy with larger volume size", func(t *testing.T) { - volumeService, cleanup := makeTestVolumeService(t, []mocked.Request{ + volumeService, cleanup := makeTestVolumeService(t, []mockutils.Request{ { Method: "GET", Path: "/volumes/1", Status: 200, @@ -60,7 +60,7 @@ func TestResize(t *testing.T) { }) t.Run("with equal volume size", func(t *testing.T) { - volumeService, cleanup := makeTestVolumeService(t, []mocked.Request{ + volumeService, cleanup := makeTestVolumeService(t, []mockutils.Request{ { Method: "GET", Path: "/volumes/1", Status: 200, @@ -76,7 +76,7 @@ func TestResize(t *testing.T) { }) t.Run("with smaller volume size", func(t *testing.T) { - volumeService, cleanup := makeTestVolumeService(t, []mocked.Request{ + volumeService, cleanup := makeTestVolumeService(t, []mockutils.Request{ { Method: "GET", Path: "/volumes/1", Status: 200, diff --git a/internal/mocked/mocked.go b/internal/mocked/mocked.go deleted file mode 100644 index ff99fe89..00000000 --- a/internal/mocked/mocked.go +++ /dev/null @@ -1,54 +0,0 @@ -package mocked - -import ( - "encoding/json" - "net/http" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -type Request struct { - Method string - Path string - PathRegexp string - - Status int - Body string - JSON any -} - -func Handler(t *testing.T, requests []Request) http.HandlerFunc { - t.Helper() - - index := 0 - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if index >= len(requests) { - t.Fatalf("received unknown request %d", index) - } - - response := requests[index] - assert.Equal(t, response.Method, r.Method) - if response.PathRegexp != "" { - require.Regexp(t, response.Path, r.RequestURI, "request %d", index) - } else { - require.Equal(t, response.Path, r.RequestURI, "request %d", index) - } - - w.WriteHeader(response.Status) - w.Header().Set("Content-Type", "application/json") - if response.Body != "" { - _, err := w.Write([]byte(response.Body)) - if err != nil { - t.Fatal(err) - } - } else if response.JSON != nil { - if err := json.NewEncoder(w).Encode(response.JSON); err != nil { - t.Fatal(err) - } - } - - index++ - }) -}