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

UiPath / uipathcli / 14471669139

15 Apr 2025 02:13PM UTC coverage: 90.311% (+0.2%) from 90.124%
14471669139

Pull #176

github

thschmitt
Split tests by plugin command and move commands into separate folders

There are quite a lot of studio plugin tests. Refactored the tests and
moved them into a separate test file per command. This makes it easier
to have an overview of the existing tests for a particular command.

Also split up the large studio plugin package into separate folders for
each command.
Pull Request #176: Split tests by plugin command and move commands into separate folders

107 of 127 new or added lines in 11 files covered. (84.25%)

2 existing lines in 1 file now uncovered.

6133 of 6791 relevant lines covered (90.31%)

1.01 hits per line

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

87.5
/plugin/studio/studio_project_reader.go
1
package studio
2

3
import (
4
        "encoding/json"
5
        "fmt"
6
        "io"
7
        "os"
8
        "strings"
9
)
10

11
const DefaultProjectJson = "project.json"
12

13
type StudioProjectReader struct {
14
        Path string
15
}
16

17
func (r StudioProjectReader) ReadMetadata() (StudioProject, error) {
1✔
18
        data, err := r.readProjectJson()
1✔
19
        if err != nil {
2✔
20
                return StudioProject{}, err
1✔
21
        }
1✔
22
        var projectJson studioProjectJson
1✔
23
        err = json.Unmarshal(data, &projectJson)
1✔
24
        if err != nil {
2✔
25
                return StudioProject{}, fmt.Errorf("Error parsing %s file: %v", DefaultProjectJson, err)
1✔
26
        }
1✔
27
        project := NewStudioProject(
1✔
28
                projectJson.Name,
1✔
29
                projectJson.Description,
1✔
30
                projectJson.ProjectId,
1✔
31
                r.convertToTargetFramework(projectJson.TargetFramework))
1✔
32
        return *project, nil
1✔
33
}
34

35
func (r StudioProjectReader) convertToTargetFramework(targetFramework string) TargetFramework {
1✔
36
        if strings.EqualFold(targetFramework, "legacy") {
2✔
37
                return TargetFrameworkLegacy
1✔
38
        }
1✔
39
        if strings.EqualFold(targetFramework, "windows") {
2✔
40
                return TargetFrameworkWindows
1✔
41
        }
1✔
42
        return TargetFrameworkCrossPlatform
1✔
43
}
44

45
func (r StudioProjectReader) AddToIgnoredFiles(fileName string) error {
1✔
46
        data, err := r.readProjectJson()
1✔
47
        if err != nil {
2✔
48
                return err
1✔
49
        }
1✔
50
        var result interface{}
1✔
51
        err = json.Unmarshal(data, &result)
1✔
52
        if err != nil {
2✔
53
                return fmt.Errorf("Error parsing %s file: %v", DefaultProjectJson, err)
1✔
54
        }
1✔
55

56
        changed, err := r.addToIgnoredFiles(result.(map[string]interface{}), fileName)
1✔
57
        if err != nil {
2✔
58
                return fmt.Errorf("Error updating %s file: %v", DefaultProjectJson, err)
1✔
59
        }
1✔
60
        if !changed {
2✔
61
                return nil
1✔
62
        }
1✔
63
        return r.updateProjectJson(result)
1✔
64
}
65

66
func (r StudioProjectReader) readProjectJson() ([]byte, error) {
1✔
67
        file, err := os.Open(r.Path)
1✔
68
        if err != nil {
2✔
69
                return nil, fmt.Errorf("Error reading %s file: %v", DefaultProjectJson, err)
1✔
70
        }
1✔
71
        defer file.Close()
1✔
72
        data, err := io.ReadAll(file)
1✔
73
        if err != nil {
1✔
NEW
74
                return nil, fmt.Errorf("Error reading %s file: %v", DefaultProjectJson, err)
×
75
        }
×
76
        return data, err
1✔
77
}
78

79
func (r StudioProjectReader) updateProjectJson(result interface{}) error {
1✔
80
        updated, err := json.Marshal(result)
1✔
81
        if err != nil {
1✔
NEW
82
                return fmt.Errorf("Error updating %s file: %v", DefaultProjectJson, err)
×
83
        }
×
84
        fileInfo, err := os.Stat(r.Path)
1✔
85
        if err != nil {
1✔
NEW
86
                return fmt.Errorf("Error updating %s file: %v", DefaultProjectJson, err)
×
87
        }
×
88
        err = os.WriteFile(r.Path, updated, fileInfo.Mode())
1✔
89
        if err != nil {
1✔
NEW
90
                return fmt.Errorf("Error updating %s file: %v", DefaultProjectJson, err)
×
91
        }
×
92
        return nil
1✔
93
}
94

95
func (r StudioProjectReader) addToIgnoredFiles(result map[string]interface{}, fileName string) (bool, error) {
1✔
96
        designOptions, err := r.createObjectField(result, "designOptions")
1✔
97
        if err != nil {
1✔
98
                return false, err
×
99
        }
×
100
        processOptions, err := r.createObjectField(designOptions, "processOptions")
1✔
101
        if err != nil {
1✔
102
                return false, err
×
103
        }
×
104
        ignoredFiles, err := r.createArrayField(processOptions, "ignoredFiles")
1✔
105
        if err != nil {
2✔
106
                return false, err
1✔
107
        }
1✔
108
        if r.isFileNameIgnored(ignoredFiles, fileName) {
2✔
109
                return false, nil
1✔
110
        }
1✔
111
        processOptions["ignoredFiles"] = append(ignoredFiles, fileName)
1✔
112
        return true, nil
1✔
113
}
114

115
func (r StudioProjectReader) createObjectField(result map[string]interface{}, fieldName string) (map[string]interface{}, error) {
1✔
116
        if _, ok := result[fieldName]; !ok {
2✔
117
                result[fieldName] = map[string]interface{}{}
1✔
118
        }
1✔
119
        field, ok := result[fieldName].(map[string]interface{})
1✔
120
        if !ok {
1✔
121
                return nil, fmt.Errorf("Unexpected type for field '%s'", fieldName)
×
122
        }
×
123
        return field, nil
1✔
124
}
125

126
func (r StudioProjectReader) createArrayField(result map[string]interface{}, fieldName string) ([]interface{}, error) {
1✔
127
        if _, ok := result[fieldName]; !ok {
2✔
128
                result[fieldName] = []interface{}{}
1✔
129
        }
1✔
130
        field, ok := result[fieldName].([]interface{})
1✔
131
        if !ok {
2✔
132
                return nil, fmt.Errorf("Unexpected type for field '%s'", fieldName)
1✔
133
        }
1✔
134
        return field, nil
1✔
135
}
136

137
func (r StudioProjectReader) isFileNameIgnored(ignoredFiles []interface{}, fileName string) bool {
1✔
138
        for _, ignoredFile := range ignoredFiles {
2✔
139
                if ignoredFile == fileName {
2✔
140
                        return true
1✔
141
                }
1✔
142
        }
143
        return false
1✔
144
}
145

146
func NewStudioProjectReader(path string) *StudioProjectReader {
1✔
147
        return &StudioProjectReader{path}
1✔
148
}
1✔
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