forked from beltran/gohive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta_test.go
125 lines (110 loc) · 2.83 KB
/
meta_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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package gohive
import (
"context"
"github.com/beltran/gohive/hive_metastore"
"log"
"os"
"fmt"
"testing"
"math/rand"
)
var lettersDb = []rune("abcdefghijklmnopqrstuvwxyz")
func randSeqDb(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = lettersDb[rand.Intn(len(lettersDb))]
}
return string(b)
}
var tableIdDb = 0
var randNameDb = randSeqDb(10)
func GetDatabaseName() string {
tableName := fmt.Sprintf("db_pokes_%s%d", randNameDb, tableIdDb)
tableIdDb+= 1
return tableName
}
func TestConnectDefaultMeta(t *testing.T) {
if os.Getenv("METASTORE_SKIP") == "1" {
t.Skip("metastore not set.")
}
configuration := NewMetastoreConnectConfiguration()
configuration.TransportMode = getTransportForMeta()
client, err := ConnectToMetastore("hm.example.com", 9083, getAuthForMeta(), configuration)
if err != nil {
log.Fatal(err)
}
client.Close()
}
func TestConnectNoneMetaFails(t *testing.T) {
if os.Getenv("METASTORE_SKIP") == "1" {
t.Skip("metastore not set.")
}
configuration := NewMetastoreConnectConfiguration()
configuration.TransportMode = getTransportForMeta()
_, err := ConnectToMetastore("hm.example.com", 9083, "NONE", configuration)
if err == nil {
log.Fatal("auth shouldn't have succeeded, none")
}
_, err = ConnectToMetastore("hm.example.com", 9083, "NOSASL", configuration)
}
func Contains(c []string, s string) bool {
for _, v := range c {
if v == s {
return true
}
}
return false
}
func TestDatabaseOperations(t *testing.T) {
if os.Getenv("METASTORE_SKIP") == "1" {
t.Skip("metastore not set.")
}
configuration := NewMetastoreConnectConfiguration()
configuration.TransportMode = getTransportForMeta()
connection, err := ConnectToMetastore("hm.example.com", 9083, getAuthForMeta(), configuration)
if err != nil {
log.Fatal(err)
}
name := GetDatabaseName()
database := hive_metastore.Database{
Name: name,
LocationUri: "/"}
err = connection.Client.CreateDatabase(context.Background(), &database)
if err != nil {
log.Fatal(err)
}
databases, err := connection.Client.GetAllDatabases(context.Background())
if err != nil {
log.Fatal(err)
}
if !Contains(databases, name) {
t.Fatalf("%s not found, databases: %+v", name, databases)
}
err = connection.Client.DropDatabase(context.Background(), name, false, false)
if err != nil {
log.Fatal(err)
}
databases, err = connection.Client.GetAllDatabases(context.Background())
if err != nil {
log.Fatal(err)
}
if Contains(databases, name) {
t.Fatalf("%s should have been deleted, databases: %+v", name, databases)
}
connection.Close()
}
func getAuthForMeta() string {
auth := os.Getenv("AUTH")
os.Setenv("KRB5CCNAME", "/tmp/krb5_gohive")
if auth == "" {
auth = "KERBEROS"
}
return auth
}
func getTransportForMeta() string {
transport := os.Getenv("TRANSPORT")
if transport == "" {
transport = "binary"
}
return transport
}