-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from grycap/tests
Improve test
- Loading branch information
Showing
2 changed files
with
84 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ func TestMakeCreateHandler(t *testing.T) { | |
// Create a fake MinIO server | ||
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, hreq *http.Request) { | ||
|
||
if hreq.URL.Path != "/test" && hreq.URL.Path != "/test/input/" && hreq.URL.Path != "/test/output/" && hreq.URL.Path != "/test/mount/" && !strings.HasPrefix(hreq.URL.Path, "/minio/admin/v3/") { | ||
if hreq.URL.Path != "/test" && hreq.URL.Path != "/test/input/" && hreq.URL.Path != "/test/output/" && hreq.URL.Path != "/test/mount/" && !strings.HasPrefix(hreq.URL.Path, "/minio/admin/v3/") && !strings.HasPrefix(hreq.URL.Path, "/test-somelongui") { | ||
t.Errorf("Unexpected path in request, got: %s", hreq.URL.Path) | ||
} | ||
|
||
|
@@ -68,56 +68,67 @@ func TestMakeCreateHandler(t *testing.T) { | |
}) | ||
r.POST("/system/services", MakeCreateHandler(&cfg, back)) | ||
|
||
w := httptest.NewRecorder() | ||
body := strings.NewReader(` | ||
{ | ||
"name": "cowsay", | ||
"cluster_id": "oscar", | ||
"memory": "1Gi", | ||
"cpu": "1.0", | ||
"log_level": "CRITICAL", | ||
"image": "ghcr.io/grycap/cowsay", | ||
"alpine": false, | ||
"script": "test", | ||
"input": [ | ||
{ | ||
"storage_provider": "minio", | ||
"path": "/test/input/" | ||
} | ||
], | ||
"output": [ | ||
{ | ||
"storage_provider": "minio", | ||
"path": "/test/output" | ||
} | ||
], | ||
"mount": { | ||
"storage_provider": "minio", | ||
"path": "/test/mount" | ||
}, | ||
"storage_providers": { | ||
"webdav": { | ||
"id": { | ||
"hostname": "` + server.URL + `", | ||
"login": "user", | ||
"password": "pass" | ||
} | ||
} | ||
}, | ||
"isolation_level": "SERVICE", | ||
"bucket_list": [], | ||
"allowed_users": ["[email protected]", "[email protected]"] | ||
} | ||
`) | ||
scenarios := []struct { | ||
name string | ||
isolationLevel string | ||
}{ | ||
{"Service", "SERVICE"}, | ||
{"User", "USER"}, | ||
} | ||
|
||
req, _ := http.NewRequest("POST", "/system/services", body) | ||
req.Header.Add("Authorization", "Bearer token") | ||
r.ServeHTTP(w, req) | ||
for _, s := range scenarios { | ||
t.Run(s.name, func(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
body := strings.NewReader(` | ||
{ | ||
"name": "cowsay", | ||
"cluster_id": "oscar", | ||
"memory": "1Gi", | ||
"cpu": "1.0", | ||
"log_level": "CRITICAL", | ||
"image": "ghcr.io/grycap/cowsay", | ||
"alpine": false, | ||
"script": "test", | ||
"input": [ | ||
{ | ||
"storage_provider": "minio", | ||
"path": "/test/input/" | ||
} | ||
], | ||
"output": [ | ||
{ | ||
"storage_provider": "minio", | ||
"path": "/test/output" | ||
} | ||
], | ||
"mount": { | ||
"storage_provider": "minio", | ||
"path": "/test/mount" | ||
}, | ||
"storage_providers": { | ||
"webdav": { | ||
"id": { | ||
"hostname": "` + server.URL + `", | ||
"login": "user", | ||
"password": "pass" | ||
} | ||
} | ||
}, | ||
"isolation_level": "` + s.isolationLevel + `", | ||
"bucket_list": [], | ||
"allowed_users": ["[email protected]", "[email protected]"] | ||
}`) | ||
|
||
req, _ := http.NewRequest("POST", "/system/services", body) | ||
req.Header.Add("Authorization", "Bearer token") | ||
r.ServeHTTP(w, req) | ||
|
||
if w.Code != http.StatusCreated { | ||
t.Errorf("expecting code %d, got %d", http.StatusCreated, w.Code) | ||
} | ||
}) | ||
} | ||
|
||
// Close the fake MinIO server | ||
defer server.Close() | ||
|
||
if w.Code != http.StatusCreated { | ||
t.Errorf("expecting code %d, got %d", http.StatusCreated, w.Code) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -20,6 +20,28 @@ func TestMakeDeleteHandler(t *testing.T) { | |
if hreq.URL.Path != "/input" && hreq.URL.Path != "/output" && !strings.HasPrefix(hreq.URL.Path, "/minio/admin/v3/") { | ||
t.Errorf("Unexpected path in request, got: %s", hreq.URL.Path) | ||
} | ||
if hreq.URL.Path == "/minio/admin/v3/info" { | ||
rw.WriteHeader(http.StatusOK) | ||
rw.Write([]byte(`{"Mode": "local", "Region": "us-east-1"}`)) | ||
} else if hreq.URL.Path == "/minio/admin/v3/info-canned-policy" { | ||
rw.WriteHeader(http.StatusOK) | ||
rw.Write([]byte(`{ | ||
"PolicyName": "input", | ||
"Policy": { | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": ["s3:GetObject"], | ||
"Resource": ["arn:aws:s3:::example-bucket/*"] | ||
} | ||
] | ||
} | ||
}`)) | ||
} else { | ||
rw.WriteHeader(http.StatusOK) | ||
rw.Write([]byte(`{"status": "success"}`)) | ||
} | ||
})) | ||
|
||
// and set the MinIO endpoint to the fake server | ||
|
@@ -41,6 +63,8 @@ func TestMakeDeleteHandler(t *testing.T) { | |
Output: []types.StorageIOConfig{ | ||
{Provider: "minio." + types.DefaultProvider, Path: "/output"}, | ||
}, | ||
IsolationLevel: "USER", | ||
AllowedUsers: []string{"[email protected]"}, | ||
StorageProviders: &types.StorageProviders{ | ||
MinIO: map[string]*types.MinIOProvider{types.DefaultProvider: { | ||
Region: "us-east-1", | ||
|