Skip to content

Commit

Permalink
Make the exposed LoadBuildConfigFromFile a method on DockerBuildConfig
Browse files Browse the repository at this point in the history
Signed-off-by: Razieh Behjati <razieh@google.com>
  • Loading branch information
rbehjati committed Dec 21, 2022
1 parent d902fc6 commit 3f5afeb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions internal/builders/docker/pkg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,17 @@ func (d *Digest) ToMap() map[string]string {
return map[string]string{d.Alg: d.Value}
}

// LoadBuildConfigFromFile loads build configuration from a toml file in the given path and returns an instance of BuildConfig.
func LoadBuildConfigFromFile(path string) (*BuildConfig, error) {
// LoadBuildConfigFromFile loads build configuration from a toml file specified
// by the BuildConfigPath of this DockerBuildConfig. An instance of BuildConfig
// is returned on success.
func (dbc *DockerBuildConfig) LoadBuildConfigFromFile() (*BuildConfig, error) {
return loadBuildConfigFromFile(dbc.BuildConfigPath)
}

// loadBuildConfigFromFile does not validate the input path, and is therefore
// not exposed. The corresponding method LoadBuildConfigFromFile must be called
// on an instance of DockerBuildConfig which has a validated BuildConfigPath.
func loadBuildConfigFromFile(path string) (*BuildConfig, error) {
tomlTree, err := toml.LoadFile(path)
if err != nil {
return nil, fmt.Errorf("couldn't load toml file: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion internal/builders/docker/pkg/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

func Test_LoadBuildConfigFromFile(t *testing.T) {
got, err := LoadBuildConfigFromFile("../testdata/config.toml")
got, err := loadBuildConfigFromFile("../testdata/config.toml")
if err != nil {
t.Fatalf("couldn't load config file: %v", err)
}
Expand Down

0 comments on commit 3f5afeb

Please sign in to comment.