add pg
diff --git a/dockertests/const.go b/dockertests/const.go
new file mode 100644
index 0000000..4f4266f
--- /dev/null
+++ b/dockertests/const.go
@@ -0,0 +1,15 @@
+package dockertests
+
+
+const (
+ dockerCsPort string = "9000"
+ dockerSsPort string = "9001"
+ pluginName = "apigeeSyncDockerTest"
+ configProxyServerBaseURI = "apigeesync_proxy_server_base"
+ configSnapServerBaseURI = "apigeesync_snapshot_server_base"
+ configChangeServerBaseURI = "apigeesync_change_server_base"
+ configConsumerKey = "apigeesync_consumer_key"
+ configConsumerSecret = "apigeesync_consumer_secret"
+ configName = "apigeesync_instance_name"
+ ApigeeSyncEventSelector = "ApigeeSync"
+)
diff --git a/dockertests/dockerTest.sh b/dockertests/dockerTest.sh
index 5c5a0cd..84d3ceb 100755
--- a/dockertests/dockerTest.sh
+++ b/dockertests/dockerTest.sh
@@ -11,6 +11,7 @@
TEST_PG_URL=postgres://postgres:changeme@$DOCKER_IP:5432/edgex
echo ${TEST_PG_URL}
+export APIGEE_SYNC_DOCKER_PG_URL=${TEST_PG_URL}
export APIGEE_SYNC_DOCKER_IP=${DOCKER_IP}
pgnum=$(docker images --filter "reference=apigeelabs/transicator-postgres" | wc -l)
@@ -54,3 +55,16 @@
docker run --name ${ssname} -d -p 9001:9001 apigeelabs/transicator-snapshot -p 9001 -u ${TEST_PG_URL}
docker run --name ${csname} -d -p 9000:9000 apigeelabs/transicator-changeserver -p 9000 -u ${TEST_PG_URL} -s testslot
+apid_config=`cat <<EOF
+apigeesync_instance_name: SQLLITAPID
+apigeesync_snapshot_server_base: http://${DOCKER_IP}:9001/
+apigeesync_change_server_base: http://${DOCKER_IP}:9000/
+apigeesync_snapshot_proto: sqlite
+log_level: Debug
+apigeesync_consumer_key: 33f39JNLosF1mDOXJoCfbauchVzPrGrl
+apigeesync_consumer_secret: LAolGShAx6H3vfNF
+apigeesync_cluster_id: 4c6bb536-0d64-43ca-abae-17c08f1a7e58
+EOF
+`
+rm -f ${WORK_DIR}/dockertests/apid_config.yaml
+echo "$apid_config" >> ${WORK_DIR}/dockertests/apid_config.yaml
\ No newline at end of file
diff --git a/dockertests/docker_test.go b/dockertests/docker_test.go
index 7092e1a..2980483 100644
--- a/dockertests/docker_test.go
+++ b/dockertests/docker_test.go
@@ -1,57 +1,37 @@
package dockertests
import (
- _ "github.com/30x/apidApigeeSync"
"github.com/30x/apid-core"
+ "github.com/30x/apid-core/factory"
+ _ "github.com/30x/apidApigeeSync"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
- "os"
- "github.com/30x/apid-core/factory"
- "testing"
- "fmt"
- "time"
"net/http/httptest"
+ "os"
+ "testing"
+ "time"
)
-const (
- dockerCsPort string = "9000"
- dockerSsPort string = "9001"
- dockerPgPort string = "5432"
- pluginName = "apigeeSyncDockerTest"
- configLogLevel = "log_level"
- configProxyServerBaseURI = "apigeesync_proxy_server_base"
- configSnapServerBaseURI = "apigeesync_snapshot_server_base"
- configChangeServerBaseURI = "apigeesync_change_server_base"
- configConsumerKey = "apigeesync_consumer_key"
- configConsumerSecret = "apigeesync_consumer_secret"
- configApidClusterId = "apigeesync_cluster_id"
- configSnapshotProtocol = "apigeesync_snapshot_proto"
- configName = "apigeesync_instance_name"
- ApigeeSyncEventSelector = "ApigeeSync"
-
- // special value - set by ApigeeSync, not taken from configuration
- configApidInstanceID = "apigeesync_apid_instance_id"
- // This will not be needed once we have plugin handling tokens.
- configBearerToken = "apigeesync_bearer_token"
-)
var (
- services apid.Services
- log apid.LogService
- data apid.DataService
- config apid.ConfigService
+ services apid.Services
+ log apid.LogService
+ data apid.DataService
+ config apid.ConfigService
+ pgUrl string
+ pgManager *ManagementPg
)
+
/*
* This test suite acts like a dummy plugin. It listens to events emitted by
* apidApigeeSync and runs tests.
*/
var _ = BeforeSuite(func() {
- hostname := os.Getenv("APIGEE_SYNC_DOCKER_IP")
+ hostname := "http://" + os.Getenv("APIGEE_SYNC_DOCKER_IP")
+ pgUrl = os.Getenv("APIGEE_SYNC_DOCKER_PG_URL")
os.Setenv("APID_CONFIG_FILE", "./apid_config.yaml")
- fmt.Println("Run BeforeSuite")
-
apid.Initialize(factory.DefaultServicesFactory())
config = apid.Config()
@@ -59,17 +39,22 @@
config.Set(configName, "dockerIT")
config.Set(configConsumerKey, "dummyKey")
config.Set(configConsumerSecret, "dummySecret")
- config.Set(configApidClusterId, "testClusterId")
- //testServer := initDummyAuthServer()
+ //config.Set(configApidClusterId, "testClusterId")
+ testServer := initDummyAuthServer()
// Setup dependencies
- config.Set(configChangeServerBaseURI, hostname+":"+dockerCsPort)
- config.Set(configSnapServerBaseURI, hostname+":"+dockerSsPort)
- //config.Set(configProxyServerBaseURI, testServer.URL)
+ config.Set(configChangeServerBaseURI, hostname+":"+dockerCsPort+"/")
+ config.Set(configSnapServerBaseURI, hostname+":"+dockerSsPort+"/")
+ config.Set(configProxyServerBaseURI, testServer.URL)
// init plugin
apid.RegisterPlugin(initPlugin)
apid.InitializePlugins("dockerTest")
+
+ // init pg driver
+ var err error
+ pgManager, err = InitDb(pgUrl)
+ Expect(err).Should(Succeed())
})
var _ = Describe("dockerIT", func() {
@@ -84,6 +69,22 @@
log.Debug("SS: " + config.GetString(configSnapServerBaseURI))
log.Debug("Auth: " + config.GetString(configProxyServerBaseURI))
+ cluster := &apidCluster{
+ id: "fed02735-0589-4998-bf00-e4d0df7af45b",
+ name: "apidcA",
+ description: "desc",
+ appName: "UOA",
+ created: time.Now(),
+ createdBy: "userA",
+ updated: time.Now(),
+ updatedBy: "userA",
+ changeSelector: "fed02735-0589-4998-bf00-e4d0df7af45b",
+ }
+
+ tx, err := pgManager.BeginTransaction()
+ Expect(err).Should(Succeed())
+ pgManager.InsertApidCluster(tx, cluster)
+
time.Sleep(5 * time.Second)
Expect(1).To(Equal(1))
}, 30)
@@ -103,7 +104,7 @@
log = services.Log().ForModule(pluginName)
data = services.Data()
- var pluginData = apid.PluginData {
+ var pluginData = apid.PluginData{
Name: pluginName,
Version: "0.0.1",
ExtraData: map[string]interface{}{
@@ -111,7 +112,6 @@
},
}
-
log.Info(pluginName + " initialized.")
return pluginData, nil
}
@@ -119,4 +119,4 @@
func TestDockerApigeeSync(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "ApigeeSync Docker Suite")
-}
\ No newline at end of file
+}
diff --git a/dockertests/management_pg.go b/dockertests/management_pg.go
new file mode 100644
index 0000000..bacd9cc
--- /dev/null
+++ b/dockertests/management_pg.go
@@ -0,0 +1,74 @@
+package dockertests
+
+import (
+ "database/sql"
+ _ "github.com/lib/pq"
+ "time"
+)
+
+type ManagementPg struct {
+ url string
+ pg *sql.DB
+}
+
+type apidCluster struct {
+ id string
+ name string
+ description string
+ appName string
+ created time.Time
+ createdBy string
+ updated time.Time
+ updatedBy string
+ changeSelector string
+}
+
+func InitDb(dbUrl string) (*ManagementPg, error) {
+ db, err := sql.Open("postgres", dbUrl)
+ if err != nil {
+ return nil, err
+ }
+
+ return &ManagementPg{
+ url: dbUrl,
+ pg: db,
+ }, nil
+}
+
+func (m *ManagementPg) InsertApidCluster(tx *sql.Tx, cluster *apidCluster) error {
+ stmt, err := tx.Prepare(`INSERT INTO edgex.apid_cluster(
+ id,
+ name,
+ description,
+ umbrella_org_app_name,
+ created,
+ created_by,
+ updated,
+ updated_by,
+ _change_selector
+ )
+ VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9)`)
+ if err != nil {
+ return err
+ }
+
+ _, err = stmt.Exec(
+ cluster.id,
+ cluster.name,
+ cluster.description,
+ cluster.appName,
+ cluster.created,
+ cluster.createdBy,
+ cluster.updated,
+ cluster.updatedBy,
+ cluster.changeSelector,
+ )
+
+ return err
+}
+
+func (m *ManagementPg) BeginTransaction() (*sql.Tx, error) {
+ tx, err := m.pg.Begin()
+ return tx, err
+}
+
diff --git a/dockertests/mockAuthServer.go b/dockertests/mockAuthServer.go
index 9d79fd6..2f43737 100644
--- a/dockertests/mockAuthServer.go
+++ b/dockertests/mockAuthServer.go
@@ -1,20 +1,18 @@
package dockertests
-
import (
- "github.com/30x/apidApigeeSync"
- "github.com/30x/apid-core"
"encoding/json"
+ "github.com/30x/apid-core"
+ "github.com/30x/apidApigeeSync"
"net/http"
)
const oauthExpiresIn = 2 * 60
type MockAuthServer struct {
-
}
-func (m *MockAuthServer) sendToken (w http.ResponseWriter, req *http.Request) {
+func (m *MockAuthServer) sendToken(w http.ResponseWriter, req *http.Request) {
oauthToken := apidApigeeSync.GenerateUUID()
res := apidApigeeSync.OauthToken{
AccessToken: oauthToken,
@@ -27,7 +25,6 @@
w.Write(body)
}
-func (m *MockAuthServer) Start (router apid.Router) {
+func (m *MockAuthServer) Start(router apid.Router) {
router.HandleFunc("/accesstoken", m.sendToken).Methods("POST")
}
-