Skip to content
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

Internal API - Create spec from variables #1303

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion common/spec/specfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package spec

import (
"encoding/json"

"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-client-go/artifactory/services/utils"
clientutils "github.com/jfrog/jfrog-client-go/utils"
Expand Down Expand Up @@ -39,6 +38,23 @@ func CreateSpecFromFile(specFilePath string, specVars map[string]string) (spec *
return
}

func CreateSpecFromBuildNameAndNumber(buildName, buildNumber string) (*SpecFiles, error) {
if buildName == "" || buildNumber == "" {
return nil, errorutils.CheckErrorf("build name and build number must be provided")
}

buildString := buildName + "/" + buildNumber
specFile := &SpecFiles{
Files: []File{
{
Build: buildString,
},
},
}

return specFile, nil
}

type File struct {
Aql utils.Aql
PathMapping utils.PathMapping
Expand Down
40 changes: 40 additions & 0 deletions common/spec/specfiles_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package spec

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestCreateSpecFromBuildNameAndNumber(t *testing.T) {
t.Run("Valid Inputs", func(t *testing.T) {
spec, err := CreateSpecFromBuildNameAndNumber("Common-builds", "1.2.0")

assert.NoError(t, err)
assert.NotNil(t, spec)
assert.Equal(t, "Common-builds/1.2.0", spec.Files[0].Build)
})

t.Run("Missing Build Name", func(t *testing.T) {
spec, err := CreateSpecFromBuildNameAndNumber("", "1.2.0")

assert.Error(t, err)
assert.Nil(t, spec)
assert.EqualError(t, err, "build name and build number must be provided")
})

t.Run("Missing Build Number", func(t *testing.T) {
spec, err := CreateSpecFromBuildNameAndNumber("Common-builds", "")

assert.Error(t, err)
assert.Nil(t, spec)
assert.EqualError(t, err, "build name and build number must be provided")
})

t.Run("Empty Build Name and Build Number", func(t *testing.T) {
spec, err := CreateSpecFromBuildNameAndNumber("", "")

assert.Error(t, err)
assert.Nil(t, spec)
assert.EqualError(t, err, "build name and build number must be provided")
})
}