github.com/mailru/activerecord@v1.12.2/internal/pkg/ds/package_w_test.go (about) 1 package ds 2 3 import ( 4 "testing" 5 ) 6 7 func Test_getImportName(t *testing.T) { 8 type args struct { 9 path string 10 } 11 tests := []struct { 12 name string 13 args args 14 want string 15 wantErr bool 16 }{ 17 { 18 name: "simple getImportName", 19 args: args{path: "go/ast"}, 20 want: "ast", 21 wantErr: false, 22 }, 23 { 24 name: "small package path", 25 args: args{path: "ast"}, 26 want: "ast", 27 wantErr: false, 28 }, 29 { 30 name: "gitlab package", 31 args: args{path: "github.com/mailru/activerecord/internal/pkg/arerror"}, 32 want: "arerror", 33 wantErr: false, 34 }, 35 { 36 name: "import with quote", 37 args: args{path: `error "github.com/mailru/activerecord/internal/pkg/arerror"`}, 38 want: "arerror", 39 wantErr: false, 40 }, 41 { 42 name: "empty import", 43 args: args{path: ""}, 44 want: "", 45 wantErr: true, 46 }, 47 } 48 for _, tt := range tests { 49 t.Run(tt.name, func(t *testing.T) { 50 got, err := getImportName(tt.args.path) 51 if (err != nil) != tt.wantErr { 52 t.Errorf("getImportName() error = %v, wantErr %v", err, tt.wantErr) 53 return 54 } 55 if got != tt.want { 56 t.Errorf("getImportName() = %v, want %v", got, tt.want) 57 } 58 }) 59 } 60 }