Код IT
← Каталог

Работа с базами данных из Go — Интеграционные тесты

Фрагмент из «Работа с базами данных из Go»: Интеграционные тесты.

Go main.go
  ctx := context.Background()
  req := testcontainers.ContainerRequest{
      Image:        "postgres:15",
      ExposedPorts: []string{"5432/tcp"},
      Env: map[string]string{
          "POSTGRES_DB":       "test",
          "POSTGRES_USER":     "test",
          "POSTGRES_PASSWORD": "test",
      },
  }
  pgContainer, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
      ContainerRequest: req,
      Started:          true,
  })
  ctx := context.Background()
  req := testcontainers.ContainerRequest{
      Image:        "postgres:15",
      ExposedPorts: []string{"5432/tcp"},
      Env: map[string]string{
          "POSTGRES_DB":       "test",
          "POSTGRES_USER":     "test",
          "POSTGRES_PASSWORD": "test",
      },
  }
  pgContainer, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
      ContainerRequest: req,
      Started:          true,
  })