@@ -17,67 +17,39 @@ package clidocstool
1717import (
1818 "io/ioutil"
1919 "os"
20+ "path"
2021 "path/filepath"
2122 "testing"
2223
23- "github.com/spf13/cobra"
2424 "github.com/stretchr/testify/assert"
2525 "github.com/stretchr/testify/require"
2626)
2727
2828//nolint:errcheck
2929func TestGenMarkdownTree (t * testing.T ) {
30- c := & cobra.Command {Use : "do [OPTIONS] arg1 arg2" }
31- s := & cobra.Command {Use : "sub [OPTIONS] arg1 arg2" }
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-
68- c .AddCommand (s )
69-
7030 tmpdir , err := ioutil .TempDir ("" , "test-gen-markdown-tree" )
7131 require .NoError (t , err )
72-
7332 defer os .RemoveAll (tmpdir )
74- require .NoError (t , GenMarkdownTree (c , tmpdir ))
7533
76- fres := filepath . Join ( tmpdir , "sub.md" )
77- require . FileExists ( t , fres )
78- bres , err := ioutil . ReadFile ( fres )
79- require . NoError ( t , err )
80- bexc , err := ioutil . ReadFile ( "fixtures/sub.md" )
34+ c , err := New ( Options {
35+ Root : buildxCmd ,
36+ SourceDir : tmpdir ,
37+ Plugin : true ,
38+ } )
8139 require .NoError (t , err )
82- assert .Equal (t , string (bres ), string (bexc ))
40+ require .NoError (t , c .GenMarkdownTree (buildxCmd ))
41+
42+ for _ , tt := range []string {"buildx.md" , "buildx_build.md" } {
43+ tt := tt
44+ t .Run (tt , func (t * testing.T ) {
45+ fres := filepath .Join (tmpdir , tt )
46+ require .FileExists (t , fres )
47+ bres , err := ioutil .ReadFile (fres )
48+ require .NoError (t , err )
49+
50+ bexc , err := ioutil .ReadFile (path .Join ("fixtures" , tt ))
51+ require .NoError (t , err )
52+ assert .Equal (t , string (bexc ), string (bres ))
53+ })
54+ }
8355}
0 commit comments