|
6 | 6 | "testing"
|
7 | 7 |
|
8 | 8 | "github.com/google/go-cmp/cmp"
|
| 9 | + "github.com/hashicorp/packer/hcl2template" |
9 | 10 | "github.com/hashicorp/packer/internal/hcp/api"
|
10 | 11 | )
|
11 | 12 |
|
@@ -333,3 +334,51 @@ func TestBucket_PopulateIteration(t *testing.T) {
|
333 | 334 | })
|
334 | 335 | }
|
335 | 336 | }
|
| 337 | + |
| 338 | +func TestReadFromHCLBuildBlock(t *testing.T) { |
| 339 | + tc := []struct { |
| 340 | + desc string |
| 341 | + buildBlock *hcl2template.BuildBlock |
| 342 | + expectedBucket *Bucket |
| 343 | + }{ |
| 344 | + { |
| 345 | + desc: "configure bucket using only hcp_packer_registry block", |
| 346 | + buildBlock: &hcl2template.BuildBlock{ |
| 347 | + HCPPackerRegistry: &hcl2template.HCPPackerRegistryBlock{ |
| 348 | + Slug: "hcp_packer_registry-block-test", |
| 349 | + Description: "description from hcp_packer_registry block", |
| 350 | + BucketLabels: map[string]string{ |
| 351 | + "org": "test", |
| 352 | + }, |
| 353 | + BuildLabels: map[string]string{ |
| 354 | + "version": "1.7.0", |
| 355 | + "based_off": "alpine", |
| 356 | + }, |
| 357 | + }, |
| 358 | + }, |
| 359 | + expectedBucket: &Bucket{ |
| 360 | + Slug: "hcp_packer_registry-block-test", |
| 361 | + Description: "description from hcp_packer_registry block", |
| 362 | + BucketLabels: map[string]string{ |
| 363 | + "org": "test", |
| 364 | + }, |
| 365 | + BuildLabels: map[string]string{ |
| 366 | + "version": "1.7.0", |
| 367 | + "based_off": "alpine", |
| 368 | + }, |
| 369 | + }, |
| 370 | + }, |
| 371 | + } |
| 372 | + for _, tt := range tc { |
| 373 | + tt := tt |
| 374 | + t.Run(tt.desc, func(t *testing.T) { |
| 375 | + bucket := &Bucket{} |
| 376 | + bucket.ReadFromHCLBuildBlock(tt.buildBlock) |
| 377 | + |
| 378 | + diff := cmp.Diff(bucket, tt.expectedBucket, cmp.AllowUnexported(Bucket{})) |
| 379 | + if diff != "" { |
| 380 | + t.Errorf("expected the build to to have contents of hcp_packer_registry block but it does not: %v", diff) |
| 381 | + } |
| 382 | + }) |
| 383 | + } |
| 384 | +} |
0 commit comments