Skip to content

Commit eb1d83e

Browse files
authored
feat(command): ✨ add Stdin arg (#44)
1 parent 8be658f commit eb1d83e

File tree

22 files changed

+598
-3
lines changed

22 files changed

+598
-3
lines changed

examples/examples_go_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ func TestRandomGo(t *testing.T) {
2525
integration.ProgramTest(t, &test)
2626
}
2727

28+
func TestStdinGo(t *testing.T) {
29+
test := getGoBaseOptions(t).
30+
With(integration.ProgramTestOptions{
31+
Dir: filepath.Join(getCwd(t), "stdin-go"),
32+
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
33+
out, ok := stack.Outputs["output"].(string)
34+
assert.True(t, ok)
35+
assert.Equal(t, "the quick brown fox", out)
36+
},
37+
})
38+
integration.ProgramTest(t, &test)
39+
}
40+
2841
func getGoBaseOptions(t *testing.T) integration.ProgramTestOptions {
2942
base := getBaseOptions(t)
3043
baseGo := base.With(integration.ProgramTestOptions{

examples/examples_nodejs_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ func TestRandom(t *testing.T) {
3131
integration.ProgramTest(t, &test)
3232
}
3333

34+
func TestStdin(t *testing.T) {
35+
test := getJSBaseOptions(t).
36+
With(integration.ProgramTestOptions{
37+
Dir: filepath.Join(getCwd(t), "stdin"),
38+
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
39+
out, ok := stack.Outputs["output"].(string)
40+
assert.True(t, ok)
41+
assert.Equal(t, "the quick brown fox", out)
42+
},
43+
})
44+
integration.ProgramTest(t, &test)
45+
}
46+
3447
func TestSimple(t *testing.T) {
3548
test := getJSBaseOptions(t).
3649
With(integration.ProgramTestOptions{

examples/stdin-go/Pulumi.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: command-random-go
2+
runtime: go
3+
description: A simple command example

examples/stdin-go/go.mod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module goaws
2+
3+
go 1.13
4+
5+
require (
6+
github.com/pulumi/pulumi-command/sdk v0.0.1
7+
github.com/pulumi/pulumi/sdk/v3 v3.20.1-0.20211216225508-8a73104cd690
8+
)
9+
10+
replace github.com/pulumi/pulumi-command/sdk => ../../sdk

examples/stdin-go/go.sum

Lines changed: 352 additions & 0 deletions
Large diffs are not rendered by default.

examples/stdin-go/main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import (
4+
"github.com/pulumi/pulumi-command/sdk/go/command/local"
5+
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
6+
)
7+
8+
func main() {
9+
pulumi.Run(func(ctx *pulumi.Context) error {
10+
11+
random, err := local.NewCommand(ctx, "stdin", &local.CommandArgs{
12+
Create: pulumi.String("head -n 1"),
13+
Stdin: pulumi.String("the quick brown fox\njumped over\nthe lazy dog"),
14+
})
15+
if err != nil {
16+
return err
17+
}
18+
19+
ctx.Export("output", random.Stdout)
20+
return nil
21+
})
22+
}

examples/stdin/Pulumi.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: command-random
2+
runtime: nodejs
3+
description: A simple command example

examples/stdin/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { local } from "@pulumi/command";
2+
3+
const random = new local.Command("stdin", {
4+
create: "head -n 1",
5+
stdin: "the quick brown fox\njumped over\nthe lazy dog"
6+
});
7+
8+
export const output = random.stdout;

examples/stdin/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "command-random",
3+
"version": "0.1.0",
4+
"devDependencies": {
5+
"@types/node": "latest"
6+
},
7+
"dependencies": {
8+
"@pulumi/pulumi": "latest",
9+
"@pulumi/random": "^4.2.0"
10+
}
11+
}

examples/stdin/tsconfig.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"compilerOptions": {
3+
"strict": true,
4+
"outDir": "bin",
5+
"target": "es2016",
6+
"module": "commonjs",
7+
"moduleResolution": "node",
8+
"sourceMap": true,
9+
"experimentalDecorators": true,
10+
"pretty": true,
11+
"noFallthroughCasesInSwitch": true,
12+
"noImplicitReturns": true,
13+
"forceConsistentCasingInFileNames": true
14+
},
15+
"files": [
16+
"index.ts"
17+
]
18+
}

0 commit comments

Comments
 (0)