-
Notifications
You must be signed in to change notification settings - Fork 8
/
prompt_test.go
36 lines (33 loc) · 1.5 KB
/
prompt_test.go
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
package main
import (
"reflect"
"testing"
)
func TestSortByLevenshteinDistance(t *testing.T) {
type args struct {
inputDests []Resource
inputSrc Resource
expect []Resource
}
resSrc := Resource{Address: "module.oldname.null_resource.resource_alpha"}
resDest1 := Resource{Address: "module.newname.null_resource.resource_alpha"}
resDest2 := Resource{Address: "module.newname.null_resource.resource_beta"}
resDest3 := Resource{Address: "module.oldname.null_resource.other_resourceA"}
resDest4 := Resource{Address: "module.oldname.null_resource.other_resourceB"}
tests := []struct {
name string
args args
}{
{name: "simple sort", args: args{inputDests: []Resource{resDest2, resDest1}, inputSrc: resSrc, expect: []Resource{resDest1, resDest2}}},
{name: "already sorted", args: args{inputDests: []Resource{resDest1, resDest2}, inputSrc: resSrc, expect: []Resource{resDest1, resDest2}}},
{name: "bigger test case", args: args{inputDests: []Resource{resDest3, resDest1, resDest2}, inputSrc: resSrc, expect: []Resource{resDest1, resDest2, resDest3}}},
{name: "sorts finally alphabetically", args: args{inputDests: []Resource{resDest4, resDest3}, inputSrc: resSrc, expect: []Resource{resDest3, resDest4}}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if sortByLevenshteinDistance(tt.args.inputDests, tt.args.inputSrc); !reflect.DeepEqual(tt.args.inputDests, tt.args.expect) {
t.Errorf("sortByLevenshteinDistance() = %v, want %v", tt.args.inputDests, tt.args.expect)
}
})
}
}