Skip to content

Commit

Permalink
Fixes for terraform component types (#515)
Browse files Browse the repository at this point in the history
* Fixes for terraform component types

* test fixes
  • Loading branch information
rocktavious authored Feb 3, 2025
1 parent 250d418 commit ecf166c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 16 deletions.
36 changes: 36 additions & 0 deletions component.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package opslevel

import "fmt"

type Component Service

type ComponentCreateInput ServiceCreateInput
Expand All @@ -14,6 +16,40 @@ type ComponentTypeConnection struct {
TotalCount int `json:"totalCount" graphql:"-"`
}

func (s *ComponentType) GetProperties(client *Client, v *PayloadVariables) (*PropertyDefinitionConnection, error) {
var q struct {
Account struct {
ComponentType struct {
Properties *PropertyDefinitionConnection `graphql:"properties(after: $after, first: $first)"`
} `graphql:"componentType(input: $input)"`
}
}
if s.Id == "" {
return nil, fmt.Errorf("unable to get properties, invalid id: '%s'", s.Id)
}
if v == nil {
v = client.InitialPageVariablesPointer()
}
(*v)["input"] = *NewIdentifier(string(s.Id))
if err := client.Query(&q, *v, WithName("ComponentTypePropertyList")); err != nil {
return nil, err
}
if s.Properties == nil {
s.Properties = &PropertyDefinitionConnection{}
}
s.Properties.Nodes = append(s.Properties.Nodes, q.Account.ComponentType.Properties.Nodes...)
s.Properties.PageInfo = q.Account.ComponentType.Properties.PageInfo
s.Properties.TotalCount += q.Account.ComponentType.Properties.TotalCount
for s.Properties.PageInfo.HasNextPage {
(*v)["after"] = s.Properties.PageInfo.End
_, err := s.GetProperties(client, v)
if err != nil {
return nil, err
}
}
return s.Properties, nil
}

func (client *Client) CreateComponentType(input ComponentTypeInput) (*ComponentType, error) {
var m struct {
Payload ComponentTypePayload `graphql:"componentTypeCreate(input:$input)"`
Expand Down
13 changes: 7 additions & 6 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ type ComponentTypeId struct {
// ComponentType Information about a particular component type
type ComponentType struct {
ComponentTypeId
Description string // The description of the component type (Optional)
Href string // The relative path to link to the component type (Required)
Icon ComponentTypeIcon // The icon associated with the component type (Required)
IsDefault bool // Whether or not the component type is the default (Required)
Name string // The name of the component type (Required)
Timestamps Timestamps // When the component type was created and updated (Required)
Description string // The description of the component type (Optional)
Href string // The relative path to link to the component type (Required)
Icon ComponentTypeIcon // The icon associated with the component type (Required)
IsDefault bool // Whether or not the component type is the default (Required)
Name string // The name of the component type (Required)
Timestamps Timestamps // When the component type was created and updated (Required)
Properties *PropertyDefinitionConnection `graphql:"-"`
}

// ComponentTypeIcon The icon for a component type
Expand Down
2 changes: 1 addition & 1 deletion property.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type PropertyDefinition struct {
DisplayType PropertyDefinitionDisplayTypeEnum `graphql:"displayType" json:"displayType"`
PropertyDisplayStatus PropertyDisplayStatusEnum `graphql:"propertyDisplayStatus" json:"propertyDisplayStatus"`
LockedStatus PropertyLockedStatusEnum `graphql:"lockedStatus" json:"lockedStatus"`
Schema JSON `json:"schema" scalar:"true"`
Schema JSONSchema `json:"schema" scalar:"true"`
}

type PropertyDefinitionConnection struct {
Expand Down
18 changes: 9 additions & 9 deletions property_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (
func TestCreatePropertyDefinition(t *testing.T) {
// Arrange
schema, schemaErr := ol.NewJSONSchema(schemaString)
schemaAsJSON, schemaAsJSONErr := ol.NewJSON(schemaString)
schemaAsJSON, schemaAsJSONErr := ol.NewJSONSchema(schemaString)
autopilot.Ok(t, schemaErr)
autopilot.Ok(t, schemaAsJSONErr)
expectedPropertyDefinition := autopilot.Register("expected_property_definition", ol.PropertyDefinition{
Expand Down Expand Up @@ -50,7 +50,7 @@ func TestCreatePropertyDefinition(t *testing.T) {
func TestUpdatePropertyDefinition(t *testing.T) {
// Arrange
schema, schemaErr := ol.NewJSONSchema(schemaString)
schemaAsJSON, schemaAsJSONErr := ol.NewJSON(schemaString2)
schemaAsJSON, schemaAsJSONErr := ol.NewJSONSchema(schemaString2)
autopilot.Ok(t, schemaErr)
autopilot.Ok(t, schemaAsJSONErr)
expectedPropertyDefinition := autopilot.Register("expected_property_definition", ol.PropertyDefinition{
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestDeletePropertyDefinition(t *testing.T) {

func TestGetPropertyDefinition(t *testing.T) {
// Arrange
schema, schemaErr := ol.NewJSON(schemaString)
schema, schemaErr := ol.NewJSONSchema(schemaString)
autopilot.Ok(t, schemaErr)
expectedPropertyDefinition := autopilot.Register("expected_property_definition",
ol.PropertyDefinition{
Expand Down Expand Up @@ -133,10 +133,10 @@ func TestGetPropertyDefinition(t *testing.T) {

func TestListPropertyDefinitions(t *testing.T) {
// Arrange
schema, schemaErr := ol.NewJSON(schemaString)
schemaPage1, schemaPage1Err := ol.NewJSON(schemaString)
schemaPage2, schemaPage2Err := ol.NewJSON(schemaString)
schemaPage3, schemaPage3Err := ol.NewJSON(schemaString)
schema, schemaErr := ol.NewJSONSchema(schemaString)
schemaPage1, schemaPage1Err := ol.NewJSONSchema(schemaString)
schemaPage2, schemaPage2Err := ol.NewJSONSchema(schemaString)
schemaPage3, schemaPage3Err := ol.NewJSONSchema(schemaString)
autopilot.Ok(t, schemaErr)
autopilot.Ok(t, schemaPage1Err)
autopilot.Ok(t, schemaPage2Err)
Expand Down Expand Up @@ -167,12 +167,12 @@ func TestListPropertyDefinitions(t *testing.T) {
testRequestOne := autopilot.NewTestRequest(
`query PropertyDefinitionList($after:String!$first:Int!){account{propertyDefinitions(after: $after, first: $first){nodes{aliases,allowedInConfigFiles,id,name,description,displaySubtype,displayType,propertyDisplayStatus,lockedStatus,schema},{{ template "pagination_request" }}}}}`,
`{{ template "pagination_initial_query_variables" }}`,
fmt.Sprintf(`{"data":{"account":{"propertyDefinitions":{"nodes":[{"aliases":["prop1"],"allowedInConfigFiles":true,"id":"XXX","name":"prop1","schema": %s},{"aliases":["prop2"],"allowedInConfigFiles":false,"id":"XXX","name":"prop2","schema": %s}],{{ template "pagination_initial_pageInfo_response" }}}}}}`, schema.ToJSON(), schema.ToJSON()),
fmt.Sprintf(`{"data":{"account":{"propertyDefinitions":{"nodes":[{"aliases":["prop1"],"allowedInConfigFiles":true,"id":"XXX","name":"prop1","schema": %s},{"aliases":["prop2"],"allowedInConfigFiles":false,"id":"XXX","name":"prop2","schema": %s}],{{ template "pagination_initial_pageInfo_response" }}}}}}`, schema.AsString(), schema.AsString()),
)
testRequestTwo := autopilot.NewTestRequest(
`query PropertyDefinitionList($after:String!$first:Int!){account{propertyDefinitions(after: $after, first: $first){nodes{aliases,allowedInConfigFiles,id,name,description,displaySubtype,displayType,propertyDisplayStatus,lockedStatus,schema},{{ template "pagination_request" }}}}}`,
`{{ template "pagination_second_query_variables" }}`,
fmt.Sprintf(`{"data":{"account":{"propertyDefinitions":{"nodes":[{"aliases":["prop3"],"allowedInConfigFiles":true,"id":"XXX","name":"prop3","schema": %s}],{{ template "pagination_second_pageInfo_response" }}}}}}`, schema.ToJSON()),
fmt.Sprintf(`{"data":{"account":{"propertyDefinitions":{"nodes":[{"aliases":["prop3"],"allowedInConfigFiles":true,"id":"XXX","name":"prop3","schema": %s}],{{ template "pagination_second_pageInfo_response" }}}}}}`, schema.AsString()),
)
requests := []autopilot.TestRequest{testRequestOne, testRequestTwo}
client := BestTestClient(t, "properties/definition_list", requests...)
Expand Down

0 comments on commit ecf166c

Please sign in to comment.