Skip to content

Commit

Permalink
use a secret
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkowl committed Jul 28, 2023
1 parent 3fa6d22 commit cb663b0
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion pkg/containerinstall/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package containerinstall
// Licensed under the Apache License 2.0.

import (
"bytes"
"context"
"testing"
"time"
Expand All @@ -14,8 +15,11 @@ import (
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/bindings/containers"
"github.com/containers/podman/v4/pkg/bindings/images"
"github.com/containers/podman/v4/pkg/bindings/secrets"
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/specgen"
"github.com/onsi/gomega/types"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/test"

Expand All @@ -33,6 +37,7 @@ var _ = Describe("Podman", Ordered, func() {
var log *logrus.Entry
var containerName string
var containerID string
var secret *entities.SecretCreateReport

BeforeAll(func() {
var err error
Expand All @@ -52,10 +57,32 @@ var _ = Describe("Podman", Ordered, func() {
Expect(err).To(BeNil())
})

It("can create a secret", func() {

secret, err = secrets.Create(
conn, bytes.NewBufferString("hello\n"),
(&secrets.CreateOptions{}).WithName(containerName))
Expect(err).To(BeNil())

})

It("can start a container", func() {
s := specgen.NewSpecGenerator(TEST_PULLSPEC, false)
s.Name = containerName
s.Entrypoint = []string{"/bin/bash", "-c", "echo 'hello'"}
s.Secrets = []specgen.Secret{
{
Source: containerName,
Target: "/.azure/testfile",
Mode: 0o644,
},
}
s.Mounts = append(s.Mounts, specs.Mount{
Destination: "/.azure",
Type: "tmpfs",
Source: "",
})
s.WorkDir = "/.azure"
s.Entrypoint = []string{"/bin/bash", "-c", "cat testfile"}

containerID, err = runContainer(conn, log, s)
Expect(err).To(BeNil())
Expand Down Expand Up @@ -91,6 +118,11 @@ var _ = Describe("Podman", Ordered, func() {
Expect(err).To(BeNil())
}

if secret != nil {
err = secrets.Remove(conn, secret.ID)
Expect(err).To(BeNil())
}

if cancel != nil {
cancel()
}
Expand Down

0 comments on commit cb663b0

Please sign in to comment.