From c4d9702f681660b5f2c42e88daa14908ba5c99a4 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Thu, 23 May 2019 16:54:56 +0200 Subject: [PATCH] Check man page with a unit test instead of a script Signed-off-by: David Gageot --- cmd/skaffold/man/man_test.go | 21 +++++++++++++++++---- hack/check-docs.sh | 10 ---------- hack/generate-man.sh | 20 ++++++++++++++++++++ 3 files changed, 37 insertions(+), 14 deletions(-) create mode 100755 hack/generate-man.sh diff --git a/cmd/skaffold/man/man_test.go b/cmd/skaffold/man/man_test.go index b716ef0afdc..21c67c04b71 100644 --- a/cmd/skaffold/man/man_test.go +++ b/cmd/skaffold/man/man_test.go @@ -18,6 +18,7 @@ package main import ( "bytes" + "io/ioutil" "testing" "github.com/GoogleContainerTools/skaffold/testutil" @@ -28,11 +29,23 @@ func TestPrintMan(t *testing.T) { var stderr bytes.Buffer err := printMan(&stdout, &stderr) + output := stdout.String() + // Sanity checks testutil.CheckError(t, false, err) - testutil.CheckContains(t, "skaffold build", stdout.String()) - testutil.CheckContains(t, "skaffold run", stdout.String()) - testutil.CheckContains(t, "skaffold dev", stdout.String()) - testutil.CheckContains(t, "Env vars", stdout.String()) testutil.CheckDeepEqual(t, "", stderr.String()) + testutil.CheckContains(t, "skaffold build", output) + testutil.CheckContains(t, "skaffold run", output) + testutil.CheckContains(t, "skaffold dev", output) + testutil.CheckContains(t, "Env vars", output) + + // Compare to current man page + header, err := ioutil.ReadFile("../../../docs/content/en/docs/references/cli/index_header") + testutil.CheckError(t, false, err) + + expected, err := ioutil.ReadFile("../../../docs/content/en/docs/references/cli/_index.md") + testutil.CheckError(t, false, err) + if string(expected) != string(header)+output { + t.Error("You have skaffold command changes but haven't generated the CLI reference docs. Please run ./hack/generate-man.sh and commit the results!") + } } diff --git a/hack/check-docs.sh b/hack/check-docs.sh index a5543032df8..fa0d2e91660 100755 --- a/hack/check-docs.sh +++ b/hack/check-docs.sh @@ -14,16 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -cp docs/content/en/docs/references/cli/index_header docs/content/en/docs/references/cli/_index.md -go run cmd/skaffold/man/man.go >> docs/content/en/docs/references/cli/_index.md - -readonly CLI_CHANGES=`git status -s | grep "docs/" | wc -l` - -if [ $CLI_CHANGES -gt 0 ]; then - echo "You have skaffold command changes but haven't generated the CLI reference docs. Please run hack/check-docs.sh and commit the results!" - exit 1 -fi - readonly DOCS_CHANGES=`git diff --name-status master | grep "docs/" | wc -l` if [ $DOCS_CHANGES -gt 0 ]; then diff --git a/hack/generate-man.sh b/hack/generate-man.sh new file mode 100755 index 00000000000..fb86cae4737 --- /dev/null +++ b/hack/generate-man.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# Copyright 2019 The Skaffold Authors +# +# 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. + +cat \ + docs/content/en/docs/references/cli/index_header \ + <(go run cmd/skaffold/man/man.go) \ + > docs/content/en/docs/references/cli/_index.md \ No newline at end of file