MCPcopy
hub / github.com/minio/minio-go / TestUpdateObjectEncryptionSuccess

Function TestUpdateObjectEncryptionSuccess

api-update-object-encryption_test.go:84–162  ·  api-update-object-encryption_test.go::TestUpdateObjectEncryptionSuccess
(t *testing.T)

Source from the content-addressed store, hash-verified

82}
83
84func TestUpdateObjectEncryptionSuccess(t *testing.T) {
85 var capturedMethod string
86 var capturedPath string
87 var capturedQuery url.Values
88 var capturedBody []byte
89
90 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
91 capturedMethod = r.Method
92 capturedPath = r.URL.Path
93 capturedQuery = r.URL.Query()
94 capturedBody, _ = io.ReadAll(r.Body)
95 w.Header().Set("x-amz-version-id", "returned-version-id")
96 w.WriteHeader(http.StatusOK)
97 }))
98 defer ts.Close()
99
100 srv, err := url.Parse(ts.URL)
101 if err != nil {
102 t.Fatal(err)
103 }
104
105 client, err := New(srv.Host, &Options{
106 Creds: credentials.NewStaticV4("accesskey", "secretkey", ""),
107 Secure: false,
108 Region: "us-east-1",
109 })
110 if err != nil {
111 t.Fatalf("Failed to create client: %v", err)
112 }
113
114 opts := UpdateObjectEncryptionOptions{
115 KMSKeyArn: "my-minio-key",
116 BucketKeyEnabled: true,
117 VersionID: "test-version-id",
118 }
119
120 result, err := client.UpdateObjectEncryption(context.Background(), "mybucket", "myobject", opts)
121 if err != nil {
122 t.Fatalf("UpdateObjectEncryption failed: %v", err)
123 }
124
125 // Verify returned version ID from response header.
126 if result.VersionID != "returned-version-id" {
127 t.Fatalf("Expected VersionID 'returned-version-id', got %q", result.VersionID)
128 }
129
130 // Verify request method.
131 if capturedMethod != http.MethodPut {
132 t.Fatalf("Expected PUT, got %s", capturedMethod)
133 }
134
135 // Verify request path.
136 if capturedPath != "/mybucket/myobject" {
137 t.Fatalf("Expected path '/mybucket/myobject', got %q", capturedPath)
138 }
139
140 // Verify query parameters.
141 if _, ok := capturedQuery["encryption"]; !ok {

Callers

nothing calls this directly

Calls 7

NewStaticV4Function · 0.92
NewFunction · 0.70
SetMethod · 0.45
HeaderMethod · 0.45
CloseMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected