Beispiel #1
0
func TestTransport(t *testing.T) {
	UserName := os.Getenv("SWIFT_API_USER")
	ApiKey := os.Getenv("SWIFT_API_KEY")
	AuthUrl := os.Getenv("SWIFT_AUTH_URL")
	if UserName == "" || ApiKey == "" || AuthUrl == "" {
		t.Fatal("SWIFT_API_USER, SWIFT_API_KEY and SWIFT_AUTH_URL not all set")
	}
	tr := &someTransport{Transport: http.Transport{MaxIdleConnsPerHost: 2048}}
	ct := swift.Connection{
		UserName:       UserName,
		ApiKey:         ApiKey,
		AuthUrl:        AuthUrl,
		Tenant:         os.Getenv("SWIFT_TENANT"),
		TenantId:       os.Getenv("SWIFT_TENANT_ID"),
		Transport:      tr,
		ConnectTimeout: 60 * time.Second,
		Timeout:        60 * time.Second,
	}
	err := ct.Authenticate()
	if err != nil {
		t.Fatal("Auth failed", err)
	}
	if !ct.Authenticated() {
		t.Fatal("Not authenticated")
	}
}
Beispiel #2
0
// Test a connection can be serialized and unserialized with XML
func TestSerializeConnectionXml(t *testing.T) {
	serializedConnection, err := xml.Marshal(c)
	if err != nil {
		t.Fatalf("Failed to serialize connection: %v", err)
	}
	c2 := new(swift.Connection)
	err = xml.Unmarshal(serializedConnection, &c2)
	if err != nil {
		t.Fatalf("Failed to unserialize connection: %v", err)
	}
	if !c2.Authenticated() {
		t.Fatal("Should be authenticated")
	}
	_, _, err = c2.Account()
	if err != nil {
		t.Fatalf("Failed to use unserialized connection: %v", err)
	}
}
Beispiel #3
0
func TestTransport(t *testing.T) {
	var err error
	UserName := os.Getenv("SWIFT_API_USER")
	ApiKey := os.Getenv("SWIFT_API_KEY")
	AuthUrl := os.Getenv("SWIFT_AUTH_URL")
	if UserName == "" || ApiKey == "" || AuthUrl == "" {
		srv, err = swifttest.NewSwiftServer("localhost")
		if err != nil {
			t.Fatal("Failed to create server", err)
		}
		UserName = "******"
		ApiKey = "swifttest"
		AuthUrl = srv.AuthURL
	}
	tr := &someTransport{Transport: http.Transport{MaxIdleConnsPerHost: 2048}}
	ct := swift.Connection{
		UserName:       UserName,
		ApiKey:         ApiKey,
		AuthUrl:        AuthUrl,
		Tenant:         os.Getenv("SWIFT_TENANT"),
		TenantId:       os.Getenv("SWIFT_TENANT_ID"),
		Transport:      tr,
		ConnectTimeout: 60 * time.Second,
		Timeout:        60 * time.Second,
	}
	err = ct.Authenticate()
	if err != nil {
		t.Fatal("Auth failed", err)
	}
	if !ct.Authenticated() {
		t.Fatal("Not authenticated")
	}
	if srv != nil {
		srv.Close()
	}
}