Skip to content

Commit 23f270a

Browse files
committed
remove obsolete functions
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 84b7d5a commit 23f270a

File tree

6 files changed

+43
-88
lines changed

6 files changed

+43
-88
lines changed

loader/extends_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ services:
274274
assert.NilError(t, os.WriteFile(filepath.Join(tmpdir, "compose.yaml"), []byte(rootYAML), 0o600))
275275

276276
extendsCount := 0
277-
actual, err := Load(types.ConfigDetails{
277+
actual, err := LoadWithContext(context.Background(), types.ConfigDetails{
278278
WorkingDir: tmpdir,
279279
ConfigFiles: []types.ConfigFile{{
280280
Filename: filepath.Join(tmpdir, "compose.yaml"),
@@ -428,7 +428,7 @@ func TestLoadExtendsListener(t *testing.T) {
428428
last:
429429
image: python`
430430
extendsCount := 0
431-
_, err := Load(buildConfigDetails(yaml, nil), func(options *Options) {
431+
_, err := LoadWithContext(context.Background(), buildConfigDetails(yaml, nil), func(options *Options) {
432432
options.SkipConsistencyCheck = true
433433
options.SkipNormalization = true
434434
options.ResolvePaths = true
@@ -470,7 +470,7 @@ services:
470470
assert.NilError(t, os.WriteFile(filepath.Join(tmpdir, "compose.yaml"), []byte(rootYAML), 0o600))
471471

472472
extendsCount := 0
473-
_, err := Load(types.ConfigDetails{
473+
_, err := LoadWithContext(context.Background(), types.ConfigDetails{
474474
WorkingDir: tmpdir,
475475
ConfigFiles: []types.ConfigFile{{
476476
Filename: filepath.Join(tmpdir, "compose.yaml"),
@@ -501,7 +501,7 @@ services:
501501
file: testdata/extends/reset.yaml
502502
service: base
503503
`
504-
p, err := Load(types.ConfigDetails{
504+
p, err := LoadWithContext(context.Background(), types.ConfigDetails{
505505
ConfigFiles: []types.ConfigFile{{
506506
Content: []byte(yaml),
507507
Filename: "-",
@@ -518,7 +518,7 @@ services:
518518
test:
519519
extends: { file: testdata/extends/interpolated.yaml, service: foo }
520520
`
521-
p, err := Load(types.ConfigDetails{
521+
p, err := LoadWithContext(context.Background(), types.ConfigDetails{
522522
ConfigFiles: []types.ConfigFile{{
523523
Content: []byte(yaml),
524524
Filename: "-",

loader/include_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
func TestLoadIncludeExtendsCombined(t *testing.T) {
31-
_, err := LoadWithContext(context.Background(), types.ConfigDetails{
31+
_, err := LoadWithContext(context.TODO(), types.ConfigDetails{
3232
WorkingDir: "testdata/combined",
3333
ConfigFiles: []types.ConfigFile{
3434
{
@@ -56,7 +56,7 @@ services:
5656
- imported
5757
`, map[string]string{"SOURCE": "override"})
5858

59-
p, err := Load(details, func(options *Options) {
59+
p, err := LoadWithContext(context.TODO(), details, func(options *Options) {
6060
options.SkipNormalization = true
6161
options.ResolvePaths = true
6262
})
@@ -82,7 +82,7 @@ services:
8282
bar:
8383
image: busybox
8484
`, map[string]string{"SOURCE": "override"})
85-
_, err := Load(details, func(options *Options) {
85+
_, err := LoadWithContext(context.TODO(), details, func(options *Options) {
8686
options.SkipNormalization = true
8787
options.ResolvePaths = true
8888
})
@@ -92,7 +92,7 @@ services:
9292
func TestIncludeRelative(t *testing.T) {
9393
wd, err := filepath.Abs(filepath.Join("testdata", "include"))
9494
assert.NilError(t, err)
95-
p, err := LoadWithContext(context.Background(), types.ConfigDetails{
95+
p, err := LoadWithContext(context.TODO(), types.ConfigDetails{
9696
ConfigFiles: []types.ConfigFile{
9797
{
9898
Filename: filepath.Join("testdata", "include", "compose.yaml"),
@@ -139,7 +139,7 @@ services:
139139
- VAR_NAME`
140140
createFileSubDir(t, tmpdir, "module", yaml, fileName)
141141

142-
p, err := Load(types.ConfigDetails{
142+
p, err := LoadWithContext(context.TODO(), types.ConfigDetails{
143143
WorkingDir: tmpdir,
144144
ConfigFiles: []types.ConfigFile{{
145145
Filename: path,
@@ -168,7 +168,7 @@ func TestIncludeWithProjectDirectory(t *testing.T) {
168168
if runtime.GOOS == "windows" {
169169
envs = map[string]string{"COMPOSE_CONVERT_WINDOWS_PATHS": "1"}
170170
}
171-
p, err := LoadWithContext(context.Background(), types.ConfigDetails{
171+
p, err := LoadWithContext(context.TODO(), types.ConfigDetails{
172172
WorkingDir: "testdata/include",
173173
Environment: envs,
174174
ConfigFiles: []types.ConfigFile{
@@ -209,7 +209,7 @@ services:
209209
image: alpine
210210
`
211211
createFile(t, filepath.Join(tmpdir, "dir"), yaml, "extended.yaml")
212-
p, err := Load(types.ConfigDetails{
212+
p, err := LoadWithContext(context.TODO(), types.ConfigDetails{
213213
WorkingDir: tmpdir,
214214
ConfigFiles: []types.ConfigFile{{
215215
Filename: path,

loader/loader.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,6 @@ func WithProfiles(profiles []string) func(*Options) {
257257
}
258258
}
259259

260-
// ParseYAML reads the bytes from a file, parses the bytes into a mapping
261-
// structure, and returns it.
262-
func ParseYAML(source []byte) (map[string]interface{}, error) {
263-
r := bytes.NewReader(source)
264-
decoder := yaml.NewDecoder(r)
265-
m, _, err := parseYAML(decoder)
266-
return m, err
267-
}
268-
269260
// PostProcessor is used to tweak compose model based on metadata extracted during yaml Unmarshal phase
270261
// that hardly can be implemented using go-yaml and mapstructure
271262
type PostProcessor interface {
@@ -275,32 +266,6 @@ type PostProcessor interface {
275266
Apply(interface{}) error
276267
}
277268

278-
func parseYAML(decoder *yaml.Decoder) (map[string]interface{}, PostProcessor, error) {
279-
var cfg interface{}
280-
processor := ResetProcessor{target: &cfg}
281-
282-
if err := decoder.Decode(&processor); err != nil {
283-
return nil, nil, err
284-
}
285-
stringMap, ok := cfg.(map[string]interface{})
286-
if ok {
287-
converted, err := convertToStringKeysRecursive(stringMap, "")
288-
if err != nil {
289-
return nil, nil, err
290-
}
291-
return converted.(map[string]interface{}), &processor, nil
292-
}
293-
cfgMap, ok := cfg.(map[interface{}]interface{})
294-
if !ok {
295-
return nil, nil, errors.New("Top-level object must be a mapping")
296-
}
297-
converted, err := convertToStringKeysRecursive(cfgMap, "")
298-
if err != nil {
299-
return nil, nil, err
300-
}
301-
return converted.(map[string]interface{}), &processor, nil
302-
}
303-
304269
// LoadConfigFiles ingests config files with ResourceLoader and returns config details with paths to local copies
305270
func LoadConfigFiles(ctx context.Context, configFiles []string, workingDir string, options ...func(*Options)) (*types.ConfigDetails, error) {
306271
if len(configFiles) < 1 {
@@ -353,12 +318,6 @@ func LoadConfigFiles(ctx context.Context, configFiles []string, workingDir strin
353318
return config, nil
354319
}
355320

356-
// Load reads a ConfigDetails and returns a fully loaded configuration.
357-
// Deprecated: use LoadWithContext.
358-
func Load(configDetails types.ConfigDetails, options ...func(*Options)) (*types.Project, error) {
359-
return LoadWithContext(context.Background(), configDetails, options...)
360-
}
361-
362321
// LoadWithContext reads a ConfigDetails and returns a fully loaded configuration as a compose-go Project
363322
func LoadWithContext(ctx context.Context, configDetails types.ConfigDetails, options ...func(*Options)) (*types.Project, error) {
364323
opts := toOptions(&configDetails, options)

loader/loader_test.go

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,8 @@ var sampleConfig = types.Config{
261261
},
262262
}
263263

264-
func TestParseYAML(t *testing.T) {
265-
dict, err := ParseYAML([]byte(sampleYAML))
266-
assert.NilError(t, err)
267-
assert.Check(t, is.DeepEqual(sampleDict, dict))
268-
}
269-
270264
func TestLoad(t *testing.T) {
271-
actual, err := Load(buildConfigDetails(sampleYAML, nil), func(options *Options) {
265+
actual, err := LoadWithContext(context.TODO(), buildConfigDetails(sampleYAML, nil), func(options *Options) {
272266
options.SkipNormalization = true
273267
options.SkipConsistencyCheck = true
274268
})
@@ -288,7 +282,7 @@ func TestLoadFromFile(t *testing.T) {
288282
if err := os.WriteFile(tmpPath, []byte(sampleYAML), 0o444); err != nil {
289283
t.Fatalf("failed to write temporary file: %s", err)
290284
}
291-
actual, err := Load(types.ConfigDetails{
285+
actual, err := LoadWithContext(context.TODO(), types.ConfigDetails{
292286
WorkingDir: workingDir,
293287
ConfigFiles: []types.ConfigFile{{
294288
Filename: tmpPath,
@@ -431,7 +425,7 @@ services:
431425
`
432426
assert.NilError(t, os.WriteFile(filepath.Join(tmpdir, "compose.yaml"), []byte(rootYAML), 0o600))
433427

434-
actual, err := Load(types.ConfigDetails{
428+
actual, err := LoadWithContext(context.TODO(), types.ConfigDetails{
435429
WorkingDir: tmpdir,
436430
ConfigFiles: []types.ConfigFile{{
437431
Filename: filepath.Join(tmpdir, "compose.yaml"),
@@ -813,7 +807,7 @@ networks:
813807
"thesize": "2gb",
814808
}
815809

816-
config, err := Load(buildConfigDetails(dict, env), func(options *Options) {
810+
config, err := LoadWithContext(context.TODO(), buildConfigDetails(dict, env), func(options *Options) {
817811
options.SkipNormalization = true
818812
options.SkipConsistencyCheck = true
819813
})
@@ -982,7 +976,7 @@ services:
982976
`
983977
configDetails := buildConfigDetails(dict, nil)
984978

985-
_, err := Load(configDetails)
979+
_, err := LoadWithContext(context.TODO(), configDetails)
986980
assert.NilError(t, err)
987981
}
988982

@@ -1007,7 +1001,7 @@ services:
10071001
configDetails := buildConfigDetails(dict, nil)
10081002

10091003
// Default behavior keeps the `env_file` entries
1010-
configWithEnvFiles, err := Load(configDetails, func(options *Options) {
1004+
configWithEnvFiles, err := LoadWithContext(context.TODO(), configDetails, func(options *Options) {
10111005
options.SkipNormalization = true
10121006
options.ResolvePaths = false
10131007
})
@@ -1024,7 +1018,7 @@ services:
10241018
assert.DeepEqual(t, configWithEnvFiles.Services["web"].Environment, expectedEnvironmentMap)
10251019

10261020
// Custom behavior removes the `env_file` entries
1027-
configWithoutEnvFiles, err := Load(configDetails, WithDiscardEnvFiles)
1021+
configWithoutEnvFiles, err := LoadWithContext(context.TODO(), configDetails, WithDiscardEnvFiles)
10281022
assert.NilError(t, err)
10291023
assert.Equal(t, len(configWithoutEnvFiles.Services["web"].EnvFiles), 0)
10301024
assert.DeepEqual(t, configWithoutEnvFiles.Services["web"].Environment, expectedEnvironmentMap)
@@ -1034,7 +1028,7 @@ func TestDecodeErrors(t *testing.T) {
10341028
dict := "name: test\nservices:\n web:\n image: nginx\n\tbuild: ."
10351029

10361030
configDetails := buildConfigDetails(dict, nil)
1037-
_, err := Load(configDetails)
1031+
_, err := LoadWithContext(context.TODO(), configDetails)
10381032
assert.Error(t, err, "yaml: line 4: found a tab character that violates indentation")
10391033
}
10401034

@@ -1054,7 +1048,7 @@ services:
10541048
shm_size: 2gb
10551049
`
10561050
configDetails := buildConfigDetails(dict, nil)
1057-
actual, err := Load(configDetails)
1051+
actual, err := LoadWithContext(context.TODO(), configDetails)
10581052
assert.NilError(t, err)
10591053

10601054
wd, _ := os.Getwd()
@@ -1084,7 +1078,7 @@ services:
10841078
`
10851079
configDetails := buildConfigDetails(dict, nil)
10861080

1087-
_, err := Load(configDetails)
1081+
_, err := LoadWithContext(context.TODO(), configDetails)
10881082
assert.NilError(t, err)
10891083
}
10901084

@@ -2145,7 +2139,7 @@ func TestLoadWithExtends(t *testing.T) {
21452139
Environment: map[string]string{},
21462140
}
21472141

2148-
actual, err := Load(configDetails)
2142+
actual, err := LoadWithContext(context.TODO(), configDetails)
21492143
assert.NilError(t, err)
21502144

21512145
extendsDir := filepath.Join("testdata", "subdir")
@@ -2189,7 +2183,7 @@ func TestLoadWithExtendsWithContextUrl(t *testing.T) {
21892183
Environment: map[string]string{},
21902184
}
21912185

2192-
actual, err := Load(configDetails)
2186+
actual, err := LoadWithContext(context.TODO(), configDetails)
21932187
assert.NilError(t, err)
21942188

21952189
expServices := types.Services{
@@ -2568,7 +2562,7 @@ services:
25682562
`
25692563
configDetails := buildConfigDetails(yaml, map[string]string{})
25702564

2571-
actual, err := Load(configDetails)
2565+
actual, err := LoadWithContext(context.TODO(), configDetails)
25722566
assert.NilError(t, err)
25732567
svc, err := actual.GetService("web")
25742568
assert.NilError(t, err)
@@ -2598,7 +2592,7 @@ services:
25982592
`
25992593
configDetails := buildConfigDetailsMultipleFiles(map[string]string{}, yaml1, yaml2, yaml3)
26002594

2601-
actual, err := Load(configDetails)
2595+
actual, err := LoadWithContext(context.TODO(), configDetails)
26022596
assert.NilError(t, err)
26032597
svc, err := actual.GetService("web")
26042598
assert.NilError(t, err)
@@ -2623,7 +2617,7 @@ services:
26232617
`
26242618
configDetails := buildConfigDetails(yaml, map[string]string{})
26252619

2626-
actual, err := Load(configDetails, withProjectName("interpolated", true))
2620+
actual, err := LoadWithContext(context.TODO(), configDetails, withProjectName("interpolated", true))
26272621
assert.NilError(t, err)
26282622
svc, err := actual.GetService("web")
26292623
assert.NilError(t, err)
@@ -2649,7 +2643,7 @@ volumes:
26492643
`
26502644
configDetails := buildConfigDetails(dict, nil)
26512645

2652-
project, err := Load(configDetails)
2646+
project, err := LoadWithContext(context.TODO(), configDetails)
26532647
assert.NilError(t, err)
26542648
path := project.Volumes["data"].DriverOpts["device"]
26552649
assert.Check(t, filepath.IsAbs(path))
@@ -2665,7 +2659,7 @@ services:
26652659
`
26662660
configDetails := buildConfigDetails(dict, nil)
26672661

2668-
project, err := Load(configDetails)
2662+
project, err := LoadWithContext(context.TODO(), configDetails)
26692663
assert.NilError(t, err)
26702664
assert.Equal(t, project.Services["extension"].Name, "extension")
26712665
assert.Equal(t, project.Services["extension"].Extensions["x-foo"], "bar")
@@ -2782,7 +2776,7 @@ configs:
27822776
func TestLoadWithInclude(t *testing.T) {
27832777
workingDir, err := os.Getwd()
27842778
assert.NilError(t, err)
2785-
p, err := Load(buildConfigDetails(`
2779+
p, err := LoadWithContext(context.TODO(), buildConfigDetails(`
27862780
name: 'test-include'
27872781
27882782
include:
@@ -2839,7 +2833,7 @@ services:
28392833
})
28402834
*/
28412835

2842-
p, err = Load(buildConfigDetails(`
2836+
p, err = LoadWithContext(context.TODO(), buildConfigDetails(`
28432837
name: 'test-include'
28442838
28452839
include:
@@ -2864,7 +2858,7 @@ services:
28642858
func TestLoadWithIncludeCycle(t *testing.T) {
28652859
workingDir, err := os.Getwd()
28662860
assert.NilError(t, err)
2867-
_, err = Load(types.ConfigDetails{
2861+
_, err = LoadWithContext(context.TODO(), types.ConfigDetails{
28682862
WorkingDir: filepath.Join(workingDir, "testdata"),
28692863
ConfigFiles: []types.ConfigFile{
28702864
{
@@ -2876,7 +2870,7 @@ func TestLoadWithIncludeCycle(t *testing.T) {
28762870
}
28772871

28782872
func TestLoadWithIncludeOverride(t *testing.T) {
2879-
p, err := Load(buildConfigDetailsMultipleFiles(nil, `
2873+
p, err := LoadWithContext(context.TODO(), buildConfigDetailsMultipleFiles(nil, `
28802874
name: 'test-include-override'
28812875
28822876
include:
@@ -3097,7 +3091,7 @@ services:
30973091
}
30983092

30993093
func TestLoadDevelopConfig(t *testing.T) {
3100-
project, err := Load(buildConfigDetails(`
3094+
project, err := LoadWithContext(context.TODO(), buildConfigDetails(`
31013095
name: load-develop
31023096
services:
31033097
frontend:
@@ -3225,7 +3219,7 @@ services:
32253219
if err := os.WriteFile(tmpPath, []byte(yaml), 0o644); err != nil {
32263220
t.Fatalf("failed to write temporary file: %s", err)
32273221
}
3228-
_, err := Load(types.ConfigDetails{
3222+
_, err := LoadWithContext(context.TODO(), types.ConfigDetails{
32293223
ConfigFiles: []types.ConfigFile{
32303224
{
32313225
Filename: tmpPath,
@@ -3246,7 +3240,7 @@ services:
32463240
if err := os.WriteFile(tmpPath, []byte(yaml), 0o644); err != nil {
32473241
t.Fatalf("failed to write temporary file: %s", err)
32483242
}
3249-
_, err := Load(types.ConfigDetails{
3243+
_, err := LoadWithContext(context.TODO(), types.ConfigDetails{
32503244
ConfigFiles: []types.ConfigFile{
32513245
{
32523246
Filename: tmpPath,

0 commit comments

Comments
 (0)