Skip to content

Commit

Permalink
refactor: Unify naming for reading manifest
Browse files Browse the repository at this point in the history
Instead of having *convert/parse/to*, we now have *parse* as the single prefix for reading manifest related data.
  • Loading branch information
Laubi committed Oct 19, 2023
1 parent 1e89f61 commit b10e9bd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
8 changes: 4 additions & 4 deletions pkg/manifest/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (e invalidUUIDError) Unwrap() error {
return e.err
}

func convertSingleAccount(c *LoaderContext, a account) (Account, error) {
func parseSingleAccount(c *LoaderContext, a account) (Account, error) {

if a.AccountUUID == "" {
return Account{}, errAccUidMissing
Expand Down Expand Up @@ -75,8 +75,8 @@ func convertSingleAccount(c *LoaderContext, a account) (Account, error) {
return acc, nil
}

// convertAccounts converts the persistence definition to the in-memory definition
func convertAccounts(c *LoaderContext, accounts []account) (map[string]Account, error) {
// parseAccounts converts the persistence definition to the in-memory definition
func parseAccounts(c *LoaderContext, accounts []account) (map[string]Account, error) {

result := make(map[string]Account, len(accounts))

Expand All @@ -85,7 +85,7 @@ func convertAccounts(c *LoaderContext, accounts []account) (map[string]Account,
return nil, fmt.Errorf("failed to parse account on position %d: %w", i, errNameMissing)
}

acc, err := convertSingleAccount(c, a)
acc, err := parseSingleAccount(c, a)
if err != nil {
return nil, fmt.Errorf("failed to parse account %q: %w", a.Name, err)
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/manifest/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestValidAccounts(t *testing.T) {
},
}

v, err := convertAccounts(&LoaderContext{}, []account{acc, acc2})
v, err := parseAccounts(&LoaderContext{}, []account{acc, acc2})
assert.NoError(t, err)

assert.Equal(t, v, map[string]Account{
Expand Down Expand Up @@ -119,31 +119,31 @@ func TestInvalidAccounts(t *testing.T) {
}

// validate that the default is valid
_, err := convertAccounts(&LoaderContext{}, []account{validAccount})
_, err := parseAccounts(&LoaderContext{}, []account{validAccount})
assert.NoError(t, err)

// tests
t.Run("name is missing", func(t *testing.T) {
a := validAccount
a.Name = ""

_, err := convertAccounts(&LoaderContext{}, []account{a})
_, err := parseAccounts(&LoaderContext{}, []account{a})
assert.ErrorIs(t, err, errNameMissing)
})

t.Run("accountUUID is missing", func(t *testing.T) {
a := validAccount
a.AccountUUID = ""

_, err := convertAccounts(&LoaderContext{}, []account{a})
_, err := parseAccounts(&LoaderContext{}, []account{a})
assert.ErrorIs(t, err, errAccUidMissing)
})

t.Run("accountUUID is invalid", func(t *testing.T) {
a := deepCopy(t, validAccount)
a.AccountUUID = "this-is-not-a-valid-uuid"

_, err := convertAccounts(&LoaderContext{}, []account{a})
_, err := parseAccounts(&LoaderContext{}, []account{a})
uuidErr := invalidUUIDError{}
if assert.ErrorAs(t, err, &uuidErr) {
assert.Equal(t, uuidErr.uuid, "this-is-not-a-valid-uuid")
Expand All @@ -154,15 +154,15 @@ func TestInvalidAccounts(t *testing.T) {
a := deepCopy(t, validAccount)
a.OAuth = oAuth{}

_, err := convertAccounts(&LoaderContext{}, []account{a})
_, err := parseAccounts(&LoaderContext{}, []account{a})
assert.ErrorContains(t, err, "oAuth is invalid")
})

t.Run("oAuth.id is not set", func(t *testing.T) {
a := deepCopy(t, validAccount)
a.OAuth.ClientID = authSecret{}

_, err := convertAccounts(&LoaderContext{}, []account{a})
_, err := parseAccounts(&LoaderContext{}, []account{a})
assert.ErrorContains(t, err, "ClientID: no name given or empty")

})
Expand All @@ -171,7 +171,7 @@ func TestInvalidAccounts(t *testing.T) {
a := deepCopy(t, validAccount)
a.OAuth.ClientSecret = authSecret{}

_, err := convertAccounts(&LoaderContext{}, []account{a})
_, err := parseAccounts(&LoaderContext{}, []account{a})
assert.ErrorContains(t, err, "ClientSecret: no name given or empty")
})
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/manifest/manifest_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func LoadManifest(context *LoaderContext) (Manifest, []error) {
var errs []error

// projects
projectDefinitions, projectErrors := toProjectDefinitions(&projectLoaderContext{
projectDefinitions, projectErrors := parseProjects(&projectLoaderContext{
fs: workingDirFs,
manifestPath: relativeManifestPath,
}, manifestYAML.Projects)
Expand All @@ -163,15 +163,15 @@ func LoadManifest(context *LoaderContext) (Manifest, []error) {
}

// environments
environmentDefinitions, manifestErrors := toEnvironments(context, manifestYAML.EnvironmentGroups)
environmentDefinitions, manifestErrors := parseEnvironments(context, manifestYAML.EnvironmentGroups)
if manifestErrors != nil {
errs = append(errs, manifestErrors...)
} else if len(environmentDefinitions) == 0 {
errs = append(errs, newManifestLoaderError(context.ManifestPath, "no environments defined in manifest"))
}

// accounts
accounts, accErr := convertAccounts(context, manifestYAML.Accounts)
accounts, accErr := parseAccounts(context, manifestYAML.Accounts)
if accErr != nil {
errs = append(errs, newManifestLoaderError(context.ManifestPath, accErr.Error()))
}
Expand Down Expand Up @@ -330,7 +330,7 @@ func validateVersion(m manifest) error {
return nil
}

func toEnvironments(context *LoaderContext, groups []group) (map[string]EnvironmentDefinition, []error) { // nolint:gocognit
func parseEnvironments(context *LoaderContext, groups []group) (map[string]EnvironmentDefinition, []error) { // nolint:gocognit
var errors []error
environments := make(map[string]EnvironmentDefinition)

Expand Down Expand Up @@ -367,7 +367,7 @@ func toEnvironments(context *LoaderContext, groups []group) (map[string]Environm
continue
}

parsedEnv, configErrors := parseEnvironment(context, env, group.Name)
parsedEnv, configErrors := parseSingleEnvironment(context, env, group.Name)

if configErrors != nil {
errors = append(errors, configErrors...)
Expand Down Expand Up @@ -415,7 +415,7 @@ func shouldSkipEnv(context *LoaderContext, group group, env environment) bool {
return true
}

func parseEnvironment(context *LoaderContext, config environment, group string) (EnvironmentDefinition, []error) {
func parseSingleEnvironment(context *LoaderContext, config environment, group string) (EnvironmentDefinition, []error) {
var errs []error

a, err := parseAuth(context, config.Auth)
Expand Down Expand Up @@ -489,7 +489,7 @@ func parseURLDefinition(context *LoaderContext, u url) (URLDefinition, error) {
return URLDefinition{}, fmt.Errorf("%q is not a valid URL type", u.Type)
}

func toProjectDefinitions(context *projectLoaderContext, definitions []project) (map[string]ProjectDefinition, []error) {
func parseProjects(context *projectLoaderContext, definitions []project) (map[string]ProjectDefinition, []error) {
var errors []error
result := make(map[string]ProjectDefinition)

Expand Down
4 changes: 2 additions & 2 deletions pkg/manifest/manifest_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,11 @@ func Test_toProjectDefinitions(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
context := &projectLoaderContext{testFs, "path/to/a/manifest.yaml"}

got, gotErrs := toProjectDefinitions(context, tt.projectDefinitions)
got, gotErrs := parseProjects(context, tt.projectDefinitions)

numErrs := len(gotErrs)
if (tt.wantErrs && numErrs <= 0) || (!tt.wantErrs && numErrs > 0) {
t.Errorf("toProjectDefinitions() returned unexpected Errors = %v", gotErrs)
t.Errorf("parseProjects() returned unexpected Errors = %v", gotErrs)
}

assert.Equal(t, tt.want, got)
Expand Down

0 comments on commit b10e9bd

Please sign in to comment.