X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/c2aceca339ec3a6f3d853865cebd0efe348ff518..365b9ca0ea4291d9864297593d185aeef66457ba:/lib/controller/handler_test.go diff --git a/lib/controller/handler_test.go b/lib/controller/handler_test.go index 9b71c349a4..f854079f97 100644 --- a/lib/controller/handler_test.go +++ b/lib/controller/handler_test.go @@ -88,6 +88,104 @@ func (s *HandlerSuite) TestConfigExport(c *check.C) { } } +func (s *HandlerSuite) TestVocabularyExport(c *check.C) { + voc := `{ + "strict_tags": false, + "tags": { + "IDTAGIMPORTANCE": { + "strict": false, + "labels": [{"label": "Importance"}], + "values": { + "HIGH": { + "labels": [{"label": "High"}] + }, + "LOW": { + "labels": [{"label": "Low"}] + } + } + } + } + }` + f, err := os.CreateTemp("", "test-vocabulary-*.json") + c.Assert(err, check.IsNil) + defer os.Remove(f.Name()) + _, err = f.WriteString(voc) + c.Assert(err, check.IsNil) + f.Close() + s.cluster.API.VocabularyPath = f.Name() + for _, method := range []string{"GET", "OPTIONS"} { + c.Log(c.TestName()+" ", method) + req := httptest.NewRequest(method, "/arvados/v1/vocabulary", nil) + resp := httptest.NewRecorder() + s.handler.ServeHTTP(resp, req) + c.Log(resp.Body.String()) + if !c.Check(resp.Code, check.Equals, http.StatusOK) { + continue + } + c.Check(resp.Header().Get("Access-Control-Allow-Origin"), check.Equals, `*`) + c.Check(resp.Header().Get("Access-Control-Allow-Methods"), check.Matches, `.*\bGET\b.*`) + c.Check(resp.Header().Get("Access-Control-Allow-Headers"), check.Matches, `.+`) + if method == "OPTIONS" { + c.Check(resp.Body.String(), check.HasLen, 0) + continue + } + var expectedVoc, receivedVoc *arvados.Vocabulary + err := json.Unmarshal([]byte(voc), &expectedVoc) + c.Check(err, check.IsNil) + err = json.Unmarshal(resp.Body.Bytes(), &receivedVoc) + c.Check(err, check.IsNil) + c.Check(receivedVoc, check.DeepEquals, expectedVoc) + } +} + +func (s *HandlerSuite) TestVocabularyFailedCheckStatus(c *check.C) { + voc := `{ + "strict_tags": false, + "tags": { + "IDTAGIMPORTANCE": { + "strict": true, + "labels": [{"label": "Importance"}], + "values": { + "HIGH": { + "labels": [{"label": "High"}] + }, + "LOW": { + "labels": [{"label": "Low"}] + } + } + } + } + }` + f, err := os.CreateTemp("", "test-vocabulary-*.json") + c.Assert(err, check.IsNil) + defer os.Remove(f.Name()) + _, err = f.WriteString(voc) + c.Assert(err, check.IsNil) + f.Close() + s.cluster.API.VocabularyPath = f.Name() + + req := httptest.NewRequest("POST", "/arvados/v1/collections", + strings.NewReader(`{ + "collection": { + "properties": { + "IDTAGIMPORTANCE": "Critical" + } + } + }`)) + req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken) + req.Header.Set("Content-type", "application/json") + + resp := httptest.NewRecorder() + s.handler.ServeHTTP(resp, req) + c.Log(resp.Body.String()) + c.Assert(resp.Code, check.Equals, http.StatusBadRequest) + var jresp httpserver.ErrorResponse + err = json.Unmarshal(resp.Body.Bytes(), &jresp) + c.Check(err, check.IsNil) + c.Assert(len(jresp.Errors), check.Equals, 1) + c.Check(jresp.Errors[0], check.Matches, `.*tag value.*is not valid for key.*`) +} + func (s *HandlerSuite) TestProxyDiscoveryDoc(c *check.C) { req := httptest.NewRequest("GET", "/discovery/v1/apis/arvados/v1/rest", nil) resp := httptest.NewRecorder() @@ -245,7 +343,7 @@ func (s *HandlerSuite) CheckObjectType(c *check.C, url string, token string, ski resp := httptest.NewRecorder() s.handler.ServeHTTP(resp, req) c.Assert(resp.Code, check.Equals, http.StatusOK, - check.Commentf("Wasn't able to get data from the controller at %q", url)) + check.Commentf("Wasn't able to get data from the controller at %q: %q", url, resp.Body.String())) err = json.Unmarshal(resp.Body.Bytes(), &proxied) c.Check(err, check.Equals, nil)