fill test files
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
This commit is contained in:
committed by
Stefan Prodan
parent
3e15e83926
commit
b78bbd5b9d
@@ -41,8 +41,4 @@ func TestBuild(t *testing.T) {
|
|||||||
if _, err := os.Stat(artifactPath); err != nil {
|
if _, err := os.Stat(artifactPath); err != nil {
|
||||||
g.Expect(err).ToNot(HaveOccurred())
|
g.Expect(err).ToNot(HaveOccurred())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("error working directory, %s", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ func Test_Push_Pull(t *testing.T) {
|
|||||||
_, err = Pull(ctx, url, tmpDir)
|
_, err = Pull(ctx, url, tmpDir)
|
||||||
g.Expect(err).ToNot(HaveOccurred())
|
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 {
|
err = filepath.Walk(testDir, func(path string, info fs.FileInfo, err error) error {
|
||||||
tmpPath := filepath.Join(tmpDir, path)
|
tmpPath := filepath.Join(tmpDir, path)
|
||||||
if _, err := os.Stat(tmpPath); err != nil && os.IsNotExist(err) {
|
if _, err := os.Stat(tmpPath); err != nil && os.IsNotExist(err) {
|
||||||
|
|||||||
@@ -19,10 +19,8 @@ package oci
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -33,13 +31,6 @@ import (
|
|||||||
_ "github.com/distribution/distribution/v3/registry/auth/htpasswd"
|
_ "github.com/distribution/distribution/v3/registry/auth/htpasswd"
|
||||||
_ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
|
_ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
|
||||||
"github.com/phayes/freeport"
|
"github.com/phayes/freeport"
|
||||||
"golang.org/x/crypto/bcrypt"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
testRegistryHtpasswdFileBasename = "authtest.htpasswd"
|
|
||||||
testRegistryUsername = "myuser"
|
|
||||||
testRegistryPassword = "mypass"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -51,24 +42,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setupRegistryServer(ctx context.Context) error {
|
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
|
// Registry config
|
||||||
config := &configuration.Configuration{}
|
config := &configuration.Configuration{}
|
||||||
port, err := freeport.GetFreePort()
|
port, err := freeport.GetFreePort()
|
||||||
@@ -93,14 +66,12 @@ func setupRegistryServer(ctx context.Context) error {
|
|||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
ctx := ctrl.SetupSignalHandler()
|
ctx := ctrl.SetupSignalHandler()
|
||||||
|
|
||||||
err := setupRegistryServer(ctx)
|
err := setupRegistryServer(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("failed to start docker registry: %s", err))
|
panic(fmt.Sprintf("failed to start docker registry: %s", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
code := m.Run()
|
code := m.Run()
|
||||||
|
|
||||||
os.Exit(code)
|
os.Exit(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
21
internal/oci/testdata/build/deployment.yaml
vendored
21
internal/oci/testdata/build/deployment.yaml
vendored
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user