-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
ddev debug match-constraint
(ddev#6645) [skip ci]
Co-authored-by: Stanislav Zhuk <[email protected]> Co-authored-by: Randy Fay <[email protected]>
- Loading branch information
1 parent
00407fd
commit 749449e
Showing
4 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/ddev/ddev/pkg/ddevapp" | ||
"github.com/ddev/ddev/pkg/util" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// DebugMatchConstraintCmd Compares a constraint against the installed DDEV version. | ||
var DebugMatchConstraintCmd = &cobra.Command{ | ||
Use: "match-constraint", | ||
Short: "Check if the currently installed ddev matches the specified version constraint.", | ||
Args: cobra.ExactArgs(1), | ||
Example: `ddev debug match-constraint ">= 1.24.0"`, | ||
Run: func(_ *cobra.Command, args []string) { | ||
versionConstraint := args[0] | ||
|
||
err := ddevapp.CheckDdevVersionConstraint(versionConstraint, "", "") | ||
if err != nil { | ||
util.Failed(err.Error()) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
DebugCmd.AddCommand(DebugMatchConstraintCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/ddev/ddev/pkg/exec" | ||
"github.com/ddev/ddev/pkg/versionconstants" | ||
"github.com/stretchr/testify/require" | ||
"regexp" | ||
"testing" | ||
) | ||
|
||
// TestDebugMatchConstraintCmd checks to see match-constraint behaves as expected | ||
// @see https://github.com/Masterminds/semver#checking-version-constraints | ||
func TestDebugMatchConstraintCmd(t *testing.T) { | ||
out, err := exec.RunHostCommand(DdevBin, "debug", "match-constraint", "-h") | ||
require.NoError(t, err, "Match constraint should not have errored for help, out='%s'", out) | ||
require.Contains(t, out, "Check if the currently installed ddev matches the specified version constraint") | ||
|
||
constraint := ">= 1.twentythree" | ||
out, err = exec.RunHostCommand(DdevBin, "debug", "match-constraint", constraint) | ||
require.Error(t, err, "Match constraint should have errored for %s, out='%s'", constraint, out) | ||
require.Contains(t, out, "constraint is not valid") | ||
|
||
constraint = "!= v0.0.0-overridden-by-make" | ||
out, err = exec.RunHostCommand(DdevBin, "debug", "match-constraint", constraint) | ||
require.NoError(t, err, "Match constraint should not have errored for %s, out='%s'", constraint, out) | ||
|
||
if !regexp.MustCompile(`^v[0-9]+\.`).MatchString(versionconstants.DdevVersion) { | ||
t.Skip(fmt.Sprintf("Skipping check for semver because DDEV version doesn't start with any valid version tag, it's '%v'", versionconstants.DdevVersion)) | ||
} | ||
|
||
constraint = ">= 1.0" | ||
out, err = exec.RunHostCommand(DdevBin, "debug", "match-constraint", constraint) | ||
require.NoError(t, err, "Match constraint should not have errored for %s, out='%s'", constraint, out) | ||
|
||
constraint = "< 1.0" | ||
out, err = exec.RunHostCommand(DdevBin, "debug", "match-constraint", constraint) | ||
require.Error(t, err, "Match constraint should have errored for %s, out='%s'", constraint, out) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters