Skip to content

Commit

Permalink
Generator updates
Browse files Browse the repository at this point in the history
  • Loading branch information
danischm committed May 22, 2024
1 parent d5e06cb commit 1935a86
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 4 deletions.
10 changes: 10 additions & 0 deletions internal/provider/data_source_sdwan_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package provider

// Section below is generated&owned by "gen/generator.go". //template:begin imports
import (
"context"
"fmt"
Expand All @@ -28,6 +29,10 @@ import (
"github.com/netascode/go-sdwan"
)

// End of section. //template:end imports

// Section below is generated&owned by "gen/generator.go". //template:begin model

// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &DeviceDataSource{}
Expand Down Expand Up @@ -116,6 +121,9 @@ func (d *DeviceDataSource) Configure(_ context.Context, req datasource.Configure
d.client = req.ProviderData.(*SdwanProviderData).Client
}

// End of section. //template:end model

// Section below is generated&owned by "gen/generator.go". //template:begin read
func (d *DeviceDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config Device

Expand Down Expand Up @@ -149,3 +157,5 @@ func (d *DeviceDataSource) Read(ctx context.Context, req datasource.ReadRequest,
diags = resp.State.Set(ctx, &config)
resp.Diagnostics.Append(diags...)
}

// End of section. //template:end read
18 changes: 15 additions & 3 deletions internal/provider/data_source_sdwan_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,26 @@

package provider

// Section below is generated&owned by "gen/generator.go". //template:begin imports
import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

// End of section. //template:end imports

// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSource
func TestAccDataSourceSdwanDevice(t *testing.T) {
if os.Getenv("SDWAN_209") == "" {
t.Skip("skipping test, set environment variable SDWAN_209")
}
var checks []resource.TestCheckFunc
checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_device.test", "devices.0.device_id", "100.0.0.101"))
checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_device.test", "devices.0.uuid", "103989be-2fa6-4afc-bfa8-179c4ed63f39"))
checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_device.test", "devices.0.uuid", "a59581e3-8afd-4ccb-9730-bc3710ec288e"))
checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_device.test", "devices.0.site_id", "100"))
checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_device.test", "devices.0.serial_number", "0DFF93B792354B08ABE5E43566347F09"))
checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_device.test", "devices.0.serial_number", "3FFEFB37892E415FAF34A95D2328EC4C"))
checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_device.test", "devices.0.hostname", "Controller01"))
checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_device.test", "devices.0.reachability", "reachable"))
checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_device.test", "devices.0.status", "normal"))
Expand All @@ -49,14 +53,22 @@ func TestAccDataSourceSdwanDevice(t *testing.T) {
})
}

// End of section. //template:end testAccDataSource

// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites
// End of section. //template:end testPrerequisites

// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig
func testAccDataSourceSdwanDeviceConfig() string {
config := ""

config += `
data "sdwan_device" "test" {
serial_number = "0DFF93B792354B08ABE5E43566347F09"
serial_number = "3FFEFB37892E415FAF34A95D2328EC4C"
name = "Controller01"
}
`
return config
}

// End of section. //template:end testAccDataSourceConfig
10 changes: 10 additions & 0 deletions internal/provider/data_source_sdwan_vedge_inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package provider

// Section below is generated&owned by "gen/generator.go". //template:begin imports
import (
"context"
"fmt"
Expand All @@ -27,6 +28,10 @@ import (
"github.com/netascode/go-sdwan"
)

// End of section. //template:end imports

// Section below is generated&owned by "gen/generator.go". //template:begin model

// Ensure the implementation satisfies the expected interfaces.
var (
_ datasource.DataSource = &VEdgeInventoryDataSource{}
Expand Down Expand Up @@ -99,6 +104,9 @@ func (d *VEdgeInventoryDataSource) Configure(_ context.Context, req datasource.C
d.client = req.ProviderData.(*SdwanProviderData).Client
}

// End of section. //template:end model

// Section below is generated&owned by "gen/generator.go". //template:begin read
func (d *VEdgeInventoryDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var config VEdgeInventory

Expand Down Expand Up @@ -126,3 +134,5 @@ func (d *VEdgeInventoryDataSource) Read(ctx context.Context, req datasource.Read
diags = resp.State.Set(ctx, &config)
resp.Diagnostics.Append(diags...)
}

// End of section. //template:end read
14 changes: 13 additions & 1 deletion internal/provider/data_source_sdwan_vedge_inventory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@

package provider

// Section below is generated&owned by "gen/generator.go". //template:begin imports
import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

// End of section. //template:end imports

// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSource
func TestAccDataSourceSdwanVEdgeInventory(t *testing.T) {
if os.Getenv("SDWAN_209") == "" {
t.Skip("skipping test, set environment variable SDWAN_209")
}
var checks []resource.TestCheckFunc
checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_vedge_inventory.test", "devices.0.chassis_number", "C8K-40C0CCFD-9EA8-2B2E-E73B-32C5924EC79B"))
checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_vedge_inventory.test", "devices.0.serial_number", "8420F3EE"))
checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_vedge_inventory.test", "devices.0.serial_number", "F57E6428"))
checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_vedge_inventory.test", "devices.0.device_type", "vedge"))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -44,6 +48,12 @@ func TestAccDataSourceSdwanVEdgeInventory(t *testing.T) {
})
}

// End of section. //template:end testAccDataSource

// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites
// End of section. //template:end testPrerequisites

// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig
func testAccDataSourceSdwanVEdgeInventoryConfig() string {
config := ""

Expand All @@ -53,3 +63,5 @@ func testAccDataSourceSdwanVEdgeInventoryConfig() string {
`
return config
}

// End of section. //template:end testAccDataSourceConfig
22 changes: 22 additions & 0 deletions internal/provider/model_sdwan_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package provider

// Section below is generated&owned by "gen/generator.go". //template:begin imports
import (
"context"

Expand All @@ -25,6 +26,9 @@ import (
"github.com/tidwall/sjson"
)

// End of section. //template:end imports

// Section below is generated&owned by "gen/generator.go". //template:begin types
type Device struct {
Id types.String `tfsdk:"id"`
SerialNumber types.String `tfsdk:"serial_number"`
Expand All @@ -43,10 +47,16 @@ type DeviceDevices struct {
State types.String `tfsdk:"state"`
}

// End of section. //template:end types

// Section below is generated&owned by "gen/generator.go". //template:begin getPath
func (data Device) getPath() string {
return "/device"
}

// End of section. //template:end getPath

// Section below is generated&owned by "gen/generator.go". //template:begin toBody
func (data Device) toBody(ctx context.Context) string {
body := ""
if !data.SerialNumber.IsNull() {
Expand Down Expand Up @@ -89,6 +99,9 @@ func (data Device) toBody(ctx context.Context) string {
return body
}

// End of section. //template:end toBody

// Section below is generated&owned by "gen/generator.go". //template:begin fromBody
func (data *Device) fromBody(ctx context.Context, res gjson.Result) {
if value := res.Get("board-serial"); value.Exists() {
data.SerialNumber = types.StringValue(value.String())
Expand Down Expand Up @@ -154,6 +167,9 @@ func (data *Device) fromBody(ctx context.Context, res gjson.Result) {
}
}

// End of section. //template:end fromBody

// Section below is generated&owned by "gen/generator.go". //template:begin hasChanges
func (data *Device) hasChanges(ctx context.Context, state *Device) bool {
hasChanges := false
if !data.SerialNumber.Equal(state.SerialNumber) {
Expand Down Expand Up @@ -194,3 +210,9 @@ func (data *Device) hasChanges(ctx context.Context, state *Device) bool {
}
return hasChanges
}

// End of section. //template:end hasChanges

// Section below is generated&owned by "gen/generator.go". //template:begin updateVersions

// End of section. //template:end updateVersions
22 changes: 22 additions & 0 deletions internal/provider/model_sdwan_vedge_inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package provider

// Section below is generated&owned by "gen/generator.go". //template:begin imports
import (
"context"

Expand All @@ -25,6 +26,9 @@ import (
"github.com/tidwall/sjson"
)

// End of section. //template:end imports

// Section below is generated&owned by "gen/generator.go". //template:begin types
type VEdgeInventory struct {
Id types.String `tfsdk:"id"`
Devices []VEdgeInventoryDevices `tfsdk:"devices"`
Expand All @@ -39,10 +43,16 @@ type VEdgeInventoryDevices struct {
DeviceType types.String `tfsdk:"device_type"`
}

// End of section. //template:end types

// Section below is generated&owned by "gen/generator.go". //template:begin getPath
func (data VEdgeInventory) getPath() string {
return "/device/vedgeinventory/detail"
}

// End of section. //template:end getPath

// Section below is generated&owned by "gen/generator.go". //template:begin toBody
func (data VEdgeInventory) toBody(ctx context.Context) string {
body := ""
if true {
Expand Down Expand Up @@ -73,6 +83,9 @@ func (data VEdgeInventory) toBody(ctx context.Context) string {
return body
}

// End of section. //template:end toBody

// Section below is generated&owned by "gen/generator.go". //template:begin fromBody
func (data *VEdgeInventory) fromBody(ctx context.Context, res gjson.Result) {
if value := res.Get("data"); value.Exists() && len(value.Array()) > 0 {
data.Devices = make([]VEdgeInventoryDevices, 0)
Expand Down Expand Up @@ -118,6 +131,9 @@ func (data *VEdgeInventory) fromBody(ctx context.Context, res gjson.Result) {
}
}

// End of section. //template:end fromBody

// Section below is generated&owned by "gen/generator.go". //template:begin hasChanges
func (data *VEdgeInventory) hasChanges(ctx context.Context, state *VEdgeInventory) bool {
hasChanges := false
if len(data.Devices) != len(state.Devices) {
Expand Down Expand Up @@ -146,3 +162,9 @@ func (data *VEdgeInventory) hasChanges(ctx context.Context, state *VEdgeInventor
}
return hasChanges
}

// End of section. //template:end hasChanges

// Section below is generated&owned by "gen/generator.go". //template:begin updateVersions

// End of section. //template:end updateVersions

0 comments on commit 1935a86

Please sign in to comment.