|
15 | 15 | package dart |
16 | 16 |
|
17 | 17 | import ( |
| 18 | + "errors" |
18 | 19 | "os" |
19 | 20 | "path/filepath" |
20 | 21 | "strings" |
21 | 22 | "testing" |
22 | 23 |
|
23 | 24 | "github.com/google/go-cmp/cmp" |
24 | 25 | "github.com/googleapis/librarian/internal/config" |
| 26 | + sidekickconfig "github.com/googleapis/librarian/internal/sidekick/config" |
25 | 27 | "github.com/googleapis/librarian/internal/testhelper" |
26 | 28 | ) |
27 | 29 |
|
@@ -361,3 +363,132 @@ func TestBuildCodec(t *testing.T) { |
361 | 363 | }) |
362 | 364 | } |
363 | 365 | } |
| 366 | + |
| 367 | +func TestToSidekickConfig(t *testing.T) { |
| 368 | + googleapisDir := t.TempDir() |
| 369 | + for _, test := range []struct { |
| 370 | + name string |
| 371 | + library *config.Library |
| 372 | + channel *config.API |
| 373 | + googleapisDir string |
| 374 | + want *sidekickconfig.Config |
| 375 | + wantErr error |
| 376 | + }{ |
| 377 | + { |
| 378 | + name: "empty library", |
| 379 | + library: &config.Library{}, |
| 380 | + channel: &config.API{ |
| 381 | + Path: "google/example/v1", |
| 382 | + }, |
| 383 | + googleapisDir: googleapisDir, |
| 384 | + want: &sidekickconfig.Config{ |
| 385 | + General: sidekickconfig.GeneralConfig{ |
| 386 | + Language: "dart", |
| 387 | + SpecificationFormat: "protobuf", |
| 388 | + ServiceConfig: "", |
| 389 | + SpecificationSource: "google/example/v1", |
| 390 | + }, |
| 391 | + Source: map[string]string{ |
| 392 | + "googleapis-root": googleapisDir, |
| 393 | + }, |
| 394 | + Codec: map[string]string{}, |
| 395 | + }, |
| 396 | + }, |
| 397 | + { |
| 398 | + name: "with name-override", |
| 399 | + library: &config.Library{ |
| 400 | + Dart: &config.DartPackage{ |
| 401 | + NameOverride: "override-name", |
| 402 | + }, |
| 403 | + }, |
| 404 | + channel: &config.API{ |
| 405 | + Path: "google/example/v1", |
| 406 | + }, |
| 407 | + googleapisDir: googleapisDir, |
| 408 | + want: &sidekickconfig.Config{ |
| 409 | + General: sidekickconfig.GeneralConfig{ |
| 410 | + Language: "dart", |
| 411 | + SpecificationFormat: "protobuf", |
| 412 | + ServiceConfig: "", |
| 413 | + SpecificationSource: "google/example/v1", |
| 414 | + }, |
| 415 | + Source: map[string]string{ |
| 416 | + "googleapis-root": googleapisDir, |
| 417 | + "name-override": "override-name", |
| 418 | + }, |
| 419 | + Codec: map[string]string{}, |
| 420 | + }, |
| 421 | + }, |
| 422 | + { |
| 423 | + name: "with dart package", |
| 424 | + library: &config.Library{ |
| 425 | + Dart: &config.DartPackage{ |
| 426 | + APIKeysEnvironmentVariables: "GOOGLE_API_KEY", |
| 427 | + Dependencies: "dep-1,dep-2", |
| 428 | + DevDependencies: "dev-dep-1,dev-dep-2", |
| 429 | + ExtraImports: "extra-imports", |
| 430 | + IssueTrackerURL: "https://tracker/issues", |
| 431 | + LibraryPathOverride: "library-path-override", |
| 432 | + NotForPublication: "false", |
| 433 | + PartFile: "part-file", |
| 434 | + ReadmeAfterTitleText: "readme-after-title-text", |
| 435 | + ReadmeQuickstartText: "readme-quickstart-text", |
| 436 | + RepositoryURL: "https://github.com/googleapis/google-cloud-dart", |
| 437 | + Packages: map[string]string{ |
| 438 | + "package:googleapis_auth": "^2.0.0", |
| 439 | + }, |
| 440 | + Prefixes: map[string]string{ |
| 441 | + "prefix:google.logging.type": "logging_type", |
| 442 | + }, |
| 443 | + Protos: map[string]string{ |
| 444 | + "proto:google.api": "package:google_cloud_api/api.dart", |
| 445 | + }, |
| 446 | + }, |
| 447 | + }, |
| 448 | + channel: &config.API{ |
| 449 | + Path: "google/example/v1", |
| 450 | + }, |
| 451 | + googleapisDir: googleapisDir, |
| 452 | + want: &sidekickconfig.Config{ |
| 453 | + General: sidekickconfig.GeneralConfig{ |
| 454 | + Language: "dart", |
| 455 | + SpecificationFormat: "protobuf", |
| 456 | + ServiceConfig: "", |
| 457 | + SpecificationSource: "google/example/v1", |
| 458 | + }, |
| 459 | + Source: map[string]string{ |
| 460 | + "googleapis-root": googleapisDir, |
| 461 | + }, |
| 462 | + Codec: map[string]string{ |
| 463 | + "api-keys-environment-variables": "GOOGLE_API_KEY", |
| 464 | + "dependencies": "dep-1,dep-2", |
| 465 | + "dev-dependencies": "dev-dep-1,dev-dep-2", |
| 466 | + "extra-imports": "extra-imports", |
| 467 | + "issue-tracker-url": "https://tracker/issues", |
| 468 | + "library-path-override": "library-path-override", |
| 469 | + "not-for-publication": "false", |
| 470 | + "package:googleapis_auth": "^2.0.0", |
| 471 | + "part-file": "part-file", |
| 472 | + "prefix:prefix:google.logging.type": "logging_type", |
| 473 | + "proto:proto:google.api": "package:google_cloud_api/api.dart", |
| 474 | + "readme-after-title-text": "readme-after-title-text", |
| 475 | + "readme-quickstart-text": "readme-quickstart-text", |
| 476 | + "repository-url": "https://github.com/googleapis/google-cloud-dart", |
| 477 | + }, |
| 478 | + }, |
| 479 | + }, |
| 480 | + } { |
| 481 | + t.Run(test.name, func(t *testing.T) { |
| 482 | + got, err := toSidekickConfig(test.library, test.channel, test.googleapisDir) |
| 483 | + if test.wantErr != nil { |
| 484 | + if !errors.Is(err, test.wantErr) { |
| 485 | + t.Errorf("toSidekickConfig() error = %v, wantErr %v", err, test.wantErr) |
| 486 | + } |
| 487 | + return |
| 488 | + } |
| 489 | + if diff := cmp.Diff(test.want, got); diff != "" { |
| 490 | + t.Errorf("mismatch (-want +got):\n%s", diff) |
| 491 | + } |
| 492 | + }) |
| 493 | + } |
| 494 | +} |
0 commit comments