From 2627653713e74dd2636e0f558bed08730bc5e10c Mon Sep 17 00:00:00 2001
From: Jody Sankey <jsankey@google.com>
Date: Mon, 13 May 2019 23:13:45 +0000
Subject: [PATCH] [identity] Move integration tests to //src/identity.

This are the final things in /garnet/bin/auth so we also delete it
(yey!).

AUTH-196 #comment

Change-Id: I0d73f3c20d4195de70799f28ce1183395baac4a6
---
 garnet/bin/auth/OWNERS                        |  3 --
 garnet/bin/auth/README.md                     |  4 --
 garnet/bin/auth/tests/BUILD.gn                | 11 -----
 garnet/packages/tests/BUILD.gn                | 12 -----
 src/identity/BUILD.gn                         |  2 +
 src/identity/bin/BUILD.gn                     |  2 +-
 .../account_manager_integration/BUILD.gn      | 14 +++++-
 .../account_manager_integration_lib_test.cmx  | 18 ++++----
 .../tests/account.rs                          |  2 +-
 .../account_manager_integration/tests/lib.rs  |  0
 .../tests/token_manager_integration/BUILD.gn  | 45 +++++++++----------
 .../dev_token_mgr_test.cc                     | 16 -------
 .../meta/token_manager_integration_test.cmx   | 12 +++++
 13 files changed, 58 insertions(+), 83 deletions(-)
 delete mode 100644 garnet/bin/auth/OWNERS
 delete mode 100644 garnet/bin/auth/README.md
 delete mode 100644 garnet/bin/auth/tests/BUILD.gn
 rename {garnet/bin/auth => src/identity}/tests/account_manager_integration/BUILD.gn (79%)
 rename {garnet/bin/auth => src/identity}/tests/account_manager_integration/meta/account_manager_integration_lib_test.cmx (100%)
 rename {garnet/bin/auth => src/identity}/tests/account_manager_integration/tests/account.rs (100%)
 rename {garnet/bin/auth => src/identity}/tests/account_manager_integration/tests/lib.rs (100%)
 rename {garnet/bin/auth => src/identity}/tests/token_manager_integration/BUILD.gn (63%)
 rename {garnet/bin/auth => src/identity}/tests/token_manager_integration/dev_token_mgr_test.cc (96%)
 create mode 100644 src/identity/tests/token_manager_integration/meta/token_manager_integration_test.cmx

diff --git a/garnet/bin/auth/OWNERS b/garnet/bin/auth/OWNERS
deleted file mode 100644
index 268f3df52b6..00000000000
--- a/garnet/bin/auth/OWNERS
+++ /dev/null
@@ -1,3 +0,0 @@
-jsankey@google.com
-ukode@google.com
-*
diff --git a/garnet/bin/auth/README.md b/garnet/bin/auth/README.md
deleted file mode 100644
index fed2a4ce488..00000000000
--- a/garnet/bin/auth/README.md
+++ /dev/null
@@ -1,4 +0,0 @@
-`/bin/auth` contains component binaries related to user identity and
-authentication. Please refer to the more detailed README.md file in each
-package for more information.
-
diff --git a/garnet/bin/auth/tests/BUILD.gn b/garnet/bin/auth/tests/BUILD.gn
deleted file mode 100644
index e192da30528..00000000000
--- a/garnet/bin/auth/tests/BUILD.gn
+++ /dev/null
@@ -1,11 +0,0 @@
-# Copyright 2019 The Fuchsia Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-group("tests") {
-  testonly = true
-  public_deps = [
-    "account_manager_integration",
-    "token_manager_integration",
-  ]
-}
diff --git a/garnet/packages/tests/BUILD.gn b/garnet/packages/tests/BUILD.gn
index c2d34d506cc..bc83c3a2c1d 100644
--- a/garnet/packages/tests/BUILD.gn
+++ b/garnet/packages/tests/BUILD.gn
@@ -201,17 +201,6 @@ group("feedback_agent") {
   ]
 }
 
-group("auth") {
-  testonly = true
-  public_deps = [
-    "//garnet/bin/auth/tests/account_manager_integration:account_manager_integration_test_pkg",
-    "//garnet/bin/auth/tests/token_manager_integration:token_manager_integration_tests",
-    "//garnet/packages/prod:auth",
-    "//src/identity/bin/dev_auth_provider",
-    "//src/identity/bin/dev_auth_provider_iotid",
-  ]
-}
-
 group("elflib") {
   testonly = true
   public_deps = [
@@ -315,7 +304,6 @@ group("all") {
     "//garnet/packages/tests:asio",
     "//garnet/packages/tests:async_promise",
     "//garnet/packages/tests:ath10k",
-    "//garnet/packages/tests:auth",
     "//garnet/packages/tests:banjo",
     "//garnet/packages/tests:bluetooth",
     "//garnet/packages/tests:boringssl",
diff --git a/src/identity/BUILD.gn b/src/identity/BUILD.gn
index 74b1828b71d..c345de58713 100644
--- a/src/identity/BUILD.gn
+++ b/src/identity/BUILD.gn
@@ -17,5 +17,7 @@ group("tests") {
   data_deps = [
     "bin:tests",
     "lib:tests",
+    "tests/account_manager_integration",
+    "tests/token_manager_integration",
   ]
 }
diff --git a/src/identity/bin/BUILD.gn b/src/identity/bin/BUILD.gn
index cf9cc6c5a57..b8e89ced2ef 100644
--- a/src/identity/bin/BUILD.gn
+++ b/src/identity/bin/BUILD.gn
@@ -29,7 +29,7 @@ test_package("identity_bin_unittests") {
   ]
 
   tests = [
-   {
+    {
       name = "account_handler_bin_test"
       environments = basic_envs
     },
diff --git a/garnet/bin/auth/tests/account_manager_integration/BUILD.gn b/src/identity/tests/account_manager_integration/BUILD.gn
similarity index 79%
rename from garnet/bin/auth/tests/account_manager_integration/BUILD.gn
rename to src/identity/tests/account_manager_integration/BUILD.gn
index 84dfbdda440..557b8e42873 100644
--- a/garnet/bin/auth/tests/account_manager_integration/BUILD.gn
+++ b/src/identity/tests/account_manager_integration/BUILD.gn
@@ -7,7 +7,17 @@ import("//build/rust/rustc_library.gni")
 import("//build/test/test_package.gni")
 import("//build/testing/environments.gni")
 
-rustc_library("account_manager_integration") {
+group("account_manager_integration") {
+  testonly = true
+  deps = [
+    ":account_manager_integration_test_pkg",
+    "//src/identity/bin/dev_auth_provider",
+    "//src/identity/bin/dev_auth_provider_iotid",
+  ]
+}
+
+rustc_library("lib") {
+  name = "account_manager_integration"
   edition = "2018"
   testonly = true
   with_unit_tests = true
@@ -32,7 +42,7 @@ rustc_library("account_manager_integration") {
 
 test_package("account_manager_integration_test_pkg") {
   deps = [
-    ":account_manager_integration",
+    ":lib",
   ]
 
   tests = [
diff --git a/garnet/bin/auth/tests/account_manager_integration/meta/account_manager_integration_lib_test.cmx b/src/identity/tests/account_manager_integration/meta/account_manager_integration_lib_test.cmx
similarity index 100%
rename from garnet/bin/auth/tests/account_manager_integration/meta/account_manager_integration_lib_test.cmx
rename to src/identity/tests/account_manager_integration/meta/account_manager_integration_lib_test.cmx
index 8b7f9e0344a..7064183d0ce 100644
--- a/garnet/bin/auth/tests/account_manager_integration/meta/account_manager_integration_lib_test.cmx
+++ b/src/identity/tests/account_manager_integration/meta/account_manager_integration_lib_test.cmx
@@ -1,13 +1,4 @@
 {
-    "program": {
-        "binary": "test/account_manager_integration_lib_test"
-    },
-    "sandbox": {
-        "services": [
-            "fuchsia.logger.LogSink",
-            "fuchsia.auth.account.AccountManager"
-        ]
-    },
     "facets": {
         "fuchsia.test": {
             "injected-services": {
@@ -17,5 +8,14 @@
                 ]
             }
         }
+    },
+    "program": {
+        "binary": "test/account_manager_integration_lib_test"
+    },
+    "sandbox": {
+        "services": [
+            "fuchsia.logger.LogSink",
+            "fuchsia.auth.account.AccountManager"
+        ]
     }
 }
diff --git a/garnet/bin/auth/tests/account_manager_integration/tests/account.rs b/src/identity/tests/account_manager_integration/tests/account.rs
similarity index 100%
rename from garnet/bin/auth/tests/account_manager_integration/tests/account.rs
rename to src/identity/tests/account_manager_integration/tests/account.rs
index ea301932881..73e657c7516 100644
--- a/garnet/bin/auth/tests/account_manager_integration/tests/account.rs
+++ b/src/identity/tests/account_manager_integration/tests/account.rs
@@ -10,8 +10,8 @@ use fidl_fuchsia_auth::{
 use fidl_fuchsia_auth_account::{
     AccountManagerMarker, AccountManagerProxy, LocalAccountId, Status,
 };
-use futures::prelude::*;
 use futures::future::join;
+use futures::prelude::*;
 
 /// Calls provision_new_account on the supplied account_manager, returning an error on any
 /// non-OK responses, or the account ID on success.
diff --git a/garnet/bin/auth/tests/account_manager_integration/tests/lib.rs b/src/identity/tests/account_manager_integration/tests/lib.rs
similarity index 100%
rename from garnet/bin/auth/tests/account_manager_integration/tests/lib.rs
rename to src/identity/tests/account_manager_integration/tests/lib.rs
diff --git a/garnet/bin/auth/tests/token_manager_integration/BUILD.gn b/src/identity/tests/token_manager_integration/BUILD.gn
similarity index 63%
rename from garnet/bin/auth/tests/token_manager_integration/BUILD.gn
rename to src/identity/tests/token_manager_integration/BUILD.gn
index 245ab738677..76c808aca4d 100644
--- a/garnet/bin/auth/tests/token_manager_integration/BUILD.gn
+++ b/src/identity/tests/token_manager_integration/BUILD.gn
@@ -3,37 +3,20 @@
 # found in the LICENSE file.
 #
 
-visibility = [ "//garnet/bin/auth/*" ]
-
-import("//build/package.gni")
+import("//build/test/test_package.gni")
 import("//build/testing/environments.gni")
 
 group("token_manager_integration") {
   testonly = true
   deps = [
-    ":e2e_dev",
-    ":token_manager_integration_tests",
+    ":token_manager_integration_test_pkg",
+    "//src/identity/bin/dev_auth_provider",
+    "//src/identity/bin/dev_auth_provider_iotid",
   ]
 }
 
-package("token_manager_integration_tests") {
-  testonly = true
-
-  deps = [
-    ":e2e_dev",
-  ]
-
-  tests = [
-    {
-      name = "dev_token_mgr_e2e_test"
-      environments = basic_envs
-    },
-  ]
-}
-
-executable("e2e_dev") {
-  output_name = "dev_token_mgr_e2e_test"
-
+executable("bin") {
+  output_name = "token_manager_integration_test"
   testonly = true
 
   sources = [
@@ -51,6 +34,20 @@ executable("e2e_dev") {
     "//garnet/public/lib/test_runner/cpp/reporting",
     "//sdk/fidl/fuchsia.auth",
     "//src/lib/fxl",
-    "//third_party/googletest:gtest",
+    "//src/lib/fxl/test:gtest_main",
+  ]
+}
+
+test_package("token_manager_integration_test_pkg") {
+  deps = [
+    ":bin",
+  ]
+
+  tests = [
+    {
+      name = "token_manager_integration_test"
+      environments = basic_envs
+    },
   ]
 }
+
diff --git a/garnet/bin/auth/tests/token_manager_integration/dev_token_mgr_test.cc b/src/identity/tests/token_manager_integration/dev_token_mgr_test.cc
similarity index 96%
rename from garnet/bin/auth/tests/token_manager_integration/dev_token_mgr_test.cc
rename to src/identity/tests/token_manager_integration/dev_token_mgr_test.cc
index 9081b548222..33a37330e68 100644
--- a/garnet/bin/auth/tests/token_manager_integration/dev_token_mgr_test.cc
+++ b/src/identity/tests/token_manager_integration/dev_token_mgr_test.cc
@@ -419,19 +419,3 @@ INSTANTIATE_TEST_SUITE_P(Cpp, DevTokenManagerAppTest,
                          ::testing::ValuesIn(kTestComponentParams));
 }  // namespace
 }  // namespace e2e_dev
-
-int main(int argc, char** argv) {
-  test_runner::GTestListener listener(argv[0]);
-  testing::InitGoogleTest(&argc, argv);
-  testing::UnitTest::GetInstance()->listeners().Append(&listener);
-  int status = RUN_ALL_TESTS();
-  testing::UnitTest::GetInstance()->listeners().Release(&listener);
-
-  {
-    async::Loop loop(&kAsyncLoopConfigAttachToThread);
-    auto context = sys::ComponentContext::Create();
-    test_runner::ReportResult(argv[0], context.get(), listener.GetResults());
-  }
-
-  return status;
-}
diff --git a/src/identity/tests/token_manager_integration/meta/token_manager_integration_test.cmx b/src/identity/tests/token_manager_integration/meta/token_manager_integration_test.cmx
new file mode 100644
index 00000000000..74db2d0b886
--- /dev/null
+++ b/src/identity/tests/token_manager_integration/meta/token_manager_integration_test.cmx
@@ -0,0 +1,12 @@
+{
+    "program": {
+        "binary": "test/token_manager_integration_test"
+    },
+    "sandbox": {
+        "services": [
+            "fuchsia.auth.TokenManagerFactory",
+            "fuchsia.logger.LogSink",
+            "fuchsia.sys.Launcher"
+        ]
+    }
+}
-- 
GitLab