Skip to content

Commit

Permalink
Fix UCI type for wireless.wifi-device
Browse files Browse the repository at this point in the history
This typo is everything that's wrong with UCI. There's no consistency in
the naming scheme. And, there's nothing stopping you from using the
incorrect UCI type. Nothing failed for any of the tests here because at
its core, UCI allows basically any config to have any name with any
section with any options. It's way too lenient, and it means that you
have to be extra careful whenever you're using it directly (like we're
doing here).

If there's a way to accurately test that we're using the correct thing,
we should switch to it. But, it's not clear how we'd actually catch a
mistake like this.

In any case, we fix this typo, so a `wireless.wifi-device` can actually
be created now.

Branch: joneshf/fix-uci-type-for-wireless-wifi-device
Pull-Request: #124
  • Loading branch information
joneshf authored Apr 3, 2023
1 parent 9503ae6 commit 39cc576
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion openwrt/internal/lucirpcglue/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lucirpcglue
import (
"context"
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
Expand Down Expand Up @@ -133,5 +134,7 @@ func (d *dataSource[Model]) Schema(
func (d dataSource[Model]) getFullTypeName(
providerTypeName string,
) string {
return fmt.Sprintf("%s_%s_%s", providerTypeName, d.uciConfig, d.uciType)
uciConfig := strings.ReplaceAll(d.uciConfig, "-", "_")
uciType := strings.ReplaceAll(d.uciType, "-", "_")
return fmt.Sprintf("%s_%s_%s", providerTypeName, uciConfig, uciType)
}
5 changes: 4 additions & 1 deletion openwrt/internal/lucirpcglue/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lucirpcglue
import (
"context"
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-framework/path"
frameworkresource "github.com/hashicorp/terraform-plugin-framework/resource"
Expand Down Expand Up @@ -307,5 +308,7 @@ func (d *resource[Model]) Update(
func (d resource[Model]) getFullTypeName(
providerTypeName string,
) string {
return fmt.Sprintf("%s_%s_%s", providerTypeName, d.uciConfig, d.uciType)
uciConfig := strings.ReplaceAll(d.uciConfig, "-", "_")
uciType := strings.ReplaceAll(d.uciType, "-", "_")
return fmt.Sprintf("%s_%s_%s", providerTypeName, uciConfig, uciType)
}
2 changes: 1 addition & 1 deletion openwrt/wireless/wifidevice/wifi_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const (
typeUCIOption = "type"

uciConfig = "wireless"
uciType = "wifi_device"
uciType = "wifi-device"
)

var (
Expand Down

0 comments on commit 39cc576

Please sign in to comment.