Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Commit

Permalink
Add App inspect unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Christophe Sirot <[email protected]>
  • Loading branch information
Jean-Christophe Sirot committed Nov 8, 2019
1 parent b58651e commit 25400b6
Showing 1 changed file with 71 additions and 4 deletions.
75 changes: 71 additions & 4 deletions internal/inspect/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import (
"fmt"
"os"
"testing"
"time"

"github.com/deislabs/cnab-go/bundle"
"github.com/deislabs/cnab-go/claim"
"github.com/docker/app/internal"
"github.com/docker/app/internal/store"
"github.com/docker/app/types"
"gotest.tools/assert"
"gotest.tools/fs"
Expand All @@ -22,7 +26,7 @@ type inspectTestCase struct {
args map[string]string
}

func TestInspect(t *testing.T) {
func TestImageInspect(t *testing.T) {
dir := fs.NewDir(t, "inspect",
fs.WithDir("no-maintainers",
fs.WithFile(internal.ComposeFileName, composeYAML),
Expand Down Expand Up @@ -121,14 +125,14 @@ text: hello`),
{name: "full"},
} {
os.Setenv(internal.DockerInspectFormatEnvVar, "pretty")
testInspect(t, dir, testcase, "")
testImageInspect(t, dir, testcase, "")
os.Setenv(internal.DockerInspectFormatEnvVar, "json")
testInspect(t, dir, testcase, "-json")
testImageInspect(t, dir, testcase, "-json")
}
})
}

func testInspect(t *testing.T, dir *fs.Dir, testcase inspectTestCase, suffix string) {
func testImageInspect(t *testing.T, dir *fs.Dir, testcase inspectTestCase, suffix string) {
app, err := types.NewAppFromDefaultFiles(dir.Join(testcase.name))
assert.NilError(t, err)
// Inspect twice to ensure output is stable (e.g. sorting of maps)
Expand All @@ -141,3 +145,66 @@ func testInspect(t *testing.T, dir *fs.Dir, testcase inspectTestCase, suffix str
})
}
}

func getInstallation() store.Installation {
created := time.Now().Add(time.Hour * -24)
modified := time.Now().Add(time.Hour * -17)
b := bundle.Bundle{
SchemaVersion: "1.0.0",
Name: "hello-world",
Version: "0.1.0",
Description: "Hello, World!",
}
i := store.Installation{
Claim: claim.Claim{
Name: "hello-world",
Revision: "01DS2ZW4QKPXHTZXZ8YAP6S9W2",
Created: created,
Modified: modified,
Bundle: &b,
Result: claim.Result{
Action: "upgrade",
Status: "success",
},
Parameters: map[string]interface{}{
"com.docker.app.args": "{}",
"com.docker.app.inspect-format": "json",
"com.docker.app.kubernetes-namespace": "default",
"com.docker.app.orchestrator": "",
"com.docker.app.render-format": "yaml",
"com.docker.app.share-registry-creds": false,
"port": "8080",
"text": "Hello, World!",
},
},
Reference: "docker.io/sirot/hello-world:0.1.0",
}
return i
}

func TestInspect(t *testing.T) {
i := getInstallation()

testCases := []struct {
name string
format string
}{
{
name: "pretty",
format: "pretty",
},
{
name: "json",
format: "json",
},
}

for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
var out bytes.Buffer
err := Inspect(&out, &i, testCase.format, "swarm")
assert.NilError(t, err)
golden.Assert(t, out.String(), fmt.Sprintf("inspect-app-%s.golden", testCase.name))
})
}
}

0 comments on commit 25400b6

Please sign in to comment.