@@ -6,39 +6,45 @@ import (
6
6
"github.com/stretchr/testify/assert"
7
7
)
8
8
9
- func TestRemoveSubdirFromSource (t * testing.T ) {
9
+ func TestSplitPackageSubdirRaw (t * testing.T ) {
10
10
11
11
tests := []struct {
12
- name string
13
- source string
14
- expected string
12
+ name string
13
+ source string
14
+ expectedPkg string
15
+ expectedSubdir string
15
16
}{
16
17
{
17
- name : "address with scheme and query string" ,
18
- source : "git::https://github.com/aquasecurity/terraform-modules.git//modules/ecs-service?ref=v0.1.0" ,
19
- expected : "git::https://github.com/aquasecurity/terraform-modules.git?ref=v0.1.0" ,
18
+ name : "address with scheme and query string" ,
19
+ source : "git::https://github.com/aquasecurity/terraform-modules.git//modules/ecs-service?ref=v0.1.0" ,
20
+ expectedPkg : "git::https://github.com/aquasecurity/terraform-modules.git?ref=v0.1.0" ,
21
+ expectedSubdir : "modules/ecs-service" ,
20
22
},
21
23
{
22
- name : "address with scheme" ,
23
- source : "git::https://github.com/aquasecurity/terraform-modules.git//modules/ecs-service" ,
24
- expected : "git::https://github.com/aquasecurity/terraform-modules.git" ,
24
+ name : "address with scheme" ,
25
+ source : "git::https://github.com/aquasecurity/terraform-modules.git//modules/ecs-service" ,
26
+ expectedPkg : "git::https://github.com/aquasecurity/terraform-modules.git" ,
27
+ expectedSubdir : "modules/ecs-service" ,
25
28
},
26
29
{
27
- name : "registry address" ,
28
- source : "hashicorp/consul/aws//modules/consul-cluster" ,
29
- expected : "hashicorp/consul/aws" ,
30
+ name : "registry address" ,
31
+ source : "hashicorp/consul/aws//modules/consul-cluster" ,
32
+ expectedPkg : "hashicorp/consul/aws" ,
33
+ expectedSubdir : "modules/consul-cluster" ,
30
34
},
31
35
{
32
- name : "without subdir" ,
33
- source : `hashicorp/consul/aws` ,
34
- expected : `hashicorp/consul/aws` ,
36
+ name : "without subdir" ,
37
+ source : `hashicorp/consul/aws` ,
38
+ expectedPkg : `hashicorp/consul/aws` ,
39
+ expectedSubdir : "." ,
35
40
},
36
41
}
37
42
38
43
for _ , test := range tests {
39
44
t .Run (test .name , func (t * testing.T ) {
40
- got := removeSubdirFromSource (test .source )
41
- assert .Equal (t , test .expected , got )
45
+ pkgAddr , subdir := splitPackageSubdirRaw (test .source )
46
+ assert .Equal (t , test .expectedPkg , pkgAddr )
47
+ assert .Equal (t , test .expectedSubdir , subdir )
42
48
})
43
49
}
44
50
}
0 commit comments