Skip to content

Commit

Permalink
Format import statements, use conditions method
Browse files Browse the repository at this point in the history
  • Loading branch information
ShajithaMohammed committed Oct 21, 2021
1 parent e2deded commit c4f1080
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 35 deletions.
5 changes: 3 additions & 2 deletions test/e2e/annotations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,9 @@ data:
require.NoErrorf(t, err, "Expected to successfully unmarshal")

_, versionedAnnExists := respKubectl.Annotations["kapp.k14s.io/versioned"]
isConditionsMet := respKubectl.Kind == "ConfigMap" || respKubectl.Name == "config" || versionedAnnExists
require.True(t, isConditionsMet, "Expected to have versioned ConfigMap resource")
require.Condition(t, func() bool {
return respKubectl.Kind == "ConfigMap" && respKubectl.Name == "config" && versionedAnnExists
}, "Expected to have versioned ConfigMap resource")

kappOut, _ := kapp.RunWithOpts([]string{"deploy", "-f", "-", "-a", name, "--json"},
RunOpts{IntoNs: true, StdinReader: strings.NewReader(yaml)})
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func NewPresentClusterResource(kind, name, ns string, kubectl Kubectl) ClusterRe

func NewMissingClusterResource(t *testing.T, kind, name, ns string, kubectl Kubectl) {
_, err := kubectl.RunWithOpts([]string{"get", kind, name, "-n", ns, "-o", "yaml"}, RunOpts{AllowError: true})
isConditionsMet := err != nil || strings.Contains(err.Error(), "Error from server (NotFound)")

require.True(t, isConditionsMet, "Expected resource to not exist")
require.Condition(t, func() bool {
return err != nil && strings.Contains(err.Error(), "Error from server (NotFound)")
}, "Expected resource to not exist")
}

func (r ClusterResource) UID() string {
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func validateChanges(t *testing.T, respTable []ui.JSONUITableResp, expected []ma
delete(row, "age")
}

require.Exactlyf(t, expected, respTable[0].Rows, "Expected to see correct changes, but did not")
require.Equalf(t, notesOp, respTable[0].Notes[0], "Expected to see correct summary, but did not")
require.Equalf(t, notesWaitTo, respTable[0].Notes[1], "Expected to see correct summary, but did not")
require.Exactlyf(t, expected, respTable[0].Rows, "Expected to see correct changes, but did not: '%s'", output)
require.Equalf(t, notesOp, respTable[0].Notes[0], "Expected to see correct summary, but did not: '%s'", output)
require.Equalf(t, notesWaitTo, respTable[0].Notes[1], "Expected to see correct summary, but did not: '%s'", output)

}
4 changes: 2 additions & 2 deletions test/e2e/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ secrets:
secrets := NewPresentClusterResource("serviceaccount", "test-sa-with-secrets", env.Namespace, kubectl).RawPath(ctlres.NewPathFromStrings([]string{"secrets"})).([]interface{})

require.Len(t, secrets, 2, "Expected one set and one generated secret")
require.Exactlyf(t, map[string]interface{}{"name": "some-secret"}, secrets[0], "Expected provided secret")
require.Exactlyf(t, map[string]interface{}{"name": "some-secret"}, secrets[0], "Expected provided secret at idx0: %#v", secrets[0])

generatedSecretName = secrets[1].(map[string]interface{})["name"].(string)
require.True(t, strings.HasPrefix(generatedSecretName, "test-sa-with-secrets-token-"), "Expected generated secret at idx1: %#v", secrets[1])
Expand Down Expand Up @@ -247,9 +247,9 @@ secrets:

secrets = NewPresentClusterResource("serviceaccount", "test-sa-without-secrets", env.Namespace, kubectl).RawPath(ctlres.NewPathFromStrings([]string{"secrets"})).([]interface{})

require.True(t, strings.HasPrefix(secrets[1].(map[string]interface{})["name"].(string), "test-sa-without-secrets-token-"), "Expected generated secret at idx1: %#v", secrets[1])
require.Len(t, secrets, 2, "Expected one set and one generated secret")
require.Exactlyf(t, map[string]interface{}{"name": "some-secret"}, secrets[0], "Expected provided secret at idx0")
require.True(t, strings.HasPrefix(secrets[1].(map[string]interface{})["name"].(string), "test-sa-without-secrets-token-"), "Expected generated secret at idx1: %#v", secrets[1])

})

Expand Down
2 changes: 2 additions & 0 deletions test/e2e/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ func TestDiffExitStatus(t *testing.T) {
RunOpts{IntoNs: true, AllowError: true, StdinReader: strings.NewReader("---\n")})

require.Errorf(t, err, "Expected to receive error")

require.Containsf(t, err.Error(), "Exiting after diffing with no pending changes (exit status 2)", "Expected to find stderr output")
require.Containsf(t, err.Error(), "exit code: '2'", "Expected to find exit code")

Expand All @@ -255,6 +256,7 @@ metadata:
RunOpts{IntoNs: true, AllowError: true, StdinReader: strings.NewReader(yaml1)})

require.Errorf(t, err, "Expected to receive error")

require.Containsf(t, err.Error(), "Exiting after diffing with pending changes (exit status 3)", "Expected to find stderr output")
require.Containsf(t, err.Error(), "exit code: '3'", "Expected to find exit code")
}
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
package e2e

import (
"github.com/stretchr/testify/require"
"os"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

type Env struct {
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
package e2e

import (
"github.com/stretchr/testify/require"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func TestFilter(t *testing.T) {
Expand Down
10 changes: 3 additions & 7 deletions test/e2e/formatted_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
package e2e

import (
"github.com/stretchr/testify/require"
"regexp"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func TestFormattedError(t *testing.T) {
Expand Down Expand Up @@ -71,11 +72,6 @@ kapp: Error: Applying create job/successful-job (batch/v1) namespace: default:
replaceUIDs := regexp.MustCompile(`"controller-uid":"[^"]+"`)
out = replaceUIDs.ReplaceAllString(out, "-replaced-")

require.Containsf(t, out, expectedErr, "Expected to see expected err in output, but did not: %d chars >>>%s<<< vs %d chars >>>%s<<<",
len(out), replaceSpace(out), len(expectedErr), replaceSpace(expectedErr))
require.Containsf(t, out, expectedErr, "Expected to see expected err in output, but did not")
})
}

func replaceSpace(in string) string {
return strings.ReplaceAll(in, " ", "#")
}
5 changes: 2 additions & 3 deletions test/e2e/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ func TestHelpCommandGroup(t *testing.T) {
kapp := Kapp{t, env.Namespace, env.KappBinaryPath, Logger{}}

_, err := kapp.RunWithOpts([]string{"app-group"}, RunOpts{NoNamespace: true, AllowError: true})

require.Errorf(t, err, "Expected to receive error")
require.Contains(t, err.Error(), "Error: Use one of available subcommands: delete, deploy",
"Expected helpful error message")

require.Contains(t, err.Error(), "Error: Use one of available subcommands: delete, deploy", "Expected helpful error message")
}
12 changes: 5 additions & 7 deletions test/e2e/ignore_failing_api_services_flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ metadata:
logger.Section("deploy app that uses failing api service", func() {
_, err := kapp.RunWithOpts([]string{"deploy", "-f", "-", "-a", name3}, RunOpts{
AllowError: true, IntoNs: true, StdinReader: strings.NewReader(yaml3)})

require.Errorf(t, err, "Expected error when deploying with failing api service")

require.Contains(t, err.Error(), "unable to retrieve the complete list of server APIs: dummykapptest.com/v1: the server is currently unable to handle the request",
"Expected api retrieval error")
})
Expand All @@ -139,10 +139,9 @@ metadata:

_, err := kapp.RunWithOpts([]string{"deploy", "-f", "-", "-a", name3, ignoreFlag}, RunOpts{
AllowError: true, IntoNs: true, StdinReader: strings.NewReader(yaml3)})

require.Errorf(t, err, "Expected error when deploying with failing api service")
require.Contains(t, err.Error(), "Expected to find kind 'dummykapptest.com/v1/Foo', but did not",
"Expected CRD retrieval error")

require.Contains(t, err.Error(), "Expected to find kind 'dummykapptest.com/v1/Foo', but did not", "Expected CRD retrieval error")
})

logger.Section("delete app that does not use api service", func() {
Expand Down Expand Up @@ -279,10 +278,9 @@ spec: {}
logger.Section("deploy app that uses failing group version", func() {
_, err := kapp.RunWithOpts([]string{"deploy", "-f", "-", "-a", name3, "--apply-timeout=5s"}, RunOpts{
AllowError: true, IntoNs: true, StdinReader: strings.NewReader(yaml3)})

require.Errorf(t, err, "Expected error when deploying with failing group version")
require.Contains(t, err.Error(), `service "failing-group-version-webhook" not found`,
"Expected api retrieval error")

require.Contains(t, err.Error(), `service "failing-group-version-webhook" not found`, "Expected api retrieval error")
})

logger.Section("delete app that uses failing group version", func() {
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/kapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ package e2e
import (
"bytes"
"fmt"
"github.com/stretchr/testify/require"
"io"
"os"
"os/exec"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

type Kapp struct {
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ package e2e
import (
"bytes"
"fmt"
"github.com/stretchr/testify/require"
"os"
"os/exec"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

type Kubectl struct {
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
package e2e

import (
"github.com/stretchr/testify/require"
"regexp"
"sort"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func TestOrder(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/update_replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
package e2e

import (
"github.com/stretchr/testify/require"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func TestUpdateFallbackOnReplace(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/update_retry_on_conflict_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ spec:
_, err := kapp.RunWithOpts([]string{"deploy", "--tty", "-f", tmpFile.Name(), "-a", name},
RunOpts{IntoNs: true, StdinReader: promptOutput.YesReader(),
StdoutWriter: promptOutput.OutputWriter(), Interactive: true, AllowError: true})

require.Errorf(t, err, "Expected error, but err was nil")

require.Contains(t, err.Error(), "Failed to update due to resource conflict (approved diff no longer matches)",
Expand Down Expand Up @@ -312,7 +311,8 @@ func (p promptOutput) WaitPresented() {
break
}
}
require.NoError(p.t, scanner.Err())
err := scanner.Err()
require.NoError(p.t, err)
}

func newTmpFile(content string, t *testing.T) *os.File {
Expand Down

0 comments on commit c4f1080

Please sign in to comment.