Skip to content

Commit

Permalink
final log/test cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
anik120 committed Oct 4, 2024
1 parent 527e324 commit 36b94e4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 61 deletions.
7 changes: 3 additions & 4 deletions internal/controllers/secretsyncer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (r *SecretSyncerReconciler) writeSecretToFile(logger logr.Logger, secret *c
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to write secret data to file: %w", err)
}
logger.Info("saved Secret data locally", "file", r.AuthFilePath)
logger.Info("saved global pull secret data locally")
return ctrl.Result{}, nil
}

Expand All @@ -99,12 +99,11 @@ func (r *SecretSyncerReconciler) deleteSecretFile(logger logr.Logger) (ctrl.Resu
logger.Info("deleting local auth file", "file", r.AuthFilePath)
if err := os.Remove(r.AuthFilePath); err != nil {
if os.IsNotExist(err) {
logger.Info("auth file does not exist, nothing to delete", "file", r.AuthFilePath)
logger.Info("auth file does not exist, nothing to delete")
return ctrl.Result{}, nil
}
return ctrl.Result{}, fmt.Errorf("failed to delete secret file: %w", err)
} else {
logger.Info("auth file deleted successfully", "file", r.AuthFilePath)
}
logger.Info("auth file deleted successfully")
return ctrl.Result{}, nil
}
99 changes: 42 additions & 57 deletions internal/rukpak/source/containers_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ func TestUnpackValidInsecure(t *testing.T) {
defer cleanup()

unpacker := &source.ContainersImageRegistry{
BaseCachePath: t.TempDir(),
SourceContextFunc: func(_ logr.Logger) (*types.SystemContext, error) {
return buildPullContext(t, imageTagRef)
},
BaseCachePath: t.TempDir(),
SourceContextFunc: buildPullContextfunc(t, imageTagRef),
}
bundleSource := &source.BundleSource{
Name: "test-bundle",
Expand Down Expand Up @@ -72,10 +70,8 @@ func TestUnpackValidUsesCache(t *testing.T) {
defer cleanup()

unpacker := &source.ContainersImageRegistry{
BaseCachePath: t.TempDir(),
SourceContextFunc: func(_ logr.Logger) (*types.SystemContext, error) {
return buildPullContext(t, imageDigestRef)
},
BaseCachePath: t.TempDir(),
SourceContextFunc: buildPullContextfunc(t, imageDigestRef),
}

bundleSource := &source.BundleSource{
Expand Down Expand Up @@ -107,10 +103,8 @@ func TestUnpackCacheCheckError(t *testing.T) {
defer cleanup()

unpacker := &source.ContainersImageRegistry{
BaseCachePath: t.TempDir(),
SourceContextFunc: func(_ logr.Logger) (*types.SystemContext, error) {
return buildPullContext(t, imageTagRef)
},
BaseCachePath: t.TempDir(),
SourceContextFunc: buildPullContextfunc(t, imageTagRef),
}
bundleSource := &source.BundleSource{
Name: "test-bundle",
Expand Down Expand Up @@ -138,10 +132,8 @@ func TestUnpackNameOnlyImageReference(t *testing.T) {
defer cleanup()

unpacker := &source.ContainersImageRegistry{
BaseCachePath: t.TempDir(),
SourceContextFunc: func(_ logr.Logger) (*types.SystemContext, error) {
return buildPullContext(t, imageTagRef)
},
BaseCachePath: t.TempDir(),
SourceContextFunc: buildPullContextfunc(t, imageTagRef),
}
bundleSource := &source.BundleSource{
Name: "test-bundle",
Expand All @@ -162,10 +154,8 @@ func TestUnpackUnservedTaggedImageReference(t *testing.T) {
defer cleanup()

unpacker := &source.ContainersImageRegistry{
BaseCachePath: t.TempDir(),
SourceContextFunc: func(_ logr.Logger) (*types.SystemContext, error) {
return buildPullContext(t, imageTagRef)
},
BaseCachePath: t.TempDir(),
SourceContextFunc: buildPullContextfunc(t, imageTagRef),
}
bundleSource := &source.BundleSource{
Name: "test-bundle",
Expand All @@ -186,10 +176,8 @@ func TestUnpackUnservedCanonicalImageReference(t *testing.T) {
defer cleanup()

unpacker := &source.ContainersImageRegistry{
BaseCachePath: t.TempDir(),
SourceContextFunc: func(_ logr.Logger) (*types.SystemContext, error) {
return buildPullContext(t, imageTagRef)
},
BaseCachePath: t.TempDir(),
SourceContextFunc: buildPullContextfunc(t, imageTagRef),
}

origRef := imageDigestRef.String()
Expand Down Expand Up @@ -272,10 +260,8 @@ func TestUnpackUnexpectedFile(t *testing.T) {
defer cleanup()

unpacker := &source.ContainersImageRegistry{
BaseCachePath: t.TempDir(),
SourceContextFunc: func(_ logr.Logger) (*types.SystemContext, error) {
return buildPullContext(t, imageTagRef)
},
BaseCachePath: t.TempDir(),
SourceContextFunc: buildPullContextfunc(t, imageTagRef),
}
bundleSource := &source.BundleSource{
Name: "test-bundle",
Expand All @@ -299,10 +285,8 @@ func TestUnpackCopySucceedsMountFails(t *testing.T) {
defer cleanup()

unpacker := &source.ContainersImageRegistry{
BaseCachePath: t.TempDir(),
SourceContextFunc: func(_ logr.Logger) (*types.SystemContext, error) {
return buildPullContext(t, imageTagRef)
},
BaseCachePath: t.TempDir(),
SourceContextFunc: buildPullContextfunc(t, imageTagRef),
}
bundleSource := &source.BundleSource{
Name: "test-bundle",
Expand All @@ -326,10 +310,8 @@ func TestCleanup(t *testing.T) {
defer cleanup()

unpacker := &source.ContainersImageRegistry{
BaseCachePath: t.TempDir(),
SourceContextFunc: func(_ logr.Logger) (*types.SystemContext, error) {
return buildPullContext(t, imageTagRef)
},
BaseCachePath: t.TempDir(),
SourceContextFunc: buildPullContextfunc(t, imageTagRef),
}
bundleSource := &source.BundleSource{
Name: "test-bundle",
Expand Down Expand Up @@ -383,27 +365,30 @@ func newReference(host, repo, tag string) (reference.NamedTagged, error) {
return reference.WithTag(ref, tag)
}

func buildPullContext(t *testing.T, ref reference.Named) (*types.SystemContext, error) {
// Build a containers/image context that allows pulling from the test registry insecurely
registriesConf := sysregistriesv2.V2RegistriesConf{Registries: []sysregistriesv2.Registry{
{
Prefix: reference.Domain(ref),
Endpoint: sysregistriesv2.Endpoint{
Location: reference.Domain(ref),
Insecure: true,
func buildPullContextfunc(t *testing.T, ref reference.Named) func(_ logr.Logger) (*types.SystemContext, error) {
return func(_ logr.Logger) (*types.SystemContext, error) {
// Build a containers/image context that allows pulling from the test registry insecurely
registriesConf := sysregistriesv2.V2RegistriesConf{Registries: []sysregistriesv2.Registry{
{
Prefix: reference.Domain(ref),
Endpoint: sysregistriesv2.Endpoint{
Location: reference.Domain(ref),
Insecure: true,
},
},
},
}}
configDir := t.TempDir()
registriesConfPath := filepath.Join(configDir, "registries.conf")
f, err := os.Create(registriesConfPath)
require.NoError(t, err)

enc := toml.NewEncoder(f)
require.NoError(t, enc.Encode(registriesConf))
require.NoError(t, f.Close())
}}
configDir := t.TempDir()
registriesConfPath := filepath.Join(configDir, "registries.conf")
f, err := os.Create(registriesConfPath)
require.NoError(t, err)

enc := toml.NewEncoder(f)
require.NoError(t, enc.Encode(registriesConf))
require.NoError(t, f.Close())

return &types.SystemContext{
SystemRegistriesConfPath: registriesConfPath,
}, nil
}

return &types.SystemContext{
SystemRegistriesConfPath: registriesConfPath,
}, nil
}

Check failure on line 394 in internal/rukpak/source/containers_image_test.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)

0 comments on commit 36b94e4

Please sign in to comment.