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

tests: Added tests for the use-cases in #150. #221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions constraints_test.go
Expand Up @@ -209,6 +209,54 @@ func TestConstraintCheck(t *testing.T) {
}
}

func TestReleaseVsPrerelease(t *testing.T) {
tests := []struct {
constraint string
version string
check bool
}{
{"<1.0.0", "1.0.0-alpha", true},
{"<1.0.0", "1.0.0-beta1", true},
{"<1.0.0", "1.0.0-rc.1", true},
{"<1.0.0", "1.0.0-rc1", true},
{"<2.0.0-0", "1.0.0-alpha", true},
{"<2.0.0-0", "1.0.0-beta1", true},
{"<2.0.0-0", "1.0.0-rc.1", true},
{"<2.0.0-0", "1.0.0-rc1", true},
{"<2.0.0-rc.1", "1.0.0-alpha", true},
{"<2.0.0-rc.1", "1.0.0-beta1", true},
{"<2.0.0-rc.1", "1.0.0-rc.1", true},
{"<2.0.0-rc.1", "1.0.0-rc1", true},
{"<2.0.0", "1.0.0-alpha", true},
{"<2.0.0", "1.0.0-beta1", true},
{"<2.0.0", "1.0.0-rc.1", true},
{"<2.0.0", "1.0.0-rc", true},
{"<2.0.0", "1.0.0-rc1", true},
{"<2.0.0", "1.0.0", true},
{"<2.0", "1.0", true},
{"<2", "1", true},
}

for _, tc := range tests {
c, err := parseConstraint(tc.constraint)
if err != nil {
t.Errorf("err: %s", err)
continue
}

v, err := NewVersion(tc.version)
if err != nil {
t.Errorf("err: %s", err)
continue
}

a, _ := c.check(v)
if a != tc.check {
t.Errorf("Constraint %q failing with %q", tc.constraint, tc.version)
}
}
}

func TestNewConstraint(t *testing.T) {
tests := []struct {
input string
Expand Down