Allow usage of Rust 1.91.1 and later patch releases#1576
Allow usage of Rust 1.91.1 and later patch releases#1576kpfleming merged 2 commits intofastly:mainfrom
Conversation
Rust 1.91.1 includes a fix for the incompatibility which appeared in 1.91.0. The CLI will now allow usage of that version, and any later patch releases in 1.91.x, but not 1.92 or later. A future CLI version will support 1.92 once beta releases of that version have been tested.
philippschulte
left a comment
There was a problem hiding this comment.
Instead of assuming that the semver parser supports your constraint I would recommend to add a table-driven test. I put it already for you together because I needed it to test your changes:
pkg/commands/compute/language_rust_test.go
package compute
import (
"errors"
"fmt"
"strings"
"testing"
"github.com/Masterminds/semver/v3"
)
func TestRustToolchainConstraint(t *testing.T) {
const constraint = ">= 1.78 != 1.91.0 < 1.92"
tests := []struct {
name string
rustVersion string
wantErr bool
wantErrorContains string
}{
{
name: "rejects 1.91.0",
rustVersion: "1.91.0",
wantErr: true,
wantErrorContains: "not compatible",
},
{
name: "allows 1.90.1",
rustVersion: "1.90.1",
wantErr: false,
},
{
name: "allows 1.91.1",
rustVersion: "1.91.1",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Parse the Rust version being tested
v, err := semver.NewVersion(tt.rustVersion)
if err != nil {
t.Fatalf("failed to parse version: %v", err)
}
// Parse the semver constraint (shared across tests)
c, err := semver.NewConstraint(constraint)
if err != nil {
t.Fatalf("failed to parse constraint: %v", err)
}
// Validate version against constraint
valid, errs := c.Validate(v)
var resultErr error
if !valid {
for _, e := range errs {
if strings.Contains(e.Error(), "is greater than") {
resultErr = fmt.Errorf("version '%s' of Rust has not been validated for use with Fastly Compute", v)
}
if strings.Contains(e.Error(), "is equal to") {
resultErr = fmt.Errorf("version '%s' of Rust is not compatible with Fastly Compute", v)
}
}
if resultErr == nil {
resultErr = fmt.Errorf("the Rust version requirement was not satisfied: '%w'", errors.Join(errs...))
}
}
// Check if error presence matches expectation
if (resultErr != nil) != tt.wantErr {
t.Errorf("unexpected error result: got %v, wantErr %v", resultErr, tt.wantErr)
}
// If error was expected, check it contains the expected string
if tt.wantErr && tt.wantErrorContains != "" && !strings.Contains(resultErr.Error(), tt.wantErrorContains) {
t.Errorf("expected error to contain %q, got %q", tt.wantErrorContains, resultErr.Error())
}
})
}
}
Please also update the changelog entry. Thanks!
|
I debated adding a test like this initially, but I opted not to because it's not testing the code in the CLI, it's testing the behavior of the In order for this to be a proper unit test as you've proposed, we would need to modify the |
|
After investigating the tests already present in the Since the actual constraint modified in this PR is configuration data and not code, I'm not really certain that a good testing strategy exists. It would almost require a complete 'functional' test which uses a built copy of the CLI and tests against various types of |
Done in 3e35b08. |
Change summary
Rust 1.91.1 includes a fix for the incompatibility which appeared in 1.91.0. The CLI will now allow usage of that version, and any later patch releases in 1.91.x, but not 1.92 or later. A future CLI version will support 1.92 once beta releases of that version have been tested.
All Submissions:
Example output when Rust 1.91.0 is used: