2020-01-29 12:14:41 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_prepareImport(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
proto []byte
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want []byte
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "sucess change import path to local",
|
|
|
|
args: args{
|
|
|
|
proto: []byte(`
|
|
|
|
package testing;
|
|
|
|
|
|
|
|
import "test.com/owner/repo/content.proto";`),
|
|
|
|
},
|
|
|
|
want: []byte(`
|
|
|
|
package testing;
|
|
|
|
|
|
|
|
import "content.proto";`),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "sucess keep google import",
|
|
|
|
args: args{
|
|
|
|
proto: []byte(`
|
|
|
|
package testing;
|
|
|
|
|
|
|
|
import "google/proto/buf";
|
|
|
|
import "test.com/owner/repo/content.proto";`),
|
|
|
|
},
|
|
|
|
want: []byte(`
|
|
|
|
package testing;
|
|
|
|
|
|
|
|
import "google/proto/buf";
|
|
|
|
import "content.proto";`),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "sucess keep local import",
|
|
|
|
args: args{
|
|
|
|
proto: []byte(`
|
|
|
|
package testing;
|
|
|
|
|
|
|
|
import "repo.proto";
|
|
|
|
import "test.com/owner/repo/content.proto";`),
|
|
|
|
},
|
|
|
|
want: []byte(`
|
|
|
|
package testing;
|
|
|
|
|
|
|
|
import "repo.proto";
|
|
|
|
import "content.proto";`),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2020-10-21 19:57:51 +00:00
|
|
|
if got := prepareImport(tt.args.proto, ""); !reflect.DeepEqual(got, tt.want) {
|
2020-01-29 12:14:41 +00:00
|
|
|
t.Errorf("prepareImport() = %v, want %v",
|
|
|
|
string(got),
|
|
|
|
string(tt.want))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|