Repository navigation
Expand file tree
/
Copy pathruntime_test.go
More file actions
107 lines (100 loc) · 2.47 KB
/
Copy pathruntime_test.go
File metadata and controls
107 lines (100 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"reflect"
"strings"
"testing"
runtimev0 "github.com/codefly-dev/core/generated/go/codefly/services/runtime/v0"
)
func TestCargoTestArgsHonorsTargetedSuiteFilterAndPackage(t *testing.T) {
request := &runtimev0.TestRequest{
Target: "warden-plugins-evidence",
Suite: "unit",
Filters: []string{"route_verifies_the_sdk_carrier_before_appending"},
Verbose: true,
}
got, err := cargoTestArgs(request)
if err != nil {
t.Fatal(err)
}
want := []string{
"test",
"--lib",
"--bins",
"--verbose",
"--package",
"warden-plugins-evidence",
"route_verifies_the_sdk_carrier_before_appending",
}
if !reflect.DeepEqual(got, want) {
t.Fatalf("cargo args = %#v, want %#v", got, want)
}
}
func TestCargoTestArgsMapsDirectoryTargetToManifestPath(t *testing.T) {
got, err := cargoTestArgs(&runtimev0.TestRequest{
Target: "./crates/evidence",
Suite: "integration",
})
if err != nil {
t.Fatal(err)
}
want := []string{
"test",
"--tests",
"--manifest-path",
"crates/evidence/Cargo.toml",
}
if !reflect.DeepEqual(got, want) {
t.Fatalf("cargo args = %#v, want %#v", got, want)
}
}
func TestCargoTestArgsUsesWorkspaceOnlyWithoutTarget(t *testing.T) {
got, err := cargoTestArgs(&runtimev0.TestRequest{Suite: "unit"})
if err != nil {
t.Fatal(err)
}
want := []string{"test", "--workspace", "--lib", "--bins"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("cargo args = %#v, want %#v", got, want)
}
}
func TestCargoTestArgsFailsClosedOnUnsupportedSemantics(t *testing.T) {
cases := map[string]*runtimev0.TestRequest{
"multiple filters": {
Filters: []string{"first", "second"},
},
"race": {
Race: true,
},
"coverage": {
Coverage: true,
},
"timeout": {
Timeout: "30s",
},
"unknown suite": {
Suite: "smoke",
},
"typed selection": {
SelectionId: "selection-1",
Selection: &runtimev0.TestSelection{
Scope: &runtimev0.TestSelection_Package{
Package: &runtimev0.TestPackageSelection{Package: "crate-a"},
},
},
},
}
for name, request := range cases {
t.Run(name, func(t *testing.T) {
args, err := cargoTestArgs(request)
if err == nil {
t.Fatalf("cargo args = %#v, want fail-closed error", args)
}
})
}
}
func TestCargoTestArgsNeverTreatsAFlagAsAFilter(t *testing.T) {
_, err := cargoTestArgs(&runtimev0.TestRequest{Filters: []string{"--ignored"}})
if err == nil || !strings.Contains(err.Error(), "native substring") {
t.Fatalf("error = %v, want native-substring rejection", err)
}
}