Skip to content

Commit

Permalink
Check man page with a unit test instead of a script
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot committed Jun 1, 2019
1 parent b139240 commit c4d9702
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
21 changes: 17 additions & 4 deletions cmd/skaffold/man/man_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"bytes"
"io/ioutil"
"testing"

"github.com/GoogleContainerTools/skaffold/testutil"
Expand All @@ -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!")
}
}
10 changes: 0 additions & 10 deletions hack/check-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions hack/generate-man.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c4d9702

Please sign in to comment.