Code review feedback
diff --git a/.gitignore b/.gitignore
index dd76eab..9d01395 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,5 @@
coverage.txt
vendor
cmd/apidGatewayDeploy/apidGatewayDeploy
-*.lock
\ No newline at end of file
+*.lock
+/apidGatewayDeploy.iml
diff --git a/api.go b/api.go
index 88ccf29..2fc41f4 100644
--- a/api.go
+++ b/api.go
@@ -287,13 +287,11 @@
w.Write([]byte("OK"))
}
-
func addHeaders(req *http.Request) {
var token = services.Config().GetString("apigeesync_bearer_token")
req.Header.Add("Authorization", "Bearer "+token)
}
-
func transmitDeploymentResultsToServer(validResults apiDeploymentResults) error {
retryIn := bundleRetryDelay
@@ -305,7 +303,7 @@
log.Errorf("unable to parse apiServerBaseURI %s: %v", apiServerBaseURI.String(), err)
return err
}
- apiPath := fmt.Sprintf("%s/clusters/%s/apids/%s/deployments",apiServerBaseURI.String(), apidClusterID, apidInstanceID)
+ apiPath := fmt.Sprintf("%s/clusters/%s/apids/%s/deployments", apiServerBaseURI.String(), apidClusterID, apidInstanceID)
resultJSON, err := json.Marshal(validResults)
if err != nil {
@@ -314,13 +312,17 @@
}
for {
- log.Debugf("transmitting deployment results to tracker by URL=%s data=%s",apiPath, string(resultJSON))
+ log.Debugf("transmitting deployment results to tracker by URL=%s data=%s", apiPath, string(resultJSON))
req, err := http.NewRequest("PUT", apiPath, bytes.NewReader(resultJSON))
+ if err != nil {
+ log.Errorf("unable to create PUT request", err)
+ return err
+ }
req.Header.Add("Content-Type", "application/json")
addHeaders(req)
resp, err := http.DefaultClient.Do(req)
- defer resp.Body.Close();
+ defer resp.Body.Close()
if err != nil || resp.StatusCode != http.StatusOK {
if err != nil {
log.Errorf("failed to communicate with tracking service: %v", err)
diff --git a/api_test.go b/api_test.go
index 1f35233..c95369f 100644
--- a/api_test.go
+++ b/api_test.go
@@ -1,15 +1,15 @@
package apiGatewayDeploy
import (
+ "bytes"
+ "encoding/json"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
+ "io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
- "encoding/json"
- "io/ioutil"
"time"
- "bytes"
)
var _ = Describe("api", func() {
@@ -155,7 +155,7 @@
time.Sleep(250 * time.Millisecond) // give api call above time to block
insertTestDeployment(testServer, deploymentID)
- deploymentsChanged<- deploymentID
+ deploymentsChanged <- deploymentID
})
It("should get 304 after blocking if no new deployment", func() {
@@ -190,8 +190,7 @@
uri.Path = deploymentsEndpoint
deploymentResult := apiDeploymentResults{
- apiDeploymentResult{
- },
+ apiDeploymentResult{},
}
payload, err := json.Marshal(deploymentResult)
Expect(err).ShouldNot(HaveOccurred())
@@ -214,7 +213,7 @@
deploymentResult := apiDeploymentResults{
apiDeploymentResult{
- ID: deploymentID,
+ ID: deploymentID,
Status: RESPONSE_STATUS_SUCCESS,
},
}
@@ -241,7 +240,7 @@
deploymentResult := apiDeploymentResults{
apiDeploymentResult{
- ID: deploymentID,
+ ID: deploymentID,
Status: RESPONSE_STATUS_SUCCESS,
},
}
@@ -273,10 +272,10 @@
deploymentResults := apiDeploymentResults{
apiDeploymentResult{
- ID: deploymentID,
- Status: RESPONSE_STATUS_FAIL,
+ ID: deploymentID,
+ Status: RESPONSE_STATUS_FAIL,
ErrorCode: 100,
- Message: "Some error message",
+ Message: "Some error message",
},
}
payload, err := json.Marshal(deploymentResults)
@@ -304,10 +303,10 @@
It("should communicate status to tracking server", func() {
deploymentResults := apiDeploymentResults{
apiDeploymentResult{
- ID: "deploymentID",
- Status: RESPONSE_STATUS_FAIL,
+ ID: "deploymentID",
+ Status: RESPONSE_STATUS_FAIL,
ErrorCode: 100,
- Message: "Some error message",
+ Message: "Some error message",
},
}
@@ -334,8 +333,8 @@
uri.Path = "/bundles/1"
bundleUri := uri.String()
bundle := bundleConfigJson{
- Name: uri.Path,
- URI: bundleUri,
+ Name: uri.Path,
+ URI: bundleUri,
ChecksumType: "crc-32",
}
bundle.Checksum = testGetChecksum(bundle.ChecksumType, bundleUri)
@@ -346,23 +345,23 @@
Expect(err).ShouldNot(HaveOccurred())
dep := DataDeployment{
- ID: deploymentID,
- BundleConfigID: deploymentID,
- ApidClusterID: deploymentID,
- DataScopeID: deploymentID,
- BundleConfigJSON: string(bundleJson),
- ConfigJSON: string(bundleJson),
- Created: "",
- CreatedBy: "",
- Updated: "",
- UpdatedBy: "",
- BundleName: deploymentID,
- BundleURI: bundle.URI,
- BundleChecksum: bundle.Checksum,
+ ID: deploymentID,
+ BundleConfigID: deploymentID,
+ ApidClusterID: deploymentID,
+ DataScopeID: deploymentID,
+ BundleConfigJSON: string(bundleJson),
+ ConfigJSON: string(bundleJson),
+ Created: "",
+ CreatedBy: "",
+ Updated: "",
+ UpdatedBy: "",
+ BundleName: deploymentID,
+ BundleURI: bundle.URI,
+ BundleChecksum: bundle.Checksum,
BundleChecksumType: bundle.ChecksumType,
- LocalBundleURI: "x",
- DeployStatus: "",
- DeployErrorCode: 0,
+ LocalBundleURI: "x",
+ DeployStatus: "",
+ DeployErrorCode: 0,
DeployErrorMessage: "",
}
diff --git a/apidGatewayDeploy_suite_test.go b/apidGatewayDeploy_suite_test.go
index 7ae2a6c..2dc0c1f 100644
--- a/apidGatewayDeploy_suite_test.go
+++ b/apidGatewayDeploy_suite_test.go
@@ -4,16 +4,16 @@
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
+ "encoding/hex"
"github.com/30x/apid-core"
"github.com/30x/apid-core/factory"
"io/ioutil"
"net/http"
"net/http/httptest"
+ "net/url"
+ "os"
"testing"
"time"
- "net/url"
- "encoding/hex"
- "os"
)
var (
@@ -56,7 +56,7 @@
router.HandleFunc("/bundles/{id}", func(w http.ResponseWriter, req *http.Request) {
count++
vars := apid.API().Vars(req)
- if count % 2 == 0 {
+ if count%2 == 0 {
w.WriteHeader(500)
return
}
@@ -71,7 +71,7 @@
router.HandleFunc("/clusters/{clusterID}/apids/{instanceID}/deployments",
func(w http.ResponseWriter, req *http.Request) {
count++
- if count % 2 == 0 {
+ if count%2 == 0 {
w.WriteHeader(500)
return
}
@@ -82,7 +82,7 @@
w.Write([]byte("OK"))
- }).Methods("PUT")
+ }).Methods("PUT")
testServer = httptest.NewServer(router)
apiServerBaseURI, err = url.Parse(testServer.URL)
diff --git a/bundle_test.go b/bundle_test.go
index 4f2bad2..b4cefda 100644
--- a/bundle_test.go
+++ b/bundle_test.go
@@ -111,7 +111,7 @@
Name: uri.Path,
URI: bundleUri,
ChecksumType: "",
- Checksum: "",
+ Checksum: "",
}
bundleJson, err := json.Marshal(bundle)
Expect(err).ShouldNot(HaveOccurred())
diff --git a/listener_test.go b/listener_test.go
index 452879e..aeddbf9 100644
--- a/listener_test.go
+++ b/listener_test.go
@@ -3,10 +3,10 @@
import (
"encoding/json"
"github.com/30x/apid-core"
+ "github.com/apigee-labs/transicator/common"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"net/url"
- "github.com/apigee-labs/transicator/common"
)
var _ = Describe("listener", func() {
@@ -23,8 +23,8 @@
uri.Path = "/bundles/1"
bundleUri := uri.String()
bundle1 := bundleConfigJson{
- Name: uri.Path,
- URI: bundleUri,
+ Name: uri.Path,
+ URI: bundleUri,
ChecksumType: "crc-32",
}
bundle1.Checksum = testGetChecksum(bundle1.ChecksumType, bundleUri)
@@ -79,8 +79,8 @@
uri.Path = "/bundles/1"
bundleUri := uri.String()
bundle := bundleConfigJson{
- Name: uri.Path,
- URI: bundleUri,
+ Name: uri.Path,
+ URI: bundleUri,
ChecksumType: "crc-32",
}
bundle.Checksum = testGetChecksum(bundle.ChecksumType, bundleUri)
@@ -95,8 +95,8 @@
Changes: []common.Change{
{
Operation: common.Insert,
- Table: DEPLOYMENT_TABLE,
- NewRow: row,
+ Table: DEPLOYMENT_TABLE,
+ NewRow: row,
},
},
}
@@ -130,7 +130,7 @@
tx, err := getDB().Begin()
Expect(err).ShouldNot(HaveOccurred())
dep := DataDeployment{
- ID: deploymentID,
+ ID: deploymentID,
LocalBundleURI: "whatever",
}
err = InsertDeployment(tx, dep)
@@ -145,8 +145,8 @@
Changes: []common.Change{
{
Operation: common.Delete,
- Table: DEPLOYMENT_TABLE,
- OldRow: row,
+ Table: DEPLOYMENT_TABLE,
+ OldRow: row,
},
},
}
diff --git a/pluginData.go b/pluginData.go
index e437d71..9625ee6 100644
--- a/pluginData.go
+++ b/pluginData.go
@@ -3,7 +3,7 @@
import "github.com/30x/apid-core"
var pluginData = apid.PluginData{
- Name: "apidGatewayDeploy",
+ Name: "apidGatewayDeploy",
Version: "0.0.1",
ExtraData: map[string]interface{}{
"schemaVersion": "0.0.1",