Skip to content

Commit

Permalink
Factor reused object creation loop code into its own function.
Browse files Browse the repository at this point in the history
Co-authored-by: Petr Babic <108874234+pbabic-redhat@users.noreply.github.com>
Signed-off-by: Josh Gwosdz <jgwosdz@redhat.com>
  • Loading branch information
erdii and pbabic-redhat committed Aug 31, 2023
1 parent f821823 commit 51510ee
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions dev/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,7 @@ func (c *Cluster) CreateAndWaitFromHttp(
objects = append(objects, objs...)
}

for i := range objects {
if err := c.CreateAndWaitForReadiness(ctx, &objects[i], opts...); err != nil {
return fmt.Errorf("creating from http: %w", err)
}
}
return nil
return c.createObjectsFromSource(ctx, "http", objects)

Check warning on line 184 in dev/cluster.go

View check run for this annotation

Codecov / codecov/patch

dev/cluster.go#L184

Added line #L184 was not covered by tests
}

// Load kube objects from a list of files,
Expand All @@ -205,12 +200,7 @@ func (c *Cluster) CreateAndWaitFromFiles(
objects = append(objects, objs...)
}

for i := range objects {
if err := c.CreateAndWaitForReadiness(ctx, &objects[i], opts...); err != nil {
return fmt.Errorf("creating from files: %w", err)
}
}
return nil
return c.createObjectsFromSource(ctx, "files", objects)

Check warning on line 203 in dev/cluster.go

View check run for this annotation

Codecov / codecov/patch

dev/cluster.go#L203

Added line #L203 was not covered by tests
}

// Load kube objects from a list of folders,
Expand All @@ -229,9 +219,13 @@ func (c *Cluster) CreateAndWaitFromFolders(
objects = append(objects, objs...)
}

return c.createObjectsFromSource(ctx, "folders", objects)

Check warning on line 222 in dev/cluster.go

View check run for this annotation

Codecov / codecov/patch

dev/cluster.go#L222

Added line #L222 was not covered by tests
}

func (c *Cluster) createObjectsFromSource(ctx context.Context, source string, objects []unstructured.Unstructured, opts ...WaitOption) error {

Check warning on line 225 in dev/cluster.go

View check run for this annotation

Codecov / codecov/patch

dev/cluster.go#L225

Added line #L225 was not covered by tests
for i := range objects {
if err := c.CreateAndWaitForReadiness(ctx, &objects[i], opts...); err != nil {
return fmt.Errorf("creating from folders: %w", err)
return fmt.Errorf("creating from %s: %w", source, err)

Check warning on line 228 in dev/cluster.go

View check run for this annotation

Codecov / codecov/patch

dev/cluster.go#L228

Added line #L228 was not covered by tests
}
}
return nil
Expand Down

0 comments on commit 51510ee

Please sign in to comment.