• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NVIDIA / skyhook / 20150581929

11 Dec 2025 11:16PM UTC coverage: 77.153%. First build
20150581929

Pull #125

github

t0mmylam
feat: Consolidate CLI e2e tests with proper assertions and CI integration
Pull Request #125: feat: Create CLI e2e tests with assertions and CI integration

1085 of 1296 new or added lines in 13 files covered. (83.72%)

5724 of 7419 relevant lines covered (77.15%)

0.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.48
/operator/internal/cli/utils/utils.go
1
/*
2
 * SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3
 * SPDX-License-Identifier: Apache-2.0
4
 *
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18

19
package utils
20

21
import (
22
        "encoding/json"
23
        "fmt"
24
        "regexp"
25
        "strings"
26

27
        "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
28

29
        "github.com/NVIDIA/skyhook/operator/api/v1alpha1"
30
)
31

32
// MatchNodes matches node patterns against a list of available nodes.
33
// Patterns can be exact node names or regex patterns.
34
func MatchNodes(patterns []string, availableNodes []string) ([]string, error) {
1✔
35
        matched := make(map[string]bool)
1✔
36

1✔
37
        for _, pattern := range patterns {
2✔
38
                // Check if it's a regex pattern (contains regex metacharacters)
1✔
39
                isRegex := strings.ContainsAny(pattern, ".*+?^${}[]|()\\")
1✔
40

1✔
41
                if isRegex {
2✔
42
                        re, err := regexp.Compile("^" + pattern + "$")
1✔
43
                        if err != nil {
2✔
44
                                return nil, fmt.Errorf("invalid regex pattern %q: %w", pattern, err)
1✔
45
                        }
1✔
46

47
                        for _, node := range availableNodes {
2✔
48
                                if re.MatchString(node) {
2✔
49
                                        matched[node] = true
1✔
50
                                }
1✔
51
                        }
52
                } else {
1✔
53
                        // Exact match
1✔
54
                        for _, node := range availableNodes {
2✔
55
                                if node == pattern {
2✔
56
                                        matched[node] = true
1✔
57
                                }
1✔
58
                        }
59
                }
60
        }
61

62
        result := make([]string, 0, len(matched))
1✔
63
        for node := range matched {
2✔
64
                result = append(result, node)
1✔
65
        }
1✔
66

67
        return result, nil
1✔
68
}
69

70
// EscapeJSONPointer escapes special characters in JSON Pointer tokens
71
// per RFC 6901: ~ becomes ~0, / becomes ~1
72
func EscapeJSONPointer(s string) string {
1✔
73
        s = strings.ReplaceAll(s, "~", "~0")
1✔
74
        s = strings.ReplaceAll(s, "/", "~1")
1✔
75
        return s
1✔
76
}
1✔
77

78
// UnstructuredToSkyhook converts an unstructured object to a Skyhook.
79
func UnstructuredToSkyhook(u *unstructured.Unstructured) (*v1alpha1.Skyhook, error) {
1✔
80
        data, err := u.MarshalJSON()
1✔
81
        if err != nil {
1✔
NEW
82
                return nil, fmt.Errorf("marshaling unstructured: %w", err)
×
NEW
83
        }
×
84

85
        var skyhook v1alpha1.Skyhook
1✔
86
        if err := json.Unmarshal(data, &skyhook); err != nil {
1✔
NEW
87
                return nil, fmt.Errorf("unmarshaling to skyhook: %w", err)
×
NEW
88
        }
×
89

90
        return &skyhook, nil
1✔
91
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc