Skip to content

Commit cef6453

Browse files
ndeloofglours
authored andcommitted
don't assume attribute type to prevent int vs uint32 type mismatch
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 92d8aae commit cef6453

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

loader/extends_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,29 @@ services:
6464
assert.Equal(t, p.Services["test2"].Hostname, "test2")
6565
assert.Equal(t, p.Services["test3"].Hostname, "test3")
6666
}
67+
68+
func TestExtendsPort(t *testing.T) {
69+
yaml := `
70+
name: test-extends-port
71+
services:
72+
test:
73+
image: test
74+
extends:
75+
file: testdata/extends/base.yaml
76+
service: with-port
77+
`
78+
abs, err := filepath.Abs(".")
79+
assert.NilError(t, err)
80+
81+
p, err := LoadWithContext(context.Background(), types.ConfigDetails{
82+
ConfigFiles: []types.ConfigFile{
83+
{
84+
Content: []byte(yaml),
85+
Filename: "(inline)",
86+
},
87+
},
88+
WorkingDir: abs,
89+
})
90+
assert.NilError(t, err)
91+
assert.Equal(t, p.Services["test"].Ports[0].Target, uint32(8000))
92+
}

loader/testdata/extends/base.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ services:
55
another:
66
extends: base
77

8+
with-port:
9+
ports:
10+
- 8000:8000

override/uncity.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,22 +143,22 @@ func portIndexer(y any, p tree.Path) (string, error) {
143143
case int:
144144
return strconv.Itoa(value), nil
145145
case map[string]any:
146-
target, ok := value["target"].(int)
146+
target, ok := value["target"]
147147
if !ok {
148148
return "", fmt.Errorf("service ports %s is missing a target port", p)
149149
}
150-
published, ok := value["published"].(string)
150+
published, ok := value["published"]
151151
if !ok {
152152
// try to parse it as an int
153-
if pub, ok := value["published"].(int); ok {
153+
if pub, ok := value["published"]; ok {
154154
published = fmt.Sprintf("%d", pub)
155155
}
156156
}
157-
host, ok := value["host_ip"].(string)
157+
host, ok := value["host_ip"]
158158
if !ok {
159159
host = "0.0.0.0"
160160
}
161-
protocol, ok := value["protocol"].(string)
161+
protocol, ok := value["protocol"]
162162
if !ok {
163163
protocol = "tcp"
164164
}

0 commit comments

Comments
 (0)