Skip to content

Commit b7fee17

Browse files
committed
First pass at fixing example command
1 parent 821a698 commit b7fee17

5 files changed

Lines changed: 52 additions & 3 deletions

File tree

src/cmd/example.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ func getExample[T any]() string {
2424
return getYaml[T]()
2525
}
2626

27+
func getExample2[T any](v T) string {
28+
var out []byte
29+
var err error
30+
if exampleIsJson {
31+
out, err = json.Marshal(v)
32+
} else {
33+
out, err = yaml.Marshal(v)
34+
}
35+
if err != nil {
36+
panic("unexpected error getting example")
37+
}
38+
return string(out)
39+
}
40+
2741
func getJson[T any]() string {
2842
var (
2943
out []byte

src/cmd/system.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ var exampleSystemCmd = &cobra.Command{
1818
Short: "Example system",
1919
Long: `Example system`,
2020
Run: func(cmd *cobra.Command, args []string) {
21-
fmt.Println(getExample[opslevel.SystemInput]())
21+
fmt.Println(getExample2(opslevel.SystemInput{
22+
Name: opslevel.RefOf("example_name"),
23+
Description: opslevel.RefOf("example_description"),
24+
OwnerId: opslevel.RefOf(opslevel.ID("Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk")),
25+
//Parent: opslevel.NewIdentifier("domain-alias"),
26+
Note: opslevel.RefOf("example_note"),
27+
}))
2228
},
2329
}
2430

src/e2e/helpers.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,23 @@ func (s Missing) Run(u *Utility) {
172172

173173
func (s Missing) Name() string { return "Missing" }
174174
func (s Missing) Deferred() bool { return true }
175+
176+
type Example struct {
177+
Cmd string
178+
Yaml string
179+
}
180+
181+
func (s Example) Run(u *Utility) {
182+
out, err := u.Run(s.Cmd + " --yaml")
183+
if err != nil {
184+
panic("example failed: " + err.Error() + "\nout: " + out)
185+
}
186+
wip := strings.TrimSpace(out)
187+
expected := strings.TrimSpace(s.Yaml)
188+
if wip != expected {
189+
u.Fatalf("example mismatch for '%s'\nExpected:\n%s\nWIP:\n%s", s.Cmd, expected, wip)
190+
}
191+
}
192+
193+
func (s Example) Name() string { return "Example" }
194+
func (s Example) Deferred() bool { return false }

src/e2e/system_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ import (
88
func TestSystemHappyPath(t *testing.T) {
99
tc := CLITest{
1010
Steps: []Step{
11+
Example{
12+
Cmd: "example system",
13+
Yaml: `
14+
description: example_description
15+
name: example_name
16+
note: example_note
17+
ownerId: Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk
18+
`,
19+
},
1120
Create{
1221
Cmd: "create system",
1322
Input: `
@@ -71,4 +80,4 @@ description: "Updated by integration test"
7180
},
7281
}
7382
tc.Run(t)
74-
}
83+
}

0 commit comments

Comments
 (0)