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

Commit

Permalink
Adds support for extra_hosts attribute. (#1)
Browse files Browse the repository at this point in the history
* Added ExtraHosts property.

* Added tests for Load().

* Formatted codes.
  • Loading branch information
Nick Santamaria authored Aug 16, 2019
1 parent 11c1466 commit bdcc120
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
1 change: 1 addition & 0 deletions compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Service struct {
CapAdd []string `yaml:"cap_add"`
Tmpfs []string `yaml:"tmpfs"`
Deploy ServiceDeploy `yaml:"deploy"`
ExtraHosts []string `yaml:"extra_hosts"`
}

// ServiceDeploy provides deployment information for a service.
Expand Down
26 changes: 26 additions & 0 deletions compose_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package compose

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestLoad(t *testing.T) {
file := "./test-data/test.yaml"
compose, err := Load(file)
assert.Nil(t, err)

assert.Equal(t, compose.Services["a"].Image, "hostname.io/org/repo:version")
assert.Equal(t, compose.Services["a"].Volumes, []string{"a:/a", "b:/b"})
assert.Equal(t, compose.Services["a"].Entrypoint, []string{"/entrypoint"})
assert.Equal(t, compose.Services["a"].Ports, []string{"1000:2000"})
assert.Equal(t, compose.Services["a"].Environment, []string{"SOME_VAR=somevalue"})
assert.Equal(t, compose.Services["a"].CapAdd, []string{"NET_ADMIN"})
assert.Equal(t, compose.Services["a"].Tmpfs, []string{"/tmp"})
assert.Equal(t, compose.Services["a"].Deploy.Resources.Reservations.CPUs, "50m")
assert.Equal(t, compose.Services["a"].Deploy.Resources.Reservations.Memory, "768Mi")
assert.Equal(t, compose.Services["a"].Deploy.Resources.Limits.CPUs, "500m")
assert.Equal(t, compose.Services["a"].Deploy.Resources.Limits.Memory, "2048Mi")
assert.Equal(t, compose.Services["a"].ExtraHosts, []string{"some.hostname:1.2.3.4"})
}
27 changes: 27 additions & 0 deletions test-data/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "3"
services:
a:
image: hostname.io/org/repo:version
volumes:
- "a:/a"
- "b:/b"
entrypoint:
- "/entrypoint"
ports:
- "1000:2000"
environment:
- SOME_VAR=somevalue
cap_add:
- NET_ADMIN
tmpfs:
- /tmp
deploy:
resources:
reservations:
cpus: '50m'
memory: '768Mi'
limits:
cpus: '500m'
memory: '2048Mi'
extra_hosts:
- "some.hostname:1.2.3.4"

0 comments on commit bdcc120

Please sign in to comment.