Skip to content

Commit f926a23

Browse files
committed
Align CLI commands with updated spec and API
1 parent a39107c commit f926a23

File tree

4 files changed

+370
-99
lines changed

4 files changed

+370
-99
lines changed

apptrust/commands/utils/utils_test.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -115,40 +115,6 @@ func TestValidateEnumFlag(t *testing.T) {
115115
}
116116
}
117117

118-
func TestParsePackagesFlag(t *testing.T) {
119-
tests := []struct {
120-
name string
121-
input string
122-
expected []map[string]string
123-
expectErr bool
124-
}{
125-
{"empty string", "", nil, false},
126-
{"single package", "foo:1.0.0", []map[string]string{{"name": "foo", "version": "1.0.0"}}, false},
127-
{"multiple packages", "foo:1.0.0,bar:2.0.0", []map[string]string{{"name": "foo", "version": "1.0.0"}, {"name": "bar", "version": "2.0.0"}}, false},
128-
{"spaces", " foo:1.0.0 , bar:2.0.0 ", []map[string]string{{"name": "foo", "version": "1.0.0"}, {"name": "bar", "version": "2.0.0"}}, false},
129-
{"invalid format", "foo", nil, true},
130-
{"missing version", "foo:", []map[string]string{{"name": "foo", "version": ""}}, false},
131-
{"missing name", ":1.0.0", []map[string]string{{"name": "", "version": "1.0.0"}}, false},
132-
}
133-
for _, tt := range tests {
134-
t.Run(tt.name, func(t *testing.T) {
135-
result, err := ParsePackagesFlag(tt.input)
136-
if tt.expectErr {
137-
if err == nil {
138-
t.Errorf("expected error for input %q, got nil", tt.input)
139-
}
140-
return
141-
}
142-
if err != nil {
143-
t.Errorf("unexpected error for input %q: %v", tt.input, err)
144-
}
145-
if !reflect.DeepEqual(result, tt.expected) {
146-
t.Errorf("ParsePackagesFlag(%q) = %v, want %v", tt.input, result, tt.expected)
147-
}
148-
})
149-
}
150-
}
151-
152118
func TestParseDelimitedSlice(t *testing.T) {
153119
tests := []struct {
154120
name string

apptrust/commands/version/create_app_version_cmd.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package version
33
import (
44
"encoding/json"
55
"strconv"
6+
"strings"
67

78
"github.com/jfrog/jfrog-cli-application/apptrust/service/versions"
89

@@ -164,6 +165,10 @@ func (cv *createAppVersionCommand) parseBuilds(buildsStr string) ([]model.Create
164165
if err != nil {
165166
return nil, errorutils.CheckErrorf("invalid build format: %v", err)
166167
}
168+
err = validateRequiredFieldsInMap(buildEntryMap, nameField, idField)
169+
if err != nil {
170+
return nil, errorutils.CheckErrorf("invalid build format: %v", err)
171+
}
167172
build := model.CreateVersionBuild{
168173
Name: buildEntryMap[nameField],
169174
Number: buildEntryMap[idField],
@@ -193,6 +198,10 @@ func (cv *createAppVersionCommand) parseReleaseBundles(rbStr string) ([]model.Cr
193198
if err != nil {
194199
return nil, errorutils.CheckErrorf("invalid release bundle format: %v", err)
195200
}
201+
err = validateRequiredFieldsInMap(releaseBundleEntryMap, nameField, versionField)
202+
if err != nil {
203+
return nil, errorutils.CheckErrorf("invalid release bundle format: %v", err)
204+
}
196205
bundles = append(bundles, model.CreateVersionReleaseBundle{
197206
Name: releaseBundleEntryMap[nameField],
198207
Version: releaseBundleEntryMap[versionField],
@@ -214,6 +223,10 @@ func (cv *createAppVersionCommand) parseSourceVersions(applicationVersionsStr st
214223
if err != nil {
215224
return nil, errorutils.CheckErrorf("invalid application version format: %v", err)
216225
}
226+
err = validateRequiredFieldsInMap(applicationVersionEntryMap, applicationKeyField, versionField)
227+
if err != nil {
228+
return nil, errorutils.CheckErrorf("invalid application version format: %v", err)
229+
}
217230
refs = append(refs, model.CreateVersionReference{
218231
ApplicationKey: applicationVersionEntryMap[applicationKeyField],
219232
Version: applicationVersionEntryMap[versionField],
@@ -284,3 +297,15 @@ func validateNoSpecAndFlagsTogether(ctx *components.Context) error {
284297
}
285298
return nil
286299
}
300+
301+
func validateRequiredFieldsInMap(m map[string]string, requiredFields ...string) error {
302+
if m == nil {
303+
return errorutils.CheckErrorf("missing required fields: %v", strings.Join(requiredFields, ", "))
304+
}
305+
for _, field := range requiredFields {
306+
if _, exists := m[field]; !exists {
307+
return errorutils.CheckErrorf("missing required field: %s", field)
308+
}
309+
}
310+
return nil
311+
}

0 commit comments

Comments
 (0)