google-cloud-php icon indicating copy to clipboard operation
google-cloud-php copied to clipboard

Cannot set up Compute system tests

Open miraleung opened this issue 3 years ago • 2 comments

Environment details

  • OS: gLinux
  • PHP version: 7.4.15
  • Package name and version: GCE client

Steps to reproduce

  1. git clone https://github.com/georgiyekkert/google-cloud-php.git
  2. Export the keyfile constants, as well as the GOOGLE_CLOUD_PROJECT and PROJECT_ID env vars
  3. cd Compute
  4. composer install
  5. Run gcloud auth login
  6. Make the changes below in SmokeTest and PaginationTest
  7. Run the tests: vendor/bin/phpunit -c phpunit-system.xml.dist tests/System/
  8. Observe the errors at the bottom.

Changes to PaginationTest

public static function setUpBeforeClass(): void
    {
        self::$projectId = getenv('PROJECT_ID');
        $keyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH');
        if (self::$projectId === false) {
            self::fail('Environment variable PROJECT_ID must be set for smoke test');
        }
        if ($keyFilePath === false) {
            self::fail('Environment variable GOOGLE_CLOUD_PHP_TESTS_KEY_PATH must be set for smoke test');
        }
        $options = ['credentials' => $keyFilePath];
        self::$instancesClient = new InstancesClient($options);
        self::$zonesClient = new ZonesClient($options);
    }

Changes to SmokeTest

public static function setUpBeforeClass(): void
    {
        self::$projectId = getenv('PROJECT_ID');
        $keyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH');
        if (self::$projectId === false) {
            self::fail('Environment variable PROJECT_ID must be set for smoke test');
        }
        if ($keyFilePath === false) {
            self::fail('Environment variable GOOGLE_CLOUD_PHP_TESTS_KEY_PATH must be set for smoke test');
        }
        $options = ['credentials' => $keyFilePath];
        self::$instancesClient = new InstancesClient($options);
        self::$machineType = sprintf(
            'https://www.googleapis.com/compute/v1/projects/%s/zones/%s/machineTypes/n1-standard-1',
            self::$projectId,
            self::ZONE
        );
    }

miraleung avatar Jun 01 '21 22:06 miraleung

Hi @miraleung First of apologies for a late follow up on this, but I have a few questions on this.

The step 5 uses a gcloud auth login but then your setUpBeforeClass code uses GOOGLE_CLOUD_PHP_TESTS_KEY_PATH.

Is the step 5 required because AFAIK client libraries use gcloud application-default login.

Also, if possible could you specify what are the exact errors you are observing because I do see an error: Call to a member function close() on null but that refers to self::$acceleratorTypesClient not being initialized in your setup function.

saranshdhingra avatar Sep 13 '22 14:09 saranshdhingra

IIRC this might have originated from post-processing code that was needed on the raw Gapics generated from g3, and I think @dwsupplee might have ended running these tests successfully. @dwsupplee may have more context as well.

miraleung avatar Sep 16 '22 18:09 miraleung

Closing this issue due to inactivity. Please reopen this issue if needed. Thank you!

ajupazhamayil avatar Nov 06 '23 08:11 ajupazhamayil