From: Nico Cesar Date: Thu, 10 Dec 2020 19:04:55 +0000 (-0500) Subject: Changed the way we test mock X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/e6852ae4b41e66c661316e8d5e78fe87aa26d53d?ds=sidebyside Changed the way we test mock After a long discussion as a result of https://dev.arvados.org/issues/17014#note-18 Tom Clegg and Nico Cesar agreed that TestCreateRemoteContainerRequestCheckRuntimeToken was expecting the same sent json object in the mock the process is client -> zzzzz cluster -> zmock and we expect to have a random runtime_token in the zmock cluster Arvados-DCO-1.1-Signed-off-by: Nico Cesar --- diff --git a/lib/controller/federation_test.go b/lib/controller/federation_test.go index 94c0a0aac0..07ed3c8bc5 100644 --- a/lib/controller/federation_test.go +++ b/lib/controller/federation_test.go @@ -652,6 +652,11 @@ func (s *FederationSuite) TestCreateRemoteContainerRequestCheckRuntimeToken(c *c req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveTokenV2) req.Header.Set("Content-type", "application/json") + // We replace zhome with zzzzz values (RailsAPI, ClusterID, SystemRootToken) + // SystemRoot token is needed because we check the + // https://[RailsAPI]/arvados/v1/api_client_authorizations/current + // https://[RailsAPI]/arvados/v1/users/current and + // https://[RailsAPI]/auth/controller/callback arvadostest.SetServiceURL(&s.testHandler.Cluster.Services.RailsAPI, "https://"+os.Getenv("ARVADOS_TEST_API_HOST")) s.testHandler.Cluster.ClusterID = "zzzzz" s.testHandler.Cluster.SystemRootToken = arvadostest.SystemRootToken @@ -661,8 +666,19 @@ func (s *FederationSuite) TestCreateRemoteContainerRequestCheckRuntimeToken(c *c var cr struct { arvados.ContainerRequest `json:"container_request"` } - c.Check(json.NewDecoder(s.remoteMockRequests[0].Body).Decode(&cr), check.IsNil) + + // Body can be a json formated or something like: + // cluster_id=zmock&container_request=%7B%22command%22%3A%5B%22abc%22%5D%2C%22container_image%22%3A%22123%22%2C%22...7D + data, err := ioutil.ReadAll(s.remoteMockRequests[0].Body) + c.Check(err, check.IsNil) + // decodedValue is somethikng like: + // {"container_request":{"command":["abc"],"container_image":"123","name":"hello world",...} + decodedValue, err := url.QueryUnescape(string(data)) + c.Check(err, check.IsNil) + c.Check(json.Unmarshal([]byte(decodedValue), &cr), check.IsNil) + // let's make sure the Runtime token is there c.Check(strings.HasPrefix(cr.ContainerRequest.RuntimeToken, "v2/zzzzz-gj3su-"), check.Equals, true) + // the Runtimetoken should be a different one than than the Token we originally did the request with. c.Check(cr.ContainerRequest.RuntimeToken, check.Not(check.Equals), arvadostest.ActiveTokenV2) }