From b78bbd5b9d54f0cdc2724b4c0612706f98ffbc74 Mon Sep 17 00:00:00 2001
From: Somtochi Onyekwere <somtochionyekwere@gmail.com>
Date: Fri, 8 Jul 2022 16:20:01 +0100
Subject: [PATCH] fill test files

Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
---
 internal/oci/build_test.go                    |  4 ---
 internal/oci/push_pull_test.go                |  2 +-
 internal/oci/suite_test.go                    | 29 -------------------
 internal/oci/testdata/build/deployment.yaml   | 21 ++++++++++++++
 internal/oci/testdata/build/somedir/repo.yaml |  8 +++++
 5 files changed, 30 insertions(+), 34 deletions(-)

diff --git a/internal/oci/build_test.go b/internal/oci/build_test.go
index 085dfe9c..2f6c5616 100644
--- a/internal/oci/build_test.go
+++ b/internal/oci/build_test.go
@@ -41,8 +41,4 @@ func TestBuild(t *testing.T) {
 	if _, err := os.Stat(artifactPath); err != nil {
 		g.Expect(err).ToNot(HaveOccurred())
 	}
-
-	if err != nil {
-		t.Errorf("error working directory, %s", err)
-	}
 }
diff --git a/internal/oci/push_pull_test.go b/internal/oci/push_pull_test.go
index f2ebc9be..c37c92d2 100644
--- a/internal/oci/push_pull_test.go
+++ b/internal/oci/push_pull_test.go
@@ -52,7 +52,7 @@ func Test_Push_Pull(t *testing.T) {
 	_, err = Pull(ctx, url, tmpDir)
 	g.Expect(err).ToNot(HaveOccurred())
 
-	// Walk directory the test directory and check that each path exists in the extracted archive
+	// Walk directory the test directory and check that all paths exists in the extracted archive
 	err = filepath.Walk(testDir, func(path string, info fs.FileInfo, err error) error {
 		tmpPath := filepath.Join(tmpDir, path)
 		if _, err := os.Stat(tmpPath); err != nil && os.IsNotExist(err) {
diff --git a/internal/oci/suite_test.go b/internal/oci/suite_test.go
index 2ac5d269..c611e1ab 100644
--- a/internal/oci/suite_test.go
+++ b/internal/oci/suite_test.go
@@ -19,10 +19,8 @@ package oci
 import (
 	"context"
 	"fmt"
-	"io/ioutil"
 	"math/rand"
 	"os"
-	"path/filepath"
 	"testing"
 	"time"
 
@@ -33,13 +31,6 @@ import (
 	_ "github.com/distribution/distribution/v3/registry/auth/htpasswd"
 	_ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
 	"github.com/phayes/freeport"
-	"golang.org/x/crypto/bcrypt"
-)
-
-const (
-	testRegistryHtpasswdFileBasename = "authtest.htpasswd"
-	testRegistryUsername             = "myuser"
-	testRegistryPassword             = "mypass"
 )
 
 var (
@@ -51,24 +42,6 @@ func init() {
 }
 
 func setupRegistryServer(ctx context.Context) error {
-	// Create a temporary workspace directory for the registry
-	workspaceDir, err := os.MkdirTemp("", "registry-test-")
-	if err != nil {
-		return fmt.Errorf("failed to create workspace directory: %w", err)
-	}
-
-	// create htpasswd file (w BCrypt, which is required)
-	pwBytes, err := bcrypt.GenerateFromPassword([]byte(testRegistryPassword), bcrypt.DefaultCost)
-	if err != nil {
-		return fmt.Errorf("failed to generate password: %s", err)
-	}
-
-	htpasswdPath := filepath.Join(workspaceDir, testRegistryHtpasswdFileBasename)
-	err = ioutil.WriteFile(htpasswdPath, []byte(fmt.Sprintf("%s:%s\n", testRegistryUsername, string(pwBytes))), 0644)
-	if err != nil {
-		return fmt.Errorf("failed to create htpasswd file: %s", err)
-	}
-
 	// Registry config
 	config := &configuration.Configuration{}
 	port, err := freeport.GetFreePort()
@@ -93,14 +66,12 @@ func setupRegistryServer(ctx context.Context) error {
 
 func TestMain(m *testing.M) {
 	ctx := ctrl.SetupSignalHandler()
-
 	err := setupRegistryServer(ctx)
 	if err != nil {
 		panic(fmt.Sprintf("failed to start docker registry: %s", err))
 	}
 
 	code := m.Run()
-
 	os.Exit(code)
 }
 
diff --git a/internal/oci/testdata/build/deployment.yaml b/internal/oci/testdata/build/deployment.yaml
index e69de29b..007ecd31 100644
--- a/internal/oci/testdata/build/deployment.yaml
+++ b/internal/oci/testdata/build/deployment.yaml
@@ -0,0 +1,21 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: nginx-deployment
+  labels:
+    app: nginx
+spec:
+  replicas: 3
+  selector:
+    matchLabels:
+      app: nginx
+  template:
+    metadata:
+      labels:
+        app: nginx
+    spec:
+      containers:
+        - name: nginx
+          image: nginx:1.14.2
+          ports:
+            - containerPort: 80
diff --git a/internal/oci/testdata/build/somedir/repo.yaml b/internal/oci/testdata/build/somedir/repo.yaml
index e69de29b..253b7632 100644
--- a/internal/oci/testdata/build/somedir/repo.yaml
+++ b/internal/oci/testdata/build/somedir/repo.yaml
@@ -0,0 +1,8 @@
+apiVersion: source.toolkit.fluxcd.io/v1beta1
+kind: HelmRepository
+metadata:
+  name: podinfo
+  namespace: flux-system
+spec:
+  interval: 2m
+  url: https://stefanprodan.github.io/podinfo
-- 
GitLab