write to a file and move code around for clarity

pull/11120/head
Sharif Elgamal 2021-04-16 15:33:50 -07:00
parent 7cd2dcfee8
commit 245f44da66
5 changed files with 487 additions and 80 deletions

View File

@ -360,7 +360,7 @@ test: $(SOURCE_GENERATED) ## Trigger minikube test
.PHONY: generate-docs
generate-docs: out/minikube ## Automatically generate commands documentation.
out/minikube generate-docs --path ./site/content/en/docs/commands/
out/minikube generate-docs --path ./site/content/en/docs/commands/ --test-path ./site/content/en/docs/contrib/tests.en.md
.PHONY: gotest
gotest: $(SOURCE_GENERATED) ## Trigger minikube test

View File

@ -28,6 +28,7 @@ import (
)
var docsPath string
var testPath string
// generateDocs represents the generate-docs command
var generateDocs = &cobra.Command{
@ -44,14 +45,16 @@ var generateDocs = &cobra.Command{
}
// generate docs
if err := generate.Docs(RootCmd, docsPath); err != nil {
if err := generate.Docs(RootCmd, docsPath, testPath); err != nil {
exit.Error(reason.InternalGenerateDocs, "Unable to generate docs", err)
}
out.Step(style.Documentation, "Docs have been saved at - {{.path}}", out.V{"path": docsPath})
out.Step(style.Documentation, "Test docs have been saved at - {{.path}}", out.V{"path": testPath})
},
}
func init() {
generateDocs.Flags().StringVar(&docsPath, "path", "", "The path on the file system where the docs in markdown need to be saved")
generateDocs.Flags().StringVar(&testPath, "test-path", "", "The path on the file system where the testing docs in markdown need to be saved")
RootCmd.AddCommand(generateDocs)
}

View File

@ -19,14 +19,10 @@ package generate
import (
"bytes"
"fmt"
"go/ast"
"go/parser"
"go/token"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"
"github.com/pkg/errors"
@ -36,8 +32,8 @@ import (
)
// Docs generates docs for minikube command
func Docs(root *cobra.Command, path string) error {
/*cmds := root.Commands()
func Docs(root *cobra.Command, path string, testPath string) error {
cmds := root.Commands()
for _, c := range cmds {
if c.Hidden {
klog.Infof("Skipping generating doc for %s as it's a hidden command", c.Name())
@ -50,8 +46,8 @@ func Docs(root *cobra.Command, path string) error {
if err := saveDocForCommand(c, []byte(contents), path); err != nil {
return errors.Wrapf(err, "saving doc for %s", c.Name())
}
}*/
return tests()
}
return testDocs(testPath)
}
// DocForCommand returns the specific doc for that command
@ -167,73 +163,3 @@ func saveDocForCommand(command *cobra.Command, contents []byte, path string) err
}
return ioutil.WriteFile(fp, contents, 0o644)
}
func tests() error {
counter := 0
err := filepath.Walk("test/integration", func(path string, info os.FileInfo, err error) error {
if info.IsDir() || !strings.HasSuffix(path, ".go") {
return nil
}
fset := token.NewFileSet()
r, e := ioutil.ReadFile(path)
if e != nil {
return errors.Wrap(e, fmt.Sprintf("error reading file %s", path))
}
file, e := parser.ParseFile(fset, "", r, parser.ParseComments)
if e != nil {
return errors.Wrap(e, fmt.Sprintf("error parsing file %s", path))
}
ast.Inspect(file, func(x ast.Node) bool {
if fd, ok := x.(*ast.FuncDecl); ok {
fnName := fd.Name.Name
if !shouldParse(fnName) {
return true
}
subtest := false
if strings.HasPrefix(fnName, "valid") {
subtest = true
fnName = fmt.Sprintf("\t%s", fnName)
}
fmt.Println(fnName)
counter++
comments := fd.Doc
if comments == nil {
if subtest {
fmt.Print("\t")
}
fmt.Println("NEEDS DOC")
fmt.Println("")
return true
}
for _, comment := range comments.List {
if strings.Contains(comment.Text, "TODO") {
continue
}
if subtest {
fmt.Print("\t")
}
fmt.Println(comment.Text)
}
fmt.Println("")
}
return true
})
return nil
})
fmt.Printf("TEST COUNT: %d\n", counter)
return err
}
func shouldParse(name string) bool {
if strings.HasPrefix(name, "Test") && !strings.HasPrefix(name, "TestMain") {
return true
}
if strings.HasPrefix(name, "valid") {
return true
}
return false
}

130
pkg/generate/testdocs.go Normal file
View File

@ -0,0 +1,130 @@
/*
Copyright 2021 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 generate
import (
"bytes"
"fmt"
"go/ast"
"go/parser"
"go/token"
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/out"
)
func testDocs(docPath string) error {
counter := 0
buf := bytes.NewBuffer([]byte{})
date := time.Now().Format("2006-01-02")
title := out.Fmt(title, out.V{"Command": "Integration Tests", "Description": "All minikube integration tests", "Date": date})
_, err := buf.Write([]byte(title))
if err != nil {
return err
}
err = filepath.Walk("test/integration", func(path string, info os.FileInfo, err error) error {
if info.IsDir() || !strings.HasSuffix(path, ".go") {
return nil
}
fset := token.NewFileSet()
r, e := ioutil.ReadFile(path)
if e != nil {
return errors.Wrap(e, fmt.Sprintf("error reading file %s", path))
}
file, e := parser.ParseFile(fset, "", r, parser.ParseComments)
if e != nil {
return errors.Wrap(e, fmt.Sprintf("error parsing file %s", path))
}
ast.Inspect(file, func(x ast.Node) bool {
if fd, ok := x.(*ast.FuncDecl); ok {
fnName := fd.Name.Name
if !shouldParse(fnName) {
return true
}
if strings.HasPrefix(fnName, "valid") {
writeSubTest(fnName, buf)
} else {
writeTest(fnName, buf)
}
counter++
comments := fd.Doc
if comments == nil {
writeComment("NEEDS DOC\n", buf)
return true
}
for _, comment := range comments.List {
if strings.Contains(comment.Text, "TODO") {
continue
}
writeComment(comment.Text, buf)
}
buf.WriteString("\n")
}
return true
})
return nil
})
if err != nil {
return err
}
_, err = buf.WriteString(fmt.Sprintf("TEST COUNT: %d\n", counter))
if err != nil {
return err
}
err = ioutil.WriteFile(docPath, buf.Bytes(), 0o644)
return err
}
func shouldParse(name string) bool {
if strings.HasPrefix(name, "Test") && !strings.HasPrefix(name, "TestMain") {
return true
}
if strings.HasPrefix(name, "valid") {
return true
}
return false
}
func writeTest(testName string, w *bytes.Buffer) error {
_, err := w.WriteString("## " + testName + "\n")
return err
}
func writeSubTest(testName string, w *bytes.Buffer) error {
_, err := w.WriteString("#### " + testName + "\n")
return err
}
func writeComment(comment string, w *bytes.Buffer) error {
// Remove the leading // from the testdoc comments
comment = comment[3:]
_, err := w.WriteString(comment + "\n")
return err
}

View File

@ -0,0 +1,348 @@
---
title: "Integration Tests"
description: >
All minikube integration tests
---
## TestDownloadOnly
TestDownloadOnly makes sure the --download-only parameter in minikube start caches the appropriate images and tarballs.
## TestDownloadOnlyKic
TestDownloadOnlyKic makes sure --download-only caches the docker driver images as well.
## TestOffline
TestOffline makes sure minikube works without internet, once the user has cached the necessary images.
This test has to run after TestDownloadOnly.
## TestAddons
TestAddons tests addons that require no special environment in parallel
#### validateIngressAddon
validateIngressAddon tests the ingress addon by deploying a default nginx pod
#### validateRegistryAddon
validateRegistryAddon tests the registry addon
#### validateMetricsServerAddon
validateMetricsServerAddon tests the metrics server addon by making sure "kubectl top pods" returns a sensible result
#### validateHelmTillerAddon
validateHelmTillerAddon tests the helm tiller addon by running "helm version" inside the cluster
#### validateOlmAddon
validateOlmAddon tests the OLM addon
#### validateCSIDriverAndSnapshots
validateCSIDriverAndSnapshots tests the csi hostpath driver by creating a persistent volume, snapshotting it and restoring it.
#### validateGCPAuthAddon
validateGCPAuthAddon tests the GCP Auth addon with either phony or real credentials and makes sure the files are mounted into pods correctly
## TestCertOptions
TestCertOptions makes sure minikube certs respect the --apiserver-ips and --apiserver-names parameters
## TestDockerFlags
TestDockerFlags makes sure the --docker-env and --docker-opt parameters are respected
## TestForceSystemdFlag
TestForceSystemdFlag tests the --force-systemd flag, as one would expect.
#### validateDockerSystemd
validateDockerSystemd makes sure the --force-systemd flag worked with the docker container runtime
#### validateContainerdSystemd
validateContainerdSystemd makes sure the --force-systemd flag worked with the containerd container runtime
## TestForceSystemdEnv
TestForceSystemdEnv makes sure the MINIKUBE_FORCE_SYSTEMD environment variable works just as well as the --force-systemd flag
## TestKVMDriverInstallOrUpdate
TestKVMDriverInstallOrUpdate makes sure our docker-machine-driver-kvm2 binary can be installed properly
## TestHyperKitDriverInstallOrUpdate
TestHyperKitDriverInstallOrUpdate makes sure our docker-machine-driver-hyperkit binary can be installed properly
## TestHyperkitDriverSkipUpgrade
TestHyperkitDriverSkipUpgrade makes sure our docker-machine-driver-hyperkit binary can be installed properly
## TestErrorSpam
TestErrorSpam asserts that there are no unexpected errors displayed in minikube command outputs.
## TestFunctional
TestFunctional are functionality tests which can safely share a profile in parallel
#### validateNodeLabels
validateNodeLabels checks if minikube cluster is created with correct kubernetes's node label
#### validateLoadImage
validateLoadImage makes sure that `minikube load image` works as expected
#### validateRemoveImage
validateRemoveImage makes sures that `minikube rm image` works as expected
#### validateDockerEnv
check functionality of minikube after evaling docker-env
#### validateStartWithProxy
validateStartWithProxy makes sure minikube start respects the HTTP_PROXY environment variable
#### validateAuditAfterStart
validateAuditAfterStart makes sure the audit log contains the correct logging after minikube start
#### validateSoftStart
validateSoftStart validates that after minikube already started, a "minikube start" should not change the configs.
#### validateKubeContext
validateKubeContext asserts that kubectl is properly configured (race-condition prone!)
#### validateKubectlGetPods
validateKubectlGetPods asserts that `kubectl get pod -A` returns non-zero content
#### validateMinikubeKubectl
validateMinikubeKubectl validates that the `minikube kubectl` command returns content
#### validateMinikubeKubectlDirectCall
validateMinikubeKubectlDirectCall validates that calling minikube's kubectl
#### validateExtraConfig
validateExtraConfig verifies minikube with --extra-config works as expected
#### validateComponentHealth
validateComponentHealth asserts that all Kubernetes components are healthy
NOTE: It expects all components to be Ready, so it makes sense to run it close after only those tests that include '--wait=all' start flag
#### validateStatusCmd
validateStatusCmd makes sure minikube status outputs correctly
#### validateDashboardCmd
validateDashboardCmd asserts that the dashboard command works
#### validateDryRun
validateDryRun asserts that the dry-run mode quickly exits with the right code
#### validateCacheCmd
validateCacheCmd tests functionality of cache command (cache add, delete, list)
#### validateConfigCmd
validateConfigCmd asserts basic "config" command functionality
#### validateLogsCmd
validateLogsCmd asserts basic "logs" command functionality
#### validateProfileCmd
validateProfileCmd asserts "profile" command functionality
#### validateServiceCmd
validateServiceCmd asserts basic "service" command functionality
#### validateAddonsCmd
validateAddonsCmd asserts basic "addon" command functionality
#### validateSSHCmd
validateSSHCmd asserts basic "ssh" command functionality
#### validateCpCmd
validateCpCmd asserts basic "cp" command functionality
#### validateMySQL
validateMySQL validates a minimalist MySQL deployment
#### validateFileSync
validateFileSync to check existence of the test file
#### validateCertSync
validateCertSync to check existence of the test certificate
#### validateUpdateContextCmd
validateUpdateContextCmd asserts basic "update-context" command functionality
#### validateMountCmd
validateMountCmd verifies the minikube mount command works properly
#### validatePersistentVolumeClaim
validatePersistentVolumeClaim makes sure PVCs work properly
#### validateTunnelCmd
validateTunnelCmd makes sure the minikube tunnel command works as expected
#### validateTunnelStart
validateTunnelStart starts `minikube tunnel`
#### validateServiceStable
validateServiceStable starts nginx pod, nginx service and waits nginx having loadbalancer ingress IP
#### validateAccessDirect
validateAccessDirect validates if the test service can be accessed with LoadBalancer IP from host
#### validateDNSDig
validateDNSDig validates if the DNS forwarding works by dig command DNS lookup
NOTE: DNS forwarding is experimental: https://minikube.sigs.k8s.io/docs/handbook/accessing/#dns-resolution-experimental
#### validateDNSDscacheutil
validateDNSDscacheutil validates if the DNS forwarding works by dscacheutil command DNS lookup
NOTE: DNS forwarding is experimental: https://minikube.sigs.k8s.io/docs/handbook/accessing/#dns-resolution-experimental
#### validateAccessDNS
validateAccessDNS validates if the test service can be accessed with DNS forwarding from host
NOTE: DNS forwarding is experimental: https://minikube.sigs.k8s.io/docs/handbook/accessing/#dns-resolution-experimental
#### validateTunnelDelete
validateTunnelDelete stops `minikube tunnel`
## TestGuestEnvironment
TestGuestEnvironment verifies files and packges installed inside minikube ISO/Base image
## TestGvisorAddon
TestGvisorAddon tests the functionality of the gVisor addon
## TestJSONOutput
TestJSONOutput makes sure json output works properly for the start, pause, unpause, and stop commands
#### validateDistinctCurrentSteps
validateDistinctCurrentSteps makes sure each step has a distinct step number
#### validateIncreasingCurrentSteps
validateIncreasingCurrentSteps verifies that for a successful minikube start, 'current step' should be increasing
## TestErrorJSONOutput
TestErrorJSONOutput makes sure json output can print errors properly
## TestKicCustomNetwork
TestKicCustomNetwork verifies the docker driver works with a custom network
## TestKicExistingNetwork
TestKicExistingNetwork verifies the docker driver and run with an existing network
## TestingKicBaseImage
TestingKicBaseImage will return true if the integraiton test is running against a passed --base-image flag
## TestMultiNode
TestMultiNode tests all multi node cluster functionality
#### validateMultiNodeStart
validateMultiNodeStart makes sure a 2 node cluster can start
#### validateAddNodeToMultiNode
validateAddNodeToMultiNode uses the minikube node add command to add a node to an existing cluster
#### validateProfileListWithMultiNode
validateProfileListWithMultiNode make sure minikube profile list outputs correct with multinode clusters
#### validateStopRunningNode
validateStopRunningNode tests the minikube node stop command
#### validateStartNodeAfterStop
validateStartNodeAfterStop tests the minikube node start command on an existing stopped node
#### validateStopMultiNodeCluster
validateStopMultiNodeCluster runs minikube stop on a multinode cluster
#### validateRestartMultiNodeCluster
validateRestartMultiNodeCluster verifies a soft restart on a multinode cluster works
#### validateDeleteNodeFromMultiNode
validateDeleteNodeFromMultiNode tests the minikube node delete command
#### validateNameConflict
validateNameConflict tests that the node name verification works as expected
#### validateDeployAppToMultiNode
validateDeployAppToMultiNode deploys an app to a multinode cluster and makes sure all nodes can serve traffic
## TestNetworkPlugins
TestNetworkPlugins tests all supported CNI options
Options tested: kubenet, bridge, flannel, kindnet, calico, cilium
Flags tested: enable-default-cni (legacy), false (CNI off), auto-detection
## TestChangeNoneUser
TestChangeNoneUser tests to make sure the CHANGE_MINIKUBE_NONE_USER environemt variable is respected
and changes the minikube file permissions from root to the correct user.
## TestPause
TestPause tests minikube pause functionality
#### validateFreshStart
validateFreshStart just starts a new minikube cluster
#### validateStartNoReconfigure
validateStartNoReconfigure validates that starting a running cluster does not invoke reconfiguration
#### validatePause
validatePause runs minikube pause
#### validateUnpause
validateUnpause runs minikube unpause
#### validateDelete
validateDelete deletes the unpaused cluster
#### validateVerifyDeleted
validateVerifyDeleted makes sure no left over left after deleting a profile such as containers or volumes
#### validateStatus
validateStatus makes sure paused clusters show up in minikube status correctly
## TestDebPackageInstall
TestPackageInstall tests installation of .deb packages with minikube itself and with kvm2 driver
on various debian/ubuntu docker images
## TestPreload
TestPreload verifies the preload tarballs get pulled in properly by minikube
## TestScheduledStopWindows
TestScheduledStopWindows tests the schedule stop functionality on Windows
## TestScheduledStopUnix
TestScheduledStopWindows tests the schedule stop functionality on Unix
## TestSkaffold
TestSkaffold makes sure skaffold run can be run with minikube
## TestStartStop
TestStartStop tests starting, stopping and restarting a minikube clusters with various Kubernetes versions and configurations
The oldest supported, newest supported and default Kubernetes versions are always tested.
#### validateFirstStart
validateFirstStart runs the initial minikube start
#### validateDeploying
validateDeploying deploys an app the minikube cluster
#### validateStop
validateStop tests minikube stop
#### validateEnableAddonAfterStop
validateEnableAddonAfterStop makes sure addons can be enabled on a stopped cluster
#### validateSecondStart
validateSecondStart verifies that starting a stopped cluster works
#### validateAppExistsAfterStop
validateAppExistsAfterStop verifies that a user's app will not vanish after a minikube stop
#### validateAddonAfterStop
validateAddonAfterStop validates that an addon which was enabled when minikube is stopped will be enabled and working..
#### validateKubernetesImages
validateKubernetesImages verifies that a restarted cluster contains all the necessary images
#### validatePauseAfterStart
validatePauseAfterStart verifies that minikube pause works
## TestInsufficientStorage
TestInsufficientStorage makes sure minikube status displays the correct info if there is insufficient disk space on the machine
## TestRunningBinaryUpgrade
TestRunningBinaryUpgrade upgrades a running legacy cluster to minikube at HEAD
## TestStoppedBinaryUpgrade
TestStoppedBinaryUpgrade starts a legacy minikube, stops it, and then upgrades to minikube at HEAD
## TestKubernetesUpgrade
TestKubernetesUpgrade upgrades Kubernetes from oldest to newest
## TestMissingContainerUpgrade
TestMissingContainerUpgrade tests a Docker upgrade where the underlying container is missing
TEST COUNT: 110