Skip to content
This repository has been archived by the owner on Mar 18, 2021. It is now read-only.

Commit

Permalink
allowing consul service tags to be set
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram Vogelaar authored and acornies committed Jan 7, 2020
1 parent 5c24ad7 commit 099e82c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,5 @@ require (
labix.org/v2/mgo v0.0.0-20140701140051-000000000287 // indirect
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 // indirect
)

go 1.13
10 changes: 10 additions & 0 deletions handlers/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func createTask(r requests.CreateFunctionRequest, providerConfig types.ProviderC
&api.Service{
Name: r.Service,
PortLabel: "http",
Tags: parseTags(envVars),
},
},
LogConfig: &api.LogConfig{
Expand Down Expand Up @@ -365,3 +366,12 @@ func parseDNSServers(envVars map[string]string, providerConfig types.ProviderCon
}
return servers
}

func parseTags(envVars map[string]string) []string {

tags := []string{}
if val, ok := envVars["tags"]; ok {
tags = strings.Split(val, ",")
}
return tags
}
33 changes: 33 additions & 0 deletions handlers/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,39 @@ func TestHandlesRequestWithDNSServers(t *testing.T) {
assert.Equal(t, expectedServers, dnsServers)
}

func TestHandlesRequestWithoutTags(t *testing.T) {
fr := createRequest()
expectedTags := []string{}

h, rw, r := setupDeploy(fr.String())

h(rw, r)

args := mockJob.Calls[0].Arguments
job := args.Get(0).(*api.Job)

Tags := job.TaskGroups[0].Tasks[0].Services[0].Tags

assert.Equal(t, expectedTags, Tags)
}

func TestHandlesRequestWithTags(t *testing.T) {
fr := createRequest()
expectedTags := []string{"foo", "bar"}
fr.EnvVars = map[string]string{"tags": "foo,bar"}

h, rw, r := setupDeploy(fr.String())

h(rw, r)

args := mockJob.Calls[0].Arguments
job := args.Get(0).(*api.Job)

Tags := job.TaskGroups[0].Tasks[0].Services[0].Tags

assert.Equal(t, expectedTags, Tags)
}

func TestHandlesRequestUsingConsulAddress(t *testing.T) {
fr := createRequest()
expectedServers := []string{"localhost"}
Expand Down

0 comments on commit 099e82c

Please sign in to comment.