Skip to content

Commit 23f5968

Browse files
authored
Setup e2e tests for some resources (#404)
* Setup e2e tests for domain * PR feedback * Checkpoint * Expand test coverage * Add system test * First pass at fixing example command * more tweaks * Fix CI * Fix up all example commands * More fixes * fixes * more fixes for removal of old code * Update Taskfile.yml * fix e2e integration tests * few more tweaks after testing manually
1 parent 32c5b15 commit 23f5968

28 files changed

+813
-78
lines changed

Taskfile.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ tasks:
5656
cmds:
5757
- go test -race -coverprofile=coverage.txt -covermode=atomic -v ./cmd/... {{ .CLI_ARGS }}
5858

59+
test-e2e:
60+
desc: Run end to end Integration tests
61+
dir: "{{.SRC_DIR}}"
62+
cmds:
63+
- go test -v ./e2e/... {{ .CLI_ARGS }}
64+
5965
update-opslevel-go:
6066
desc: Update opslevel-go version to latest release
6167
dir: "{{.SRC_DIR}}"

src/cmd/action.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ var exampleActionCmd = &cobra.Command{
1717
Short: "Example action",
1818
Long: `Example action`,
1919
Run: func(cmd *cobra.Command, args []string) {
20-
fmt.Println(getExample[opslevel.CustomActionsWebhookActionCreateInput]())
20+
fmt.Println(getExample(opslevel.CustomActionsWebhookActionCreateInput{
21+
Name: "example_name",
22+
Description: opslevel.RefOf("example_description"),
23+
WebhookUrl: "example_webhook_url",
24+
HttpMethod: opslevel.CustomActionsHttpMethodEnumPost,
25+
Headers: &opslevel.JSON{
26+
"example_header": "example_value",
27+
},
28+
LiquidTemplate: opslevel.RefOf("example_liquid_template"),
29+
}))
2130
},
2231
}
2332

src/cmd/alias.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ var exampleAliasCmd = &cobra.Command{
1616
Short: "Example alias",
1717
Long: `Example alias`,
1818
Run: func(cmd *cobra.Command, args []string) {
19-
fmt.Println(getExample[opslevel.AliasCreateInput]())
19+
fmt.Println(getExample(opslevel.AliasCreateInput{
20+
OwnerId: opslevel.ID("Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"),
21+
Alias: "example_alias",
22+
}))
2023
},
2124
}
2225

src/cmd/dependency.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ var exampleServiceDependencyCmd = &cobra.Command{
2020
Short: "Example service dependency",
2121
Long: `Example service dependency`,
2222
Run: func(cmd *cobra.Command, args []string) {
23-
fmt.Println(getExample[opslevel.ServiceDependencyCreateInput]())
23+
fmt.Println(getExample(opslevel.ServiceDependencyCreateInput{
24+
DependencyKey: opslevel.ServiceDependencyKey{
25+
SourceIdentifier: opslevel.NewIdentifier("example_source"),
26+
DestinationIdentifier: opslevel.NewIdentifier("example_destination"),
27+
},
28+
Notes: opslevel.RefOf("example_notes"),
29+
}))
2430
},
2531
}
2632

src/cmd/domain.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ var exampleDomainCmd = &cobra.Command{
1717
Short: "Example Domain",
1818
Long: `Example Domain`,
1919
Run: func(cmd *cobra.Command, args []string) {
20-
fmt.Println(getExample[opslevel.DomainInput]())
20+
fmt.Println(getExample(opslevel.DomainInput{
21+
Name: opslevel.RefOf("example_name"),
22+
Description: opslevel.RefOf("example_description"),
23+
OwnerId: opslevel.RefOf(opslevel.ID("Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk")),
24+
Note: opslevel.RefOf("example_note"),
25+
}))
2126
},
2227
}
2328

src/cmd/example.go

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmd
33
import (
44
"encoding/json"
55

6-
"github.com/opslevel/opslevel-go/v2025"
76
"github.com/spf13/cobra"
87
"github.com/spf13/viper"
98
"gopkg.in/yaml.v2"
@@ -17,35 +16,16 @@ var exampleCmd = &cobra.Command{
1716
Long: "Examples of OpsLevel resources in different formats",
1817
}
1918

20-
func getExample[T any]() string {
19+
func getExample[T any](v T) string {
20+
var out []byte
21+
var err error
2122
if exampleIsJson {
22-
return getJson[T]()
23+
out, err = json.Marshal(v)
24+
} else {
25+
out, err = yaml.Marshal(v)
2326
}
24-
return getYaml[T]()
25-
}
26-
27-
func getJson[T any]() string {
28-
var (
29-
out []byte
30-
err error
31-
)
32-
t := opslevel.NewExampleOf[T]()
33-
out, err = json.Marshal(t)
34-
if err != nil {
35-
panic("unexpected error getting example json")
36-
}
37-
return string(out)
38-
}
39-
40-
func getYaml[T any]() string {
41-
var (
42-
out []byte
43-
err error
44-
)
45-
t := opslevel.NewExampleOf[T]()
46-
out, err = yaml.Marshal(t)
4727
if err != nil {
48-
panic("unexpected error getting example yaml")
28+
panic("unexpected error getting example")
4929
}
5030
return string(out)
5131
}

src/cmd/filter.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@ var exampleFilterCmd = &cobra.Command{
1515
Short: "Example filter",
1616
Long: `Example filter`,
1717
Run: func(cmd *cobra.Command, args []string) {
18-
fmt.Println(getExample[opslevel.FilterCreateInput]())
18+
fmt.Println(getExample(opslevel.FilterCreateInput{
19+
Name: "example_name",
20+
Predicates: &[]opslevel.FilterPredicateInput{
21+
{
22+
Key: opslevel.PredicateKeyEnumAliases,
23+
Type: opslevel.PredicateTypeEnumEquals,
24+
Value: opslevel.RefOf("example_value"),
25+
CaseSensitive: opslevel.RefOf(false),
26+
},
27+
},
28+
}))
1929
},
2030
}
2131

src/cmd/infra.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,22 @@ var exampleInfraCmd = &cobra.Command{
2020
Short: "Example infrastructure resource",
2121
Long: `Example infrastructure resource`,
2222
Run: func(cmd *cobra.Command, args []string) {
23-
fmt.Println(getExample[opslevel.InfrastructureResourceInput]())
23+
fmt.Println(getExample(opslevel.InfraInput{
24+
Schema: "example_schema",
25+
Owner: opslevel.NewID("Z2lkOi8vc2VydmljZS8xMjM0NTY3ODk"),
26+
Provider: &opslevel.InfraProviderInput{
27+
Account: "example_account",
28+
Name: "example_provider_name",
29+
Type: "example_provider_type",
30+
URL: "example_external_url",
31+
},
32+
Data: &opslevel.JSON{
33+
"name": "my-big-query",
34+
"endpoint": "https://google.com",
35+
"engine": "BigQuery",
36+
"replica": false,
37+
},
38+
}))
2439
},
2540
}
2641

src/cmd/integration.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ type IntegrationInputType struct {
3939

4040
type IntegrationInput interface {
4141
opslevel.AWSIntegrationInput |
42-
opslevel.AzureResourcesIntegrationInput |
43-
EventIntegrationInputDTO |
44-
opslevel.GoogleCloudIntegrationInput
42+
opslevel.AzureResourcesIntegrationInput |
43+
EventIntegrationInputDTO |
44+
opslevel.GoogleCloudIntegrationInput
4545
}
4646

4747
func validateIntegrationInput() (*IntegrationInputType, error) {

src/cmd/property.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,31 @@ import (
1414
"github.com/spf13/cobra"
1515
)
1616

17+
func buildExamplePropertyInput() string {
18+
return getExample(opslevel.PropertyInput{
19+
Definition: *opslevel.NewIdentifier("example_definition"),
20+
Owner: *opslevel.NewIdentifier("example_owner"),
21+
Value: opslevel.JsonString("example_value"),
22+
})
23+
}
24+
25+
func buildExamplePropertyDefinitionInput() string {
26+
return getExample(opslevel.PropertyDefinitionInput{
27+
Name: opslevel.RefOf("example_name"),
28+
Description: opslevel.RefOf("example_description"),
29+
Schema: &opslevel.JSONSchema{
30+
"type": "string",
31+
},
32+
})
33+
}
34+
1735
var examplePropertyCmd = &cobra.Command{
1836
Use: "property",
1937
Aliases: []string{"prop"},
2038
Short: "Example Property",
2139
Long: `Example Property`,
2240
Run: func(cmd *cobra.Command, args []string) {
23-
fmt.Println(getExample[opslevel.PropertyInput]())
41+
fmt.Println(buildExamplePropertyInput())
2442
},
2543
}
2644

@@ -104,7 +122,7 @@ EOF
104122
105123
cat << EOF | opslevel assign property -f -
106124
%s
107-
EOF`, getYaml[opslevel.PropertyInput]()),
125+
EOF`, buildExamplePropertyInput()),
108126
Run: func(cmd *cobra.Command, args []string) {
109127
input, err := readResourceInput[opslevel.PropertyInput]()
110128
cobra.CheckErr(err)
@@ -149,7 +167,7 @@ var examplePropertyDefinitionCmd = &cobra.Command{
149167
Short: "Example Property Definition",
150168
Long: `Example Property Definition`,
151169
Run: func(cmd *cobra.Command, args []string) {
152-
fmt.Println(getExample[opslevel.PropertyDefinitionInput]())
170+
fmt.Println(buildExamplePropertyDefinitionInput())
153171
},
154172
}
155173

@@ -161,7 +179,7 @@ var createPropertyDefinitionCmd = &cobra.Command{
161179
Example: fmt.Sprintf(`
162180
cat << EOF | opslevel create property-definition -f -
163181
%s
164-
EOF`, getYaml[opslevel.PropertyDefinitionInput]()),
182+
EOF`, buildExamplePropertyDefinitionInput()),
165183
Run: func(cmd *cobra.Command, args []string) {
166184
input, err := readPropertyDefinitionInput()
167185
cobra.CheckErr(err)
@@ -180,7 +198,7 @@ var updatePropertyDefinitionCmd = &cobra.Command{
180198
Example: fmt.Sprintf(`
181199
cat << EOF | opslevel update property-definition propdef3 -f -
182200
%s
183-
EOF`, getYaml[opslevel.PropertyDefinitionInput]()),
201+
EOF`, buildExamplePropertyDefinitionInput()),
184202
Args: cobra.ExactArgs(1),
185203
ArgAliases: []string{"ID", "ALIAS"},
186204
Run: func(cmd *cobra.Command, args []string) {

0 commit comments

Comments
 (0)