-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from dskiff/dskiff/config-file
Add config file support
- Loading branch information
Showing
10 changed files
with
181 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
build: | ||
destination-path: /usr/local/bin | ||
entrypoint: /usr/local/bin/tko | ||
default-labels: | ||
org.opencontainers.image.title: tko | ||
org.opencontainers.image.url: github.com/dskiff/tko | ||
org.opencontainers.image.source: github.com/dskiff/tko |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package main_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/alecthomas/kong" | ||
kongyaml "github.com/alecthomas/kong-yaml" | ||
"github.com/dskiff/tko/pkg/cmd" | ||
"gotest.tools/v3/assert" | ||
) | ||
|
||
func TestYamlBasic(t *testing.T) { | ||
yaml := ` | ||
build: | ||
base-ref: base-image@sha256:1234 | ||
platform: custom-os/arch-variant | ||
entrypoint: /entrypoint | ||
destination-path: /destination | ||
target-repo: repo/target | ||
author: me | ||
default-labels: | ||
label1: value1 | ||
label2: value2 | ||
labels: | ||
label3: value3 | ||
label4: value4 | ||
tmp: /tmp-dir | ||
verbose: true | ||
` | ||
|
||
r, err := kongyaml.Loader(strings.NewReader(yaml)) | ||
assert.NilError(t, err) | ||
|
||
cli := cmd.CLI{} | ||
parser := mustNew(t, &cli, kong.Resolvers(r)) | ||
_, err = parser.Parse([]string{"build", "/source"}) | ||
assert.NilError(t, err) | ||
|
||
assert.Equal(t, "base-image@sha256:1234", cli.Build.BaseRef) | ||
|
||
assert.Equal(t, "custom-os/arch-variant", cli.Build.Platform) | ||
|
||
assert.Equal(t, "/entrypoint", cli.Build.Entrypoint) | ||
assert.Equal(t, "/destination", cli.Build.DestinationPath) | ||
assert.Equal(t, "repo/target", cli.Build.TargetRepo) | ||
|
||
assert.Equal(t, "me", cli.Build.Author) | ||
assert.Equal(t, "value1", cli.Build.DefaultLabels["label1"]) | ||
assert.Equal(t, "value2", cli.Build.DefaultLabels["label2"]) | ||
assert.Equal(t, "value3", cli.Build.Labels["label3"]) | ||
assert.Equal(t, "value4", cli.Build.Labels["label4"]) | ||
|
||
assert.Equal(t, "/tmp-dir", cli.Build.Tmp) | ||
assert.Equal(t, true, cli.Build.Verbose) | ||
} | ||
|
||
func TestVersionArgs(t *testing.T) { | ||
cli := cmd.CLI{} | ||
parser := mustNew(t, &cli) | ||
args, err := parser.Parse([]string{"version"}) | ||
assert.NilError(t, err) | ||
|
||
assert.Equal(t, true, args.Command() == "version") | ||
} | ||
|
||
func TestBuildArgs(t *testing.T) { | ||
cli := cmd.CLI{} | ||
parser := mustNew(t, &cli) | ||
_, err := parser.Parse([]string{"build", "/source", | ||
"-b", "base-image@sha256:1234", | ||
"-p", "custom-os/arch-variant", | ||
"-e", "/entrypoint", | ||
"-d", "/destination", | ||
"-t", "repo/target", | ||
"-a", "me", | ||
"-L", "label1=value1", | ||
"-L", "label2=value2", | ||
"-l", "label3=value3", | ||
"-l", "label4=value4", | ||
"-T", "REMOTE", | ||
"-v", | ||
"--tmp", "/tmp-dir", | ||
}) | ||
assert.NilError(t, err) | ||
|
||
assert.Equal(t, "base-image@sha256:1234", cli.Build.BaseRef) | ||
|
||
assert.Equal(t, "custom-os/arch-variant", cli.Build.Platform) | ||
|
||
assert.Equal(t, "/entrypoint", cli.Build.Entrypoint) | ||
assert.Equal(t, "/destination", cli.Build.DestinationPath) | ||
assert.Equal(t, "repo/target", cli.Build.TargetRepo) | ||
|
||
assert.Equal(t, "me", cli.Build.Author) | ||
assert.Equal(t, "value1", cli.Build.DefaultLabels["label1"]) | ||
assert.Equal(t, "value2", cli.Build.DefaultLabels["label2"]) | ||
assert.Equal(t, "value3", cli.Build.Labels["label3"]) | ||
assert.Equal(t, "value4", cli.Build.Labels["label4"]) | ||
|
||
assert.Equal(t, "/tmp-dir", cli.Build.Tmp) | ||
assert.Equal(t, true, cli.Build.Verbose) | ||
} | ||
|
||
func mustNew(t *testing.T, cli interface{}, options ...kong.Option) *kong.Kong { | ||
t.Helper() | ||
options = append([]kong.Option{ | ||
kong.Name("test"), | ||
kong.Exit(func(int) { | ||
t.Helper() | ||
t.Fatalf("unexpected exit()") | ||
}), | ||
}, options...) | ||
parser, err := kong.New(cli, options...) | ||
assert.NilError(t, err) | ||
return parser | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters