THRIFT-2491 unable to import generated ThriftTest service
authorJens Geyer <jensg@apache.org>
Fri, 2 May 2014 21:37:39 +0000 (23:37 +0200)
committerJens Geyer <jensg@apache.org>
Fri, 2 May 2014 21:37:39 +0000 (23:37 +0200)
Client: Go
Patch: Aleksey Pesternikov

This closes #105

commit f2e7186ca8d63f407dba0c56ee51afd6405926ba
 Author: Aleksey Pesternikov <ap@alekseys-mbp.att.net>
 Date: 2014-04-22T12:48:14Z

add _ to generated filename if it ends with _test.go

compiler/cpp/src/generate/t_generator.h
compiler/cpp/src/generate/t_go_generator.cc
lib/go/test/Makefile.am
lib/go/test/NamespacedTest.thrift
lib/go/test/tests/binary_key_test.go
lib/go/test/tests/multiplexed_protocol_test.go
lib/go/test/tests/one_way_test.go
lib/go/test/tests/optional_fields_test.go
test/ThriftTest.thrift

index d5cf835..d131777 100644 (file)
@@ -193,7 +193,7 @@ class t_generator {
     in[0] = tolower(in[0]);
     return in;
   }
-  std::string lowercase(std::string in) {
+  static std::string lowercase(std::string in) {
     for (size_t i = 0; i < in.size(); ++i) {
       in[i] = tolower(in[i]);
     }
index 4893c71..6f273f1 100644 (file)
@@ -254,12 +254,11 @@ public:
             return package_flag;
         }
         std::string real_module = program->get_namespace("go");
-
-        if (real_module.empty()) {
-            return program->get_name();
+        if (!real_module.empty()) {
+               return real_module;
         }
 
-        return real_module;
+        return lowercase(program->get_name());
     }
 
 private:
@@ -1510,7 +1509,15 @@ void t_go_generator::generate_go_struct_writer(ofstream& out,
  */
 void t_go_generator::generate_service(t_service* tservice)
 {
-    string f_service_name = package_dir_ + "/" + underscore(service_name_) + ".go";
+       string test_suffix("_test");
+       string filename = lowercase(service_name_);
+       string f_service_name;
+       if (filename.compare(filename.length() - test_suffix.length(),
+                       test_suffix.length(), test_suffix) == 0) {
+               f_service_name = package_dir_ + "/" + filename + "_.go";
+       } else {
+               f_service_name = package_dir_ + "/" + filename + ".go";
+       }
     f_service_.open(f_service_name.c_str());
     f_service_ <<
                go_autogen_comment() <<
index 5499fb7..0be6cf7 100644 (file)
@@ -47,11 +47,11 @@ gopath: $(top_srcdir)/compiler/cpp/thrift $(THRIFTTEST) \
 
 check: gopath
        GOPATH=`pwd`/gopath $(GO) build \
-                               IncludesTest \
-                               BinaryKeyTest \
-                               ServicesTest \
-                               TypedefFieldTest \
-                               RefAnnotationFieldsTest
+                               includestest \
+                               binarykeytest \
+                               servicestest \
+                               typedeffieldtest \
+                               refannotationfieldstest
        GOPATH=`pwd`/gopath $(GO) test thrift tests
 
 clean-local:
index 1bb2fc4..a910350 100644 (file)
@@ -19,7 +19,7 @@
 
 include "ThriftTest.thrift"
 
-namespace go lib.go.test.NamespacedTest
+namespace go lib.go.test.namespacedtest
 
 enum Stuff {
   ONE = 1,
index 4cd3eb4..aa96193 100644 (file)
 package tests
 
 import (
-       "BinaryKeyTest"
+       "binarykeytest"
        "testing"
 )
 
 func TestBinaryMapKeyGeneratesString(t *testing.T) {
-       s := BinaryKeyTest.NewTestStruct()
+       s := binarykeytest.NewTestStruct()
        //This will only compile if BinToString has type of map[string]string
        s.BinToString = make(map[string]string)
 }
index 5b8a328..00669ef 100644 (file)
@@ -20,7 +20,7 @@
 package tests
 
 import (
-       "MultiplexedProtocolTest"
+       "multiplexedprotocoltest"
        "net"
        "testing"
        "thrift"
@@ -61,37 +61,37 @@ func TestInitTwoServers(t *testing.T) {
        }
        server = thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
 
-       firstProcessor := MultiplexedProtocolTest.NewFirstProcessor(&FirstImpl{})
+       firstProcessor := multiplexedprotocoltest.NewFirstProcessor(&FirstImpl{})
        processor.RegisterProcessor("FirstService", firstProcessor)
 
-       secondProcessor := MultiplexedProtocolTest.NewSecondProcessor(&SecondImpl{})
+       secondProcessor := multiplexedprotocoltest.NewSecondProcessor(&SecondImpl{})
        processor.RegisterProcessor("SecondService", secondProcessor)
 
        go server.Serve()
 }
 
-var firstClient *MultiplexedProtocolTest.FirstClient
+var firstClient *multiplexedprotocoltest.FirstClient
 
 func TestInitClient1(t *testing.T) {
        socket := thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT)
        transport := thrift.NewTFramedTransport(socket)
        var protocol thrift.TProtocol = thrift.NewTBinaryProtocolTransport(transport)
        protocol = thrift.NewTMultiplexedProtocol(protocol, "FirstService")
-       firstClient = MultiplexedProtocolTest.NewFirstClientProtocol(transport, protocol, protocol)
+       firstClient = multiplexedprotocoltest.NewFirstClientProtocol(transport, protocol, protocol)
        err := transport.Open()
        if err != nil {
                t.Fatal("Unable to open client socket", err)
        }
 }
 
-var secondClient *MultiplexedProtocolTest.SecondClient
+var secondClient *multiplexedprotocoltest.SecondClient
 
 func TestInitClient2(t *testing.T) {
        socket := thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT)
        transport := thrift.NewTFramedTransport(socket)
        var protocol thrift.TProtocol = thrift.NewTBinaryProtocolTransport(transport)
        protocol = thrift.NewTMultiplexedProtocol(protocol, "SecondService")
-       secondClient = MultiplexedProtocolTest.NewSecondClientProtocol(transport, protocol, protocol)
+       secondClient = multiplexedprotocoltest.NewSecondClientProtocol(transport, protocol, protocol)
        err := transport.Open()
        if err != nil {
                t.Fatal("Unable to open client socket", err)
@@ -99,11 +99,11 @@ func TestInitClient2(t *testing.T) {
 }
 
 //create client without service prefix
-func createLegacyClient(t *testing.T) *MultiplexedProtocolTest.SecondClient {
+func createLegacyClient(t *testing.T) *multiplexedprotocoltest.SecondClient {
        socket := thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT)
        transport := thrift.NewTFramedTransport(socket)
        var protocol thrift.TProtocol = thrift.NewTBinaryProtocolTransport(transport)
-       legacyClient := MultiplexedProtocolTest.NewSecondClientProtocol(transport, protocol, protocol)
+       legacyClient := multiplexedprotocoltest.NewSecondClientProtocol(transport, protocol, protocol)
        err := transport.Open()
        if err != nil {
                t.Fatal("Unable to open client socket", err)
@@ -139,7 +139,7 @@ func TestCallLegacy(t *testing.T) {
                t.Fatal("Expecting error")
        }
        //register default processor and call again
-       processor.RegisterDefault(MultiplexedProtocolTest.NewSecondProcessor(&SecondImpl{}))
+       processor.RegisterDefault(multiplexedprotocoltest.NewSecondProcessor(&SecondImpl{}))
        legacyClient = createLegacyClient(t)
        ret, err = legacyClient.ReturnTwo()
        if err != nil {
index 5ffbbfe..3ff025f 100644 (file)
@@ -20,9 +20,9 @@
 package tests
 
 import (
-       "OnewayTest"
        "fmt"
        "net"
+       "onewaytest"
        "testing"
        "thrift"
        "time"
@@ -47,7 +47,7 @@ const TIMEOUT = time.Second
 
 var addr net.Addr
 var server *thrift.TSimpleServer
-var client *OnewayTest.OneWayClient
+var client *onewaytest.OneWayClient
 
 func TestInitOneway(t *testing.T) {
        var err error
@@ -56,7 +56,7 @@ func TestInitOneway(t *testing.T) {
        if err != nil {
                t.Fatal("Unable to create server socket", err)
        }
-       processor := OnewayTest.NewOneWayProcessor(&impl{})
+       processor := onewaytest.NewOneWayProcessor(&impl{})
        server = thrift.NewTSimpleServer2(processor, serverTransport)
 
        go server.Serve()
@@ -65,7 +65,7 @@ func TestInitOneway(t *testing.T) {
 func TestInitOnewayClient(t *testing.T) {
        transport := thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT)
        protocol := thrift.NewTBinaryProtocolTransport(transport)
-       client = OnewayTest.NewOneWayClientProtocol(transport, protocol, protocol)
+       client = onewaytest.NewOneWayClientProtocol(transport, protocol, protocol)
        err := transport.Open()
        if err != nil {
                t.Fatal("Unable to open client socket", err)
index 4b0797c..324bf00 100644 (file)
 package tests
 
 import (
-       "OptionalFieldsTest"
        "bytes"
        gomock "code.google.com/p/gomock/gomock"
+       "optionalfieldstest"
        "testing"
        "thrift"
 )
 
 func TestIsSetReturnFalseOnCreation(t *testing.T) {
-       ao := OptionalFieldsTest.NewAllOptional()
+       ao := optionalfieldstest.NewAllOptional()
        if ao.IsSetS() {
                t.Errorf("Optional field S is set on initialization")
        }
@@ -71,7 +71,7 @@ func TestIsSetReturnFalseOnCreation(t *testing.T) {
 }
 
 func TestDefaultValuesOnCreation(t *testing.T) {
-       ao := OptionalFieldsTest.NewAllOptional()
+       ao := optionalfieldstest.NewAllOptional()
        if ao.GetS() != "DEFAULT" {
                t.Errorf("Unexpected default value %#v for field S", ao.GetS())
        }
@@ -112,7 +112,7 @@ func TestDefaultValuesOnCreation(t *testing.T) {
 }
 
 func TestInitialValuesOnCreation(t *testing.T) {
-       ao := OptionalFieldsTest.NewAllOptional()
+       ao := optionalfieldstest.NewAllOptional()
        if ao.S != "DEFAULT" {
                t.Errorf("Unexpected initial value %#v for field S", ao.S)
        }
@@ -152,11 +152,11 @@ func TestInitialValuesOnCreation(t *testing.T) {
 }
 
 func TestIsSetReturnTrueAfterUpdate(t *testing.T) {
-       ao := OptionalFieldsTest.NewAllOptional()
+       ao := optionalfieldstest.NewAllOptional()
        ao.S = "somevalue"
        ao.I = 123
        ao.B = true
-       ao.Aa = OptionalFieldsTest.NewStructA()
+       ao.Aa = optionalfieldstest.NewStructA()
        if !ao.IsSetS() {
                t.Errorf("Field S should be set")
        }
@@ -172,7 +172,7 @@ func TestIsSetReturnTrueAfterUpdate(t *testing.T) {
 }
 
 func TestListNotEmpty(t *testing.T) {
-       ao := OptionalFieldsTest.NewAllOptional()
+       ao := optionalfieldstest.NewAllOptional()
        ao.L = []int64{1, 2, 3}
        if !ao.IsSetL() {
                t.Errorf("Field L should be set")
@@ -189,7 +189,7 @@ func TestNoOptionalUnsetFieldsOnWire(t *testing.T) {
                proto.EXPECT().WriteFieldStop().Return(nil),
                proto.EXPECT().WriteStructEnd().Return(nil),
        )
-       ao := OptionalFieldsTest.NewAllOptional()
+       ao := optionalfieldstest.NewAllOptional()
        ao.Write(proto)
 }
 
@@ -202,7 +202,7 @@ func TestNoSetToDefaultFieldsOnWire(t *testing.T) {
                proto.EXPECT().WriteFieldStop().Return(nil),
                proto.EXPECT().WriteStructEnd().Return(nil),
        )
-       ao := OptionalFieldsTest.NewAllOptional()
+       ao := optionalfieldstest.NewAllOptional()
        ao.I = 42
        ao.Write(proto)
 }
@@ -220,7 +220,7 @@ func TestOneISetFieldOnWire(t *testing.T) {
                proto.EXPECT().WriteFieldStop().Return(nil),
                proto.EXPECT().WriteStructEnd().Return(nil),
        )
-       ao := OptionalFieldsTest.NewAllOptional()
+       ao := optionalfieldstest.NewAllOptional()
        ao.I = 123
        ao.Write(proto)
 }
@@ -240,7 +240,7 @@ func TestOneLSetFieldOnWire(t *testing.T) {
                proto.EXPECT().WriteFieldStop().Return(nil),
                proto.EXPECT().WriteStructEnd().Return(nil),
        )
-       ao := OptionalFieldsTest.NewAllOptional()
+       ao := optionalfieldstest.NewAllOptional()
        ao.L = []int64{1, 2}
        ao.Write(proto)
 }
@@ -257,7 +257,7 @@ func TestOneBinSetFieldOnWire(t *testing.T) {
                proto.EXPECT().WriteFieldStop().Return(nil),
                proto.EXPECT().WriteStructEnd().Return(nil),
        )
-       ao := OptionalFieldsTest.NewAllOptional()
+       ao := optionalfieldstest.NewAllOptional()
        ao.Bin = []byte("somebytestring")
        ao.Write(proto)
 }
@@ -274,7 +274,7 @@ func TestOneEmptyBinSetFieldOnWire(t *testing.T) {
                proto.EXPECT().WriteFieldStop().Return(nil),
                proto.EXPECT().WriteStructEnd().Return(nil),
        )
-       ao := OptionalFieldsTest.NewAllOptional()
+       ao := optionalfieldstest.NewAllOptional()
        ao.Bin = []byte{}
        ao.Write(proto)
 }
index 7ca194e..4a689fe 100644 (file)
@@ -31,7 +31,7 @@ namespace js ThriftTest
 namespace st ThriftTest
 namespace py ThriftTest
 namespace py.twisted ThriftTest
-namespace go ThriftTest
+namespace go thrifttest
 namespace php ThriftTest
 namespace delphi Thrift.Test
 namespace cocoa ThriftTest