mirror of https://github.com/databricks/cli.git
add unit tests
This commit is contained in:
parent
6b8e1dfff2
commit
d9685ab33c
|
@ -20,7 +20,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// From https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
|
// source: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
|
||||||
semverRegex = regexp.MustCompile(`(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?`)
|
semverRegex = regexp.MustCompile(`(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?`)
|
||||||
uuidRegex = regexp.MustCompile(`[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}`)
|
uuidRegex = regexp.MustCompile(`[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}`)
|
||||||
numIdRegex = regexp.MustCompile(`[0-9]{3,}`)
|
numIdRegex = regexp.MustCompile(`[0-9]{3,}`)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package testdiff
|
package testdiff
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -44,3 +45,21 @@ func TestReplacement_TemporaryDirectory(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, "/tmp/.../tail", repls.Replace("/tmp/foo/bar/qux/tail"))
|
assert.Equal(t, "/tmp/.../tail", repls.Replace("/tmp/foo/bar/qux/tail"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReplacement_OS(t *testing.T) {
|
||||||
|
var repls ReplacementsContext
|
||||||
|
|
||||||
|
PrepareReplacementOS(t, &repls)
|
||||||
|
|
||||||
|
assert.Equal(t, "[OS]", repls.Replace(runtime.GOOS))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReplacement_Semver(t *testing.T) {
|
||||||
|
var repls ReplacementsContext
|
||||||
|
|
||||||
|
PrepareReplacementsSemver(t, &repls)
|
||||||
|
|
||||||
|
assert.Equal(t, "[SEMVER]", repls.Replace("1.2.3"))
|
||||||
|
assert.Equal(t, "[SEMVER]", repls.Replace("1.2.3-alpha"))
|
||||||
|
assert.Equal(t, "[SEMVER]", repls.Replace("1.2.3-alpha+build"))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue