-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
TimHuynh
committed
Jan 8, 2025
1 parent
a4f29d0
commit 41df509
Showing
9 changed files
with
245 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package minio | ||
|
||
import ( | ||
"context" | ||
"github.com/gin-gonic/gin" | ||
api "github.com/go-vela/server/api/types" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
func TestMinioClient_Bucket_Delete_Success(t *testing.T) { | ||
// setup context | ||
gin.SetMode(gin.TestMode) | ||
|
||
resp := httptest.NewRecorder() | ||
_, engine := gin.CreateTestContext(resp) | ||
|
||
// setup mock server | ||
// mock create bucket call | ||
engine.PUT("/foo/", func(c *gin.Context) { | ||
c.Header("Content-Type", "application/json") | ||
c.Status(http.StatusOK) | ||
}) | ||
|
||
// mock delete bucket call | ||
engine.DELETE("/foo/", func(c *gin.Context) { | ||
c.Status(http.StatusOK) | ||
}) | ||
|
||
fake := httptest.NewServer(engine) | ||
defer fake.Close() | ||
ctx := context.TODO() | ||
b := new(api.Bucket) | ||
b.BucketName = "foo" | ||
client, _ := NewTest(fake.URL, "miniokey", "miniosecret", false) | ||
|
||
// create bucket | ||
err := client.CreateBucket(ctx, b) | ||
if err != nil { | ||
t.Errorf("CreateBucket returned err: %v", err) | ||
} | ||
|
||
// run test | ||
err = client.DeleteBucket(ctx, b) | ||
if resp.Code != http.StatusOK { | ||
t.Errorf("DeleteBucket returned %v, want %v", resp.Code, http.StatusOK) | ||
} | ||
|
||
// in Minio SDK, removeBucket returns status code 200 OK as error if a bucket is deleted successfully | ||
if err != nil && err.Error() != "200 OK" { | ||
t.Errorf("DeleteBucket returned err: %v", err) | ||
} | ||
|
||
} | ||
|
||
func TestMinioClient_Bucket_Delete_BucketNotFound(t *testing.T) { | ||
// setup context | ||
gin.SetMode(gin.TestMode) | ||
|
||
resp := httptest.NewRecorder() | ||
_, engine := gin.CreateTestContext(resp) | ||
|
||
// mock delete bucket call | ||
engine.DELETE("/foo/", func(c *gin.Context) { | ||
c.JSON(http.StatusOK, gin.H{"message": "The specified bucket does not exist"}) | ||
}) | ||
|
||
fake := httptest.NewServer(engine) | ||
defer fake.Close() | ||
ctx := context.TODO() | ||
b := new(api.Bucket) | ||
b.BucketName = "foo" | ||
client, _ := NewTest(fake.URL, "miniokey", "miniosecret", false) | ||
|
||
// run test | ||
err := client.DeleteBucket(ctx, b) | ||
if resp.Code != http.StatusOK { | ||
t.Errorf("DeleteBucket returned %v, want %v", resp.Code, http.StatusOK) | ||
} | ||
|
||
if err == nil { | ||
t.Errorf("DeleteBucket expected error, got nil") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.