content: /*
   * Copyright 2023 Aiven Oy
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package io.aiven.kafka.tieredstorage.storage.gcs;
  
  import java.util.Map;
  
  import io.aiven.kafka.tieredstorage.storage.BaseStorageTest;
  import io.aiven.kafka.tieredstorage.storage.StorageBackend;
  import io.aiven.kafka.tieredstorage.storage.TestUtils;
  import io.aiven.testcontainers.fakegcsserver.FakeGcsServerContainer;
  
  import com.google.cloud.NoCredentials;
  import com.google.cloud.storage.BucketInfo;
  import com.google.cloud.storage.Storage;
  import com.google.cloud.storage.StorageOptions;
  import org.junit.jupiter.api.BeforeAll;
  import org.junit.jupiter.api.BeforeEach;
  import org.junit.jupiter.api.TestInfo;
  import org.testcontainers.junit.jupiter.Container;
  import org.testcontainers.junit.jupiter.Testcontainers;
  
  @Testcontainers
  class GcsStorageTest extends BaseStorageTest {
      @Container
      static final FakeGcsServerContainer GCS_SERVER = new FakeGcsServerContainer();
  
      static Storage storage;
      private String bucketName;
  
      @BeforeAll
      static void setUpClass() throws Exception {
          storage = StorageOptions.newBuilder()
              .setCredentials(NoCredentials.getInstance())
              .setHost(GCS_SERVER.url())
              .setProjectId("test-project")
              .build()
              .getService();
      }
  
      @BeforeEach
      void setUp(final TestInfo testInfo) {
          bucketName = TestUtils.testNameToBucketName(testInfo);
          storage.create(BucketInfo.newBuilder(bucketName).build());
      }
  
      @Override
      protected StorageBackend storage() {
          final GcsStorage gcsStorage = new GcsStorage();
          final Map<String, Object> configs = Map.of(
              "gcs.bucket.name", bucketName,
              "gcs.endpoint.url", GCS_SERVER.url(),
              "gcs.credentials.default", "false"
          );
          gcsStorage.configure(configs);
          return gcsStorage;
      }
  }
  