Skip to content

Commit 94b2e8f

Browse files
authored
Merge pull request #950 from meshery/copilot/fix-failing-go-tests
Fix failing Go tests
2 parents 8c26fbe + c1207f0 commit 94b2e8f

8 files changed

Lines changed: 185 additions & 157 deletions

File tree

converter/tests/samples/edge-firewall-relationship.yml

Lines changed: 94 additions & 94 deletions
Large diffs are not rendered by default.
3.5 KB
Binary file not shown.

files/tests/samples/valid_design.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ components:
4040
registrant:
4141
created_at: 2025-01-27T22:09:21.794655001Z
4242
credential_id: 00000000-0000-0000-0000-000000000000
43-
deleted_at: 0001-01-01T00:00:00Z
43+
deleted_at: null
4444
id: 9e04779c-94b6-6a03-575c-66f4c57541eb
4545
kind: github
4646
name: Github
@@ -220,7 +220,7 @@ components:
220220
registrant:
221221
created_at: 2025-01-27T22:09:21.794655001Z
222222
credential_id: 00000000-0000-0000-0000-000000000000
223-
deleted_at: 0001-01-01T00:00:00Z
223+
deleted_at: null
224224
id: 9e04779c-94b6-6a03-575c-66f4c57541eb
225225
kind: github
226226
name: Github
@@ -288,16 +288,16 @@ relationships:
288288
version: v1.32.0-alpha.3
289289
name: kubernetes
290290
registrant:
291-
created_at: 0001-01-01T00:00:00Z
291+
created_at: null
292292
credential_id: 00000000-0000-0000-0000-000000000000
293-
deleted_at: 0001-01-01T00:00:00Z
293+
deleted_at: null
294294
id: 00000000-0000-0000-0000-000000000000
295295
kind: ""
296296
name: ""
297297
status: ""
298298
sub_type: ""
299299
type: ""
300-
updated_at: 0001-01-01T00:00:00Z
300+
updated_at: null
301301
user_id: 00000000-0000-0000-0000-000000000000
302302
connection_id: 9e04779c-94b6-6a03-575c-66f4c57541eb
303303
schemaVersion: models.meshery.io/v1beta1
@@ -326,16 +326,16 @@ relationships:
326326
version: ""
327327
name: '*'
328328
registrant:
329-
created_at: 0001-01-01T00:00:00Z
329+
created_at: null
330330
credential_id: 00000000-0000-0000-0000-000000000000
331-
deleted_at: 0001-01-01T00:00:00Z
331+
deleted_at: null
332332
id: 00000000-0000-0000-0000-000000000000
333333
kind: ""
334334
name: ""
335335
status: ""
336336
sub_type: ""
337337
type: ""
338-
updated_at: 0001-01-01T00:00:00Z
338+
updated_at: null
339339
user_id: 00000000-0000-0000-0000-000000000000
340340
connection_id: 00000000-0000-0000-0000-000000000000
341341
schemaVersion: ""
@@ -365,16 +365,16 @@ relationships:
365365
version: ""
366366
name: kubernetes
367367
registrant:
368-
created_at: 0001-01-01T00:00:00Z
368+
created_at: null
369369
credential_id: 00000000-0000-0000-0000-000000000000
370-
deleted_at: 0001-01-01T00:00:00Z
370+
deleted_at: null
371371
id: 00000000-0000-0000-0000-000000000000
372372
kind: github
373373
name: ""
374374
status: ""
375375
sub_type: ""
376376
type: ""
377-
updated_at: 0001-01-01T00:00:00Z
377+
updated_at: null
378378
user_id: 00000000-0000-0000-0000-000000000000
379379
connection_id: 00000000-0000-0000-0000-000000000000
380380
schemaVersion: ""

generators/github/package_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func TestGenerateCompFromGitHub(t *testing.T) {
4040

4141
{ // Source pointing to a directly downloadable file (not a repo per se)
4242
ghPackageManager: GitHubPackageManager{
43-
PackageName: "k8s-config-connector",
44-
SourceURL: "https://raw.githubusercontent.com/GoogleCloudPlatform/k8s-config-connector/master/crds/alloydb_v1beta1_alloydbbackup.yaml",
43+
PackageName: "gateway-api",
44+
SourceURL: "https://raw.githubusercontent.com/kubernetes-sigs/gateway-api/main/config/crd/standard/gateway.networking.k8s.io_gatewayclasses.yaml",
4545
},
4646
want: 1,
4747
},

models/meshmodel/core/policies/rego_policy_relationship.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import (
2020
var SyncRelationship sync.Mutex
2121

2222
type Rego struct {
23-
store storagepkg.Store
24-
txn storagepkg.Transaction
25-
ctx context.Context
26-
policyDir string
23+
store storagepkg.Store
24+
txn storagepkg.Transaction
25+
ctx context.Context
26+
policyDir string
2727
}
2828

2929
// NewRegoInstance creates a new Rego evaluator with relationships loaded
@@ -52,7 +52,7 @@ func NewRegoInstance(policyDir string, regManager *registry.RegistryManager) (*R
5252
}
5353

5454
// CustomPrint implements the print.Hook interface to capture print statements
55-
type CustomPrint struct{
55+
type CustomPrint struct {
5656
Messages []string
5757
}
5858

@@ -136,7 +136,7 @@ func (r *Rego) RegoPolicyHandler(
136136
for _, comp := range resp.Design.Components {
137137
var patches []patching.Patch
138138
for _, up := range updates {
139-
if up.Id == comp.Id.String() {
139+
if up.Id == comp.ID.String() {
140140
patches = append(patches, patching.Patch{Path: up.Path[1:], Value: up.Value})
141141
}
142142
}

orchestration/design.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func EnrichComponentWithMesheryMetadata(comp *component.ComponentDefinition, des
4545
// Assign the new label
4646
labels[ResourceSourceDesignIdLabelKey] = designId
4747
annotations[ResourceSourceDesignVersionLabelKey] = designVersion
48-
annotations[ResourceSourceComponentIdLabelKey] = comp.Id.String()
48+
annotations[ResourceSourceComponentIdLabelKey] = comp.ID.String()
4949

5050
return nil
5151
}

registry/component.go

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
package registry
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"os"
67
"path/filepath"
78
"strconv"
89
"strings"
9-
"encoding/json"
1010

1111
"github.com/meshery/meshkit/encoding"
1212
"github.com/meshery/meshkit/files"
1313
"github.com/meshery/meshkit/models/meshmodel/entity"
1414
"github.com/meshery/meshkit/utils"
1515
"github.com/meshery/meshkit/utils/csv"
1616
"github.com/meshery/meshkit/utils/manifests"
17+
"github.com/meshery/schemas"
1718
"github.com/meshery/schemas/models/v1alpha1/capability"
19+
corev1alpha1 "github.com/meshery/schemas/models/v1alpha1/core"
1820
schmeaVersion "github.com/meshery/schemas/models/v1beta1"
1921
"github.com/meshery/schemas/models/v1beta1/component"
20-
"github.com/meshery/schemas"
2122
)
2223

2324
const (
@@ -123,7 +124,9 @@ func (c *ComponentCSV) UpdateCompDefinition(compDef *component.ComponentDefiniti
123124
if c.Capabilities != "" && c.Capabilities != "null" {
124125
err := encoding.Unmarshal([]byte(c.Capabilities), &capabilities)
125126
if err != nil {
126-
Log.Error(err)
127+
if Log != nil {
128+
Log.Error(err)
129+
}
127130
defaultCapabilities, defaultErr := getMinimalUICapabilitiesFromSchema()
128131
if defaultErr == nil {
129132
capabilities = defaultCapabilities
@@ -132,7 +135,9 @@ func (c *ComponentCSV) UpdateCompDefinition(compDef *component.ComponentDefiniti
132135
} else {
133136
defaultCapabilities, err := getMinimalUICapabilitiesFromSchema()
134137
if err != nil {
135-
Log.Error(err)
138+
if Log != nil {
139+
Log.Error(err)
140+
}
136141
} else {
137142
capabilities = defaultCapabilities
138143
}
@@ -176,7 +181,7 @@ func (c *ComponentCSV) UpdateCompDefinition(compDef *component.ComponentDefiniti
176181
for _, key := range compStyleValues {
177182
if c.Shape != "" {
178183
shape := c.Shape
179-
compDefStyles.Shape = (*component.ComponentDefinitionStylesShape)(&shape)
184+
compDefStyles.Shape = (*corev1alpha1.Shape)(&shape)
180185
}
181186
if c.PrimaryColor != "" {
182187

@@ -210,8 +215,6 @@ func (c *ComponentCSV) UpdateCompDefinition(compDef *component.ComponentDefiniti
210215
return nil
211216
}
212217

213-
214-
215218
type ComponentCSVHelper struct {
216219
SpreadsheetID int64
217220
SpreadsheetURL string
@@ -465,43 +468,42 @@ func getSVGForComponent(model ModelCSV, component ComponentCSV) (colorSVG string
465468
return
466469
}
467470

468-
469471
func getMinimalUICapabilitiesFromSchema() ([]capability.Capability, error) {
470-
schema, err := schemas.Schemas.ReadFile("schemas/constructs/v1beta1/component/component.json")
471-
if err != nil {
472-
return nil, fmt.Errorf("failed to read component schema: %v", err)
473-
}
474-
475-
capabilitiesJSON, err := extractCapabilitiesJSONFromSchema(schema)
476-
if err != nil {
477-
return nil, fmt.Errorf("failed to extract capabilities from schema: %v", err)
478-
}
479-
480-
var allCapabilities []capability.Capability
481-
if err := json.Unmarshal(capabilitiesJSON, &allCapabilities); err != nil {
482-
return nil, fmt.Errorf("failed to unmarshal capabilities: %v", err)
483-
}
484-
485-
if len(allCapabilities) >= 3 {
486-
return allCapabilities[len(allCapabilities)-3:], nil
487-
}
488-
489-
return nil, fmt.Errorf("insufficient default capabilities in schema, found %d", len(allCapabilities))
472+
schema, err := schemas.Schemas.ReadFile("schemas/constructs/v1beta1/component/component.yaml")
473+
if err != nil {
474+
return nil, fmt.Errorf("failed to read component schema: %v", err)
475+
}
476+
477+
capabilitiesJSON, err := extractCapabilitiesJSONFromSchema(schema)
478+
if err != nil {
479+
return nil, fmt.Errorf("failed to extract capabilities from schema: %v", err)
480+
}
481+
482+
var allCapabilities []capability.Capability
483+
if err := json.Unmarshal(capabilitiesJSON, &allCapabilities); err != nil {
484+
return nil, fmt.Errorf("failed to unmarshal capabilities: %v", err)
485+
}
486+
487+
if len(allCapabilities) >= 3 {
488+
return allCapabilities[len(allCapabilities)-3:], nil
489+
}
490+
491+
return nil, fmt.Errorf("insufficient default capabilities in schema, found %d", len(allCapabilities))
490492
}
491493

492494
func extractCapabilitiesJSONFromSchema(schema []byte) ([]byte, error) {
493-
var schemaMap map[string]interface{}
494-
if err := json.Unmarshal(schema, &schemaMap); err != nil {
495-
return nil, err
496-
}
497-
498-
if properties, ok := schemaMap["properties"].(map[string]interface{}); ok {
499-
if capabilitiesSchema, ok := properties["capabilities"].(map[string]interface{}); ok {
500-
if defaultValue, ok := capabilitiesSchema["default"]; ok {
501-
return json.Marshal(defaultValue)
502-
}
503-
}
504-
}
505-
506-
return nil, fmt.Errorf("default capabilities not found in schema")
507-
}
495+
var schemaMap map[string]interface{}
496+
if err := encoding.Unmarshal(schema, &schemaMap); err != nil {
497+
return nil, err
498+
}
499+
500+
if properties, ok := schemaMap["properties"].(map[string]interface{}); ok {
501+
if capabilitiesSchema, ok := properties["capabilities"].(map[string]interface{}); ok {
502+
if defaultValue, ok := capabilitiesSchema["default"]; ok {
503+
return json.Marshal(defaultValue)
504+
}
505+
}
506+
}
507+
508+
return nil, fmt.Errorf("default capabilities not found in schema")
509+
}

schema/compiler.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,29 @@ func jsonPointer(path []string) string {
209209
func escapeJSONPointerToken(token string) string {
210210
return strings.NewReplacer("~", "~0", "/", "~1").Replace(token)
211211
}
212+
213+
// keywordFromLocation extracts and unescapes the last JSON Pointer segment
214+
// from a schema location string (e.g. "#/properties/foo~1bar" → "foo/bar").
215+
// Returns an empty string when the location has no meaningful path segments.
216+
func keywordFromLocation(location string) string {
217+
// Isolate the fragment portion (after '#').
218+
_, fragment, hasFragment := strings.Cut(location, "#")
219+
if !hasFragment {
220+
fragment = location
221+
}
222+
223+
// The fragment is a JSON Pointer like "/properties/foo~1bar".
224+
// Split on "/" and take the last non-empty token.
225+
parts := strings.Split(fragment, "/")
226+
last := ""
227+
for i := len(parts) - 1; i >= 0; i-- {
228+
if parts[i] != "" {
229+
last = parts[i]
230+
break
231+
}
232+
}
233+
234+
// Unescape JSON Pointer escape sequences (~1 → /, ~0 → ~).
235+
// Order matters: ~1 must be replaced before ~0.
236+
return strings.NewReplacer("~1", "/", "~0", "~").Replace(last)
237+
}

0 commit comments

Comments
 (0)