Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check man page with a unit test instead of a script #2180

Merged
merged 1 commit into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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