Skip to content

Commit

Permalink
Create spec from variables (#1303)
Browse files Browse the repository at this point in the history
  • Loading branch information
oshratZairi authored Nov 26, 2024
1 parent 04daeb8 commit e16bd86
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
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")
})
}

0 comments on commit e16bd86

Please sign in to comment.