|
1 |
| -# PulumiConfig |
| 1 | +### About the projects: |
| 2 | +<details> |
| 3 | + <summary>Table of contents</summary> |
| 4 | + <ol> |
| 5 | + <li> |
| 6 | + <a href="#pulumi-config">PulumiConfig Section</a> |
| 7 | + <ul> |
| 8 | + <li><a href="#features">Features</a></li> |
| 9 | + <li><a href="#installation">Installation</a></li> |
| 10 | + <li><a href="#usage">Usage</a></li> |
| 11 | + <li><a href="#examples">Examples</a></li> |
| 12 | + </ul> |
| 13 | + </li> |
| 14 | + <li> |
| 15 | + <a href="#pulumi-test">PulumiTest Section</a> |
| 16 | + <ul> |
| 17 | + <li><a href="#features-1">Features</a></li> |
| 18 | + <li><a href="#installation-1">Installation</a></li> |
| 19 | + <li><a href="#usage-1">Usage</a></li> |
| 20 | + <li><a href="#examples-1">Examples</a></li> |
| 21 | + </ul> |
| 22 | + </li> |
| 23 | + </ol> |
| 24 | +</details> |
| 25 | + |
| 26 | + |
| 27 | +<!-- pulumi-config --> |
| 28 | +## PulumiConfig <a id="pulumi-config"></a> |
2 | 29 |
|
3 | 30 | PulumiConfig is a Golang library designed to improve the way developers manage configuration in Pulumi. By leveraging Golang structs, it simplifies the process of tracking and validating configuration keys, ensuring a more efficient and error-free deployment process in cloud infrastructure projects.
|
4 | 31 |
|
5 |
| -## Features |
| 32 | +### Features <a id="features"></a> |
6 | 33 |
|
7 | 34 | - **Seamless Integration**: Effortlessly integrates with Pulumi and Golang projects.
|
8 | 35 | - **Automated Key Tracking**: Automatically tracks configuration keys using Golang structs.
|
9 | 36 | - **JSON Tagging**: Supports JSON tagging for Pulumi configuration keys, including nested structs.
|
10 | 37 | - **[go-playground/validator](https://github.com/go-playground/validator)**, letting you define both field- and struct-level validations., allowing required values and complex validations.
|
11 | 38 | - **Namespace Overrides**: Use `overrideConfigNamespace` to override specific fields with values from a different namespace.
|
12 | 39 |
|
13 |
| -## Installation |
| 40 | +### Installation <a id="installation"></a> |
| 41 | + |
14 | 42 |
|
15 | 43 | To integrate PulumiConfig into your Golang project, follow these steps:
|
16 | 44 |
|
@@ -151,7 +179,7 @@ func main() {
|
151 | 179 |
|
152 | 180 | You can use `overrideConfigNamespace` on any field-level struct tag. PulumiConfig will first load from the main namespace, and then—if `overrideConfigNamespace` is set—load the separate namespace and merge those values in.
|
153 | 181 |
|
154 |
| -### Example: Custom Field and Struct Validators |
| 182 | +### Example: Custom Field and Struct Validators <a id="examples"></a> |
155 | 183 |
|
156 | 184 | Below is a more in-depth example illustrating how you can combine PulumiConfig with the Pulumi DigitalOcean provider for domain-specific validation:
|
157 | 185 |
|
@@ -290,6 +318,118 @@ func main() {
|
290 | 318 |
|
291 | 319 | By combining `StructValidation` and `FieldValidation`, you can enforce both global and per-field checks for your Pulumi configurations. Adjust or extend as needed for your own providers or custom logic.
|
292 | 320 |
|
| 321 | + |
| 322 | + |
| 323 | + |
| 324 | + |
| 325 | +<!-- pulumi-test --> |
| 326 | +## PulumiTest <a id="pulumi-test"></a> |
| 327 | + |
| 328 | + |
| 329 | +`pulumitest` is a Go package that provides helper functions to simplify testing Pulumi resources and outputs. It simplifies Pulumi testing by abstracting common patterns and offering intuitive assertions for resource validation. |
| 330 | + |
| 331 | +### Features <a id="features-1"></a> |
| 332 | + |
| 333 | +- **Simplifies Testing**: Provides utility functions to compare Pulumi outputs and resources without writing boilerplate code. |
| 334 | +- **Fast Test Workflow**: Enables quick and efficient testing of Pulumi programs in Go. |
| 335 | + |
| 336 | + |
| 337 | +### Installation <a id="installation-1"></a> |
| 338 | + |
| 339 | +To use `pulumitest`, import it into your test files: |
| 340 | + |
| 341 | +```go |
| 342 | +import ("github.com/exivity/pulumiconfig/pkg/pulumitest") |
| 343 | +``` |
| 344 | + |
| 345 | +## Usage |
| 346 | + |
| 347 | +### Basic Usage |
| 348 | +Below are the public functions provided by `pulumitest` and how to use them: |
| 349 | + |
| 350 | +```bash |
| 351 | +pulumitest.AssertStringOutputEqual(t, expectedOutput, actualOutput) |
| 352 | +pulumitest.AssertMapEqual(t, expectedMap, actualMap) |
| 353 | +pulumitest.AssertStringMapEqual(t, expectedStringMap, actualStringMap) |
| 354 | +``` |
| 355 | + |
| 356 | +Sets the Pulumi configuration for a test. |
| 357 | +```bash |
| 358 | +pulumitest.SetPulumiConfig(t, map[string]string{ |
| 359 | + "key1": "value1", |
| 360 | + "key2": "value2", |
| 361 | +}) |
| 362 | +``` |
| 363 | + |
| 364 | +### Example: Testing Map Outputs <a id="examples-1"></a> |
| 365 | +Compares two pulumi.MapOutput values and reports if they are not equal. |
| 366 | + |
| 367 | +```go |
| 368 | +package test |
| 369 | + |
| 370 | +import ( |
| 371 | + "testing" |
| 372 | + |
| 373 | + "github.com/pulumi/pulumi/sdk/v3/go/pulumi" |
| 374 | + "github.com/exivity/pulumiconfig/pkg/pulumitest" |
| 375 | +) |
| 376 | + |
| 377 | +func TestAssertMapEqual(t *testing.T) { |
| 378 | + type args struct { |
| 379 | + expected pulumi.MapOutput |
| 380 | + actual pulumi.MapOutput |
| 381 | + msgAndArgs []interface{} |
| 382 | + } |
| 383 | + tests := []struct { |
| 384 | + name string |
| 385 | + args args |
| 386 | + wantFailed bool |
| 387 | + }{ |
| 388 | + { |
| 389 | + name: "nil outputs", // Both maps are empty. |
| 390 | + args: args{ |
| 391 | + expected: pulumi.Map{}.ToMapOutput(), |
| 392 | + actual: pulumi.Map{}.ToMapOutput(), |
| 393 | + }, |
| 394 | + wantFailed: false, |
| 395 | + }, |
| 396 | + { |
| 397 | + name: "expect and actual are equal", // Both maps have the same key-value pairs. |
| 398 | + args: args{ |
| 399 | + expected: pulumi.Map{ |
| 400 | + "key": pulumi.String("value"), |
| 401 | + }.ToMapOutput(), |
| 402 | + actual: pulumi.Map{ |
| 403 | + "key": pulumi.String("value"), |
| 404 | + }.ToMapOutput(), |
| 405 | + }, |
| 406 | + wantFailed: false, |
| 407 | + }, |
| 408 | + { |
| 409 | + name: "expect and actual are not equal", // Maps have different values for the same key. |
| 410 | + args: args{ |
| 411 | + expected: pulumi.Map{ |
| 412 | + "key": pulumi.String("value"), |
| 413 | + }.ToMapOutput(), |
| 414 | + actual: pulumi.Map{ |
| 415 | + "key": pulumi.String(""), |
| 416 | + }.ToMapOutput(), |
| 417 | + }, |
| 418 | + wantFailed: true, |
| 419 | + }, |
| 420 | + } |
| 421 | + for _, tt := range tests { |
| 422 | + t.Run(tt.name, func(t *testing.T) { |
| 423 | + testT := &testing.T{} |
| 424 | + AssertMapEqual(testT, tt.args.expected, tt.args.actual, tt.args.msgAndArgs...) |
| 425 | + assert.Equal(t, tt.wantFailed, testT.Failed()) |
| 426 | + }) |
| 427 | + } |
| 428 | +} |
| 429 | + |
| 430 | +``` |
| 431 | + |
293 | 432 | ## License
|
294 | 433 |
|
295 | 434 | PulumiConfig is released under MIT. See the [LICENSE](./LICENSE) file for more details.
|
| 435 | + |
0 commit comments