Repository: allegro/marathon-consul
Pull request #247 (2017-07-18 16:55:50)

Use new tags slice for every service.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/12444668/badge)](https://coveralls.io/builds/12444668)

Coverage decreased (-0.006%) to 89.368% when pulling **dcc00bce87cd852ecfd01a925fa8fe2a1dbdf067 on hotfix/slice_append_magic** into **e36ce2dc17344704e6afb217f5f103c83c585264 on master**.


Patch:
diff --git a/apps/app.go b/apps/app.go
index 5c9a67d..c839809 100644
--- a/apps/app.go
+++ b/apps/app.go
@@ -103,7 +103,6 @@ func (app App) RegistrationIntentsNumber() int {
 }
 
 func (app App) RegistrationIntents(task *Task, nameSeparator string) []RegistrationIntent {
-	commonTags := labelsToTags(app.Labels)
 	taskPortsCount := len(task.Ports)
 	definitions := app.findConsulPortDefinitions()
 	if len(definitions) == 0 && taskPortsCount != 0 {
@@ -111,7 +110,7 @@ func (app App) RegistrationIntents(task *Task, nameSeparator string) []Registrat
 			{
 				Name: app.labelsToName(app.Labels, nameSeparator),
 				Port: task.Ports[0],
-				Tags: commonTags,
+				Tags: labelsToTags(app.Labels),
 			},
 		}
 	}
@@ -125,7 +124,7 @@ func (app App) RegistrationIntents(task *Task, nameSeparator string) []Registrat
 		intents = append(intents, RegistrationIntent{
 			Name: app.labelsToName(d.Labels, nameSeparator),
 			Port: task.Ports[d.Index],
-			Tags: append(commonTags, labelsToTags(d.Labels)...),
+			Tags: append(labelsToTags(app.Labels), labelsToTags(d.Labels)...),
 		})
 	}
 	return intents


Test patch:
diff --git a/apps/app_test.go b/apps/app_test.go
index a301cfc..13dd754 100644
--- a/apps/app_test.go
+++ b/apps/app_test.go
@@ -49,6 +49,23 @@ func TestParseApps(t *testing.T) {
 	assert.Equal(t, expected, apps)
 }
 
+func TestAppInt(t *testing.T) {
+	appBlob, _ := ioutil.ReadFile("testdata/lorem-ipsum.json")
+	app, err := ParseApp(appBlob)
+	assert.NoError(t, err)
+	t.Log(app)
+
+	assert.Equal(t, 2, app.RegistrationIntentsNumber())
+
+	task := Task{Ports: []int{0, 1, 2, 3}}
+	intents := app.RegistrationIntents(&task,".")
+
+	assert.Contains(t,  intents[0].Tags, "Lorem ipsum dolor sit amet, consectetur adipiscing elit")
+	assert.Contains(t,  intents[1].Tags, "secureConnection:true")
+	assert.NotContains(t,  intents[0].Tags, "secureConnection:true")
+	assert.NotContains(t,  intents[1].Tags, "Lorem ipsum dolor sit amet, consectetur adipiscing elit")
+}
+
 func TestParseApp(t *testing.T) {
 	t.Parallel()
 
diff --git a/apps/testdata/lorem-ipsum.json b/apps/testdata/lorem-ipsum.json
new file mode 100644
index 0000000..f82c7e1
--- /dev/null
+++ b/apps/testdata/lorem-ipsum.json
@@ -0,0 +1,47 @@
+{
+  "app": {
+  "id": "lorem/ipsum",
+  "cmd": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
+  "healthChecks": [
+    {
+      "path": "/ping",
+      "protocol": "HTTP"
+    }
+  ],
+  "labels": {
+    "artifactId": "Lorem ipsum",
+    "default-monitoring": "tag",
+    "hystrix-dashboard": "tag",
+    "weight:50": "tag",
+    "consul": "lorem-ipsum"
+  },
+  "portDefinitions": [
+    {
+      "port": 10115,
+      "protocol": "tcp",
+      "labels": {
+        "consul": "lorem-ipsum",
+        "Lorem ipsum dolor sit amet, consectetur adipiscing elit": "tag"
+      }
+    },
+    {
+      "port": 10116,
+      "protocol": "tcp",
+      "labels": {}
+    },
+    {
+      "port": 10130,
+      "protocol": "tcp",
+      "labels": {
+        "consul": "lorem-ipsum-secured",
+        "secureConnection:true": "tag"
+      }
+    },
+    {
+      "port": 10214,
+      "protocol": "tcp",
+      "labels": {}
+    }
+  ]
+}
+}
\ No newline at end of file