24a25 > "github.com/google/uuid" 462a464,487 > } > > // generate and activate an ssh key for the user attached to the APITestContext > // TODO: pick a better name; golang doesn't do method overriding. > func withCtxKeyFile(t *testing.T, ctx APITestContext, callback func()) { > // we need to have write:public_key to do this step > // the easiest way is to create a throwaway ctx that is identical but only has that permission > ctxKeyWriter := ctx > ctxKeyWriter.Token = getTokenForLoggedInUser(t, ctx.Session, auth.AccessTokenScopeWriteUser) > > keyName := "One of " + ctx.Username + "'s keys: #" + uuid.New().String() > withKeyFile(t, keyName, func(keyFile string) { > var key api.PublicKey > > doAPICreateUserKey(ctxKeyWriter, keyName, keyFile, > func(t *testing.T, _key api.PublicKey) { > // save the key ID so we can delete it at the end > key = _key > })(t) > > defer doAPIDeleteUserKey(ctxKeyWriter, key.ID)(t) > > callback() > })