-
Notifications
You must be signed in to change notification settings - Fork 14
Replace Viper with encoding/json for config loading #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,8 +1,10 @@ | ||||||
| package config | ||||||
|
|
||||||
| import ( | ||||||
| "fmt" | ||||||
| "os" | ||||||
| "path/filepath" | ||||||
| "sort" | ||||||
| "strings" | ||||||
| "testing" | ||||||
| ) | ||||||
|
|
@@ -1069,6 +1071,128 @@ func TestAuthenticationMethodValidation(t *testing.T) { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| // baseAzureJSON is the minimal valid azure config block shared across label tests. | ||||||
| const baseAzureJSON = `{ | ||||||
| "azure": { | ||||||
| "subscriptionId": "12345678-1234-1234-1234-123456789012", | ||||||
| "tenantId": "12345678-1234-1234-1234-123456789012", | ||||||
| "cloud": "AzurePublicCloud", | ||||||
| "bootstrapToken": { "token": "abcdef.0123456789abcdef" }, | ||||||
| "targetCluster": { | ||||||
| "resourceId": "/subscriptions/12345678-1234-1234-1234-123456789012/resourceGroups/test-rg/providers/Microsoft.ContainerService/managedClusters/test-cluster", | ||||||
| "location": "eastus" | ||||||
| } | ||||||
| }, | ||||||
| "node": { | ||||||
| "kubelet": { | ||||||
| "serverURL": "https://test-cluster.hcp.eastus.azmk8s.io:443", | ||||||
| "caCertData": "LS0tLS1CRUdJTi1DRVJUSUZJQ0FURS0tLS0t" | ||||||
| }, | ||||||
| "labels": %s | ||||||
| } | ||||||
| }` | ||||||
|
|
||||||
| // TestLoadConfigNodeLabels verifies that node label keys are preserved exactly | ||||||
| // as written in the config file. This is the root motivation: Kubernetes label | ||||||
| // keys such as "cleanroom.azure.com/flexnode" or "topology.kubernetes.io/zone" | ||||||
| // contain dots, which Viper's default "." key-path delimiter misinterpreted as | ||||||
| // nested JSON keys, silently dropping the labels on load. | ||||||
| func TestLoadConfigNodeLabels(t *testing.T) { | ||||||
| tests := []struct { | ||||||
| name string | ||||||
| labelsJSON string | ||||||
| expectedLabels map[string]string // only the user-supplied labels; defaults are checked separately | ||||||
|
||||||
| expectedLabels map[string]string // only the user-supplied labels; defaults are checked separately | |
| expectedLabels map[string]string // labels expected to be preserved from the config file |
Copilot
AI
Apr 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t.Parallel() inside a range loop subtest captures the loop variable tt. On Go versions prior to 1.22 this can cause all parallel subtests to read the final tt value (flaky/incorrect assertions). Rebind tt := tt (or index into the slice) before t.Run to make the tests correct across Go versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
json.Unmarshalsilently ignores unknown fields, which can allow config typos to go unnoticed (potentially leading to confusing runtime behavior). Consider decoding viajson.DecoderwithDisallowUnknownFields()and returning an error that includes theconfigPathto make misconfigurations easier to diagnose.