@@ -21,24 +21,63 @@ import (
2121 "testing"
2222
2323 "github.com/spf13/cobra"
24+ "github.com/stretchr/testify/assert"
25+ "github.com/stretchr/testify/require"
2426)
2527
28+ //nolint:errcheck
2629func TestGenYamlTree (t * testing.T ) {
2730 c := & cobra.Command {Use : "do [OPTIONS] arg1 arg2" }
2831 s := & cobra.Command {Use : "sub [OPTIONS] arg1 arg2" , Run : func (cmd * cobra.Command , args []string ) {}}
32+
33+ flags := s .Flags ()
34+ _ = flags .Bool ("push" , false , "Shorthand for --output=type=registry" )
35+ _ = flags .Bool ("load" , false , "Shorthand for --output=type=docker" )
36+ _ = flags .StringArrayP ("tag" , "t" , []string {}, "Name and optionally a tag in the 'name:tag' format" )
37+ flags .SetAnnotation ("tag" , "docs.external.url" , []string {"https://docs.docker.com/engine/reference/commandline/build/#tag-an-image--t" })
38+ _ = flags .StringArray ("build-arg" , []string {}, "Set build-time variables" )
39+ flags .SetAnnotation ("build-arg" , "docs.external.url" , []string {"https://docs.docker.com/engine/reference/commandline/build/#set-build-time-variables---build-arg" })
40+ _ = flags .StringP ("file" , "f" , "" , "Name of the Dockerfile (Default is 'PATH/Dockerfile')" )
41+ flags .SetAnnotation ("file" , "docs.external.url" , []string {"https://docs.docker.com/engine/reference/commandline/build/#specify-a-dockerfile--f" })
42+ _ = flags .StringArray ("label" , []string {}, "Set metadata for an image" )
43+ _ = flags .StringArray ("cache-from" , []string {}, "External cache sources (eg. user/app:cache, type=local,src=path/to/dir)" )
44+ _ = flags .StringArray ("cache-to" , []string {}, "Cache export destinations (eg. user/app:cache, type=local,dest=path/to/dir)" )
45+ _ = flags .String ("target" , "" , "Set the target build stage to build." )
46+ flags .SetAnnotation ("target" , "docs.external.url" , []string {"https://docs.docker.com/engine/reference/commandline/build/#specifying-target-build-stage---target" })
47+ _ = flags .StringSlice ("allow" , []string {}, "Allow extra privileged entitlement, e.g. network.host, security.insecure" )
48+ _ = flags .StringArray ("platform" , []string {}, "Set target platform for build" )
49+ _ = flags .StringArray ("secret" , []string {}, "Secret file to expose to the build: id=mysecret,src=/local/secret" )
50+ _ = flags .StringArray ("ssh" , []string {}, "SSH agent socket or keys to expose to the build (format: `default|<id>[=<socket>|<key>[,<key>]]`)" )
51+ _ = flags .StringArrayP ("output" , "o" , []string {}, "Output destination (format: type=local,dest=path)" )
52+ // not implemented
53+ _ = flags .String ("network" , "default" , "Set the networking mode for the RUN instructions during build" )
54+ _ = flags .StringSlice ("add-host" , []string {}, "Add a custom host-to-IP mapping (host:ip)" )
55+ _ = flags .SetAnnotation ("add-host" , "docs.external.url" , []string {"https://docs.docker.com/engine/reference/commandline/build/#add-entries-to-container-hosts-file---add-host" })
56+ _ = flags .String ("iidfile" , "" , "Write the image ID to the file" )
57+ // hidden flags
58+ _ = flags .BoolP ("quiet" , "q" , false , "Suppress the build output and print image ID on success" )
59+ flags .MarkHidden ("quiet" )
60+ _ = flags .Bool ("squash" , false , "Squash newly built layers into a single new layer" )
61+ flags .MarkHidden ("squash" )
62+ _ = flags .String ("ulimit" , "" , "Ulimit options" )
63+ flags .MarkHidden ("ulimit" )
64+ _ = flags .StringSlice ("security-opt" , []string {}, "Security options" )
65+ flags .MarkHidden ("security-opt" )
66+ _ = flags .Bool ("compress" , false , "Compress the build context using gzip" )
67+
2968 c .AddCommand (s )
3069
3170 tmpdir , err := ioutil .TempDir ("" , "test-gen-yaml-tree" )
32- if err != nil {
33- t .Fatalf ("Failed to create tmpdir: %s" , err .Error ())
34- }
35- defer os .RemoveAll (tmpdir )
71+ require .NoError (t , err )
3672
37- if err := GenYamlTree (c , tmpdir ); err != nil {
38- t .Fatalf ("GenYamlTree failed: %s" , err .Error ())
39- }
73+ defer os .RemoveAll (tmpdir )
74+ require .NoError (t , GenYamlTree (c , tmpdir ))
4075
41- if _ , err := os .Stat (filepath .Join (tmpdir , "do_sub.yaml" )); err != nil {
42- t .Fatalf ("Expected file 'do_sub.yaml' to exist" )
43- }
76+ fres := filepath .Join (tmpdir , "do_sub.yaml" )
77+ require .FileExists (t , fres )
78+ bres , err := ioutil .ReadFile (fres )
79+ require .NoError (t , err )
80+ bexc , err := ioutil .ReadFile ("fixtures/do_sub.yaml" )
81+ require .NoError (t , err )
82+ assert .Equal (t , string (bres ), string (bexc ))
4483}
0 commit comments