diff --git a/cmd/minikube/cmd/generate-docs_test.go b/cmd/minikube/cmd/generate-docs_test.go new file mode 100644 index 0000000000..06178eda95 --- /dev/null +++ b/cmd/minikube/cmd/generate-docs_test.go @@ -0,0 +1,47 @@ +/* +Copyright 2020 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cmd + +import ( + "fmt" + "io/ioutil" + "path/filepath" + "testing" + + "k8s.io/minikube/pkg/generate" +) + +func TestCommandsDocs(t *testing.T) { + dir := "../../../site/content/en/docs/Reference/Commands/" + + for _, sc := range RootCmd.Commands() { + t.Run(sc.Name(), func(t *testing.T) { + fp := filepath.Join(dir, fmt.Sprintf("%s.md", sc.Name())) + expectedContents, err := ioutil.ReadFile(fp) + if err != nil { + t.Fatalf("Docs are not updated. Please run `make generate-docs` to update commands documentation: %v", err) + } + actualContents, err := generate.DocForCommand(sc) + if err != nil { + t.Fatalf("error getting contents: %v", err) + } + if string(actualContents) != string(expectedContents) { + t.Fatalf("Docs are not updated. Please run `make generate-docs` to update commands documentation.") + } + }) + } +} diff --git a/pkg/generate/docs.go b/pkg/generate/docs.go index 887a8c684c..905009ef7b 100644 --- a/pkg/generate/docs.go +++ b/pkg/generate/docs.go @@ -38,7 +38,7 @@ import ( func Docs(root *cobra.Command, path string) error { cmds := root.Commands() for _, c := range cmds { - contents, err := docForCommand(c) + contents, err := DocForCommand(c) if err != nil { return errors.Wrapf(err, "generating doc for %s", c.Name) } @@ -49,7 +49,7 @@ func Docs(root *cobra.Command, path string) error { return nil } -func docForCommand(command *cobra.Command) ([]byte, error) { +func DocForCommand(command *cobra.Command) ([]byte, error) { buf := bytes.NewBuffer([]byte{}) if err := generateTitle(command, buf); err != nil { return nil, errors.Wrap(err, "generating title")