Skip to content

Commit

Permalink
e2e fix and manifest changes (#43)
Browse files Browse the repository at this point in the history
Signed-off-by: Takeshi Yoneda <[email protected]>

Co-authored-by: Devarajan Ramaswamy <[email protected]>
  • Loading branch information
mathetake and deva26 authored Jun 23, 2021
1 parent 5994e78 commit eb21f30
Show file tree
Hide file tree
Showing 35 changed files with 318 additions and 788 deletions.
45 changes: 22 additions & 23 deletions api/manifest_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io/ioutil"
"testing"

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

Expand Down Expand Up @@ -47,9 +46,9 @@ func Test_parseManifestEOLDate(t *testing.T) {
a, err := parseManifestEOLDate(c.in)
require.NoError(t, err)
y, m, d := a.Date()
assert.Equal(t, c.expYear, y)
assert.Equal(t, c.expMonth, int(m))
assert.Equal(t, c.expDay, d)
require.Equal(t, c.expYear, y)
require.Equal(t, c.expMonth, int(m))
require.Equal(t, c.expDay, d)
}
})
}
Expand Down Expand Up @@ -84,7 +83,7 @@ func TestIstioDistribution_ToString(t *testing.T) {
exp: "1.8.3-istio-v0",
},
} {
assert.Equal(t, c.exp, c.in.ToString())
require.Equal(t, c.exp, c.in.ToString())
}
}

Expand Down Expand Up @@ -124,7 +123,7 @@ func TestIstioDistributionEqual(t *testing.T) {
exp: false,
},
} {
assert.Equal(t, c.exp, c.in.Equal(operand))
require.Equal(t, c.exp, c.in.Equal(operand))
}
}

Expand Down Expand Up @@ -154,12 +153,12 @@ func TestIstioDistribution_ExistInManifest(t *testing.T) {

ok, err := d.ExistInManifest(ms)
require.NoError(t, err)
assert.True(t, ok)
require.True(t, ok)

d.FlavorVersion--
ok, err = d.ExistInManifest(ms)
require.NoError(t, err)
assert.False(t, ok)
require.False(t, ok)
}

func TestIstioDistribution_Group(t *testing.T) {
Expand All @@ -173,14 +172,14 @@ func TestIstioDistribution_Group(t *testing.T) {
} {
actual, err := c.in.Group()
require.NoError(t, err)
assert.Equal(t, c.exp, actual)
require.Equal(t, c.exp, actual)
}
}

func TestIstioDistribution_IsUpstream(t *testing.T) {
assert.True(t, (&IstioDistribution{Flavor: "istio"}).IsUpstream())
assert.False(t, (&IstioDistribution{Flavor: "tetrate"}).IsUpstream())
assert.False(t, (&IstioDistribution{Flavor: "tetratefips"}).IsUpstream())
require.True(t, (&IstioDistribution{Flavor: "istio"}).IsUpstream())
require.False(t, (&IstioDistribution{Flavor: "tetrate"}).IsUpstream())
require.False(t, (&IstioDistribution{Flavor: "tetratefips"}).IsUpstream())
}

func TestIstioDistribution_GreaterThan(t *testing.T) {
Expand All @@ -192,7 +191,7 @@ func TestIstioDistribution_GreaterThan(t *testing.T) {
} {
actual, err := base.GreaterThan(c)
require.NoError(t, err)
assert.True(t, actual)
require.True(t, actual)
}
})

Expand All @@ -203,15 +202,15 @@ func TestIstioDistribution_GreaterThan(t *testing.T) {
} {
actual, err := base.GreaterThan(c)
require.NoError(t, err)
assert.False(t, actual)
require.False(t, actual)
}
})
}

func TestIstioDistribution_Equal(t *testing.T) {
base := &IstioDistribution{Version: "1.2.3", Flavor: "tetrate", FlavorVersion: 40}
t.Run("true", func(t *testing.T) {
assert.True(t, base.Equal(&IstioDistribution{Version: "1.2.3", Flavor: "tetrate", FlavorVersion: 40}))
require.True(t, base.Equal(&IstioDistribution{Version: "1.2.3", Flavor: "tetrate", FlavorVersion: 40}))
})

t.Run("false", func(t *testing.T) {
Expand Down Expand Up @@ -249,7 +248,7 @@ func TestIstioDistributionFromString(t *testing.T) {
} {
v, err := IstioDistributionFromString(c.in)
require.NoError(t, err, c.in, c.in)
assert.Equal(t, c.exp, v)
require.Equal(t, c.exp, v)
}
})

Expand All @@ -260,7 +259,7 @@ func TestIstioDistributionFromString(t *testing.T) {
"1.6.7-tetrate-v", "1.7.113-tetrate-",
} {
_, err := IstioDistributionFromString(in)
assert.Error(t, err, in)
require.Error(t, err, in)
}
})
}
Expand All @@ -277,8 +276,8 @@ func Test_parseFlavor(t *testing.T) {
} {
flavor, flavorVersion, err := parseFlavor(c.in)
require.NoError(t, err)
assert.Equal(t, c.flavor, flavor)
assert.Equal(t, c.flavorVersion, flavorVersion)
require.Equal(t, c.flavor, flavor)
require.Equal(t, c.flavorVersion, flavorVersion)
}
})

Expand Down Expand Up @@ -572,13 +571,13 @@ func TestGetLatestDistribution(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
latest, isSecure, err := GetLatestDistribution(test.current, test.maniest)
assert.NoError(t, err)
require.NoError(t, err)
if latest == nil {
assert.Equal(t, latest, test.wants)
require.Equal(t, latest, test.wants)
} else {
assert.True(t, latest.Equal(test.wants))
require.True(t, latest.Equal(test.wants))
}
assert.Equal(t, test.wantsSecure, isSecure)
require.Equal(t, test.wantsSecure, isSecure)
})
}
}
9 changes: 4 additions & 5 deletions cmd/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"

"github.com/stretchr/testify/require"
"github.com/tetratelabs/getmesh/api"
)

Expand Down Expand Up @@ -139,10 +138,10 @@ func Test_fetchParams(t *testing.T) {
t.Run(fmt.Sprintf("%d-th case", i), func(t *testing.T) {
actual, err := fetchParams(c.flag, c.mf)
if c.exp == nil {
assert.Error(t, err)
require.Error(t, err)
} else {
assert.NoError(t, err)
assert.Equal(t, c.exp, actual)
require.NoError(t, err)
require.Equal(t, c.exp, actual)
}
})

Expand Down
13 changes: 6 additions & 7 deletions cmd/gen_ca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/spf13/pflag"
"github.com/stretchr/testify/require"
"gotest.tools/assert"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"
Expand Down Expand Up @@ -58,7 +57,7 @@ func TestPreFlightChecks(t *testing.T) {
cfg.SetDefaultValues()
cfg.DisableSecretCreation = false
err := genCAPreFlightChecks(cfg, cs)
assert.ErrorContains(t, err, "namespaces \"istio-system\" not found")
require.Contains(t, err.Error(), "namespaces \"istio-system\" not found")

ns := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "istio-system"}}
_, err = cs.CoreV1().Namespaces().Create(context.Background(), ns, metav1.CreateOptions{})
Expand All @@ -76,21 +75,21 @@ func TestPreFlightChecks(t *testing.T) {
cs := fake.NewSimpleClientset()
cfg := &config.Config{}
cfg.DisableSecretCreation = true
assert.Equal(t, genCAPreFlightChecks(cfg, cs), nil)
require.Equal(t, genCAPreFlightChecks(cfg, cs), nil)

// readonly error
ro := filepath.Join(d, "readonly")
require.NoError(t, os.Mkdir(ro, 0400))
cfg.CertParameters.SecretFilePath = filepath.Join(ro, "test.yaml")
err = genCAPreFlightChecks(cfg, cs)
assert.ErrorContains(t, err, "unable to write on secret file path:")
require.Contains(t, err.Error(), "unable to write on secret file path:")

// ok
f, err := ioutil.TempFile(d, "")
require.NoError(t, err)
cfg.CertParameters.SecretFilePath = f.Name()
err = genCAPreFlightChecks(cfg, cs)
assert.ErrorContains(t, err, f.Name()+"` already exist, please change the file path before proceeding")
require.Contains(t, err.Error(), f.Name()+"` already exist, please change the file path before proceeding")
})
}

Expand All @@ -115,7 +114,7 @@ func TestFetchParametersError(t *testing.T) {
t.Run(c.label, func(t *testing.T) {
require.NoError(t, flags.Parse(c.arguments))
_, err := genCAFetchParameters(flags)
assert.ErrorContains(t, err, c.expected)
require.Contains(t, err.Error(), c.expected)
})
}
}
Expand Down Expand Up @@ -250,7 +249,7 @@ func TestFetchParametersSucess(t *testing.T) {
// so explicit error checks aren't required
cfg, err := genCAFetchParameters(flags)
require.NoError(t, err)
assert.Equal(t, true, c.checker(cfg))
require.Equal(t, true, c.checker(cfg))
})
}
}
11 changes: 5 additions & 6 deletions cmd/istioctl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"os"
"testing"

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

"github.com/tetratelabs/getmesh/api"
Expand Down Expand Up @@ -103,7 +102,7 @@ func TestIstioctl_istioctlArgChecks(t *testing.T) {
require.Error(t, err)
})

assert.Contains(t, buf.String(), "Your active istioctl of version 1.7.4-tetratefips-v0 is deprecated.")
require.Contains(t, buf.String(), "Your active istioctl of version 1.7.4-tetratefips-v0 is deprecated.")
t.Log(buf.String())
})
}
Expand Down Expand Up @@ -172,7 +171,7 @@ func TestIstioctl_istioctlParsePreCheckArgs(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
actual := istioctlParsePreCheckArgs(c.args)
assert.Equal(t, c.exp, actual)
require.Equal(t, c.exp, actual)
})
}
}
Expand Down Expand Up @@ -247,7 +246,7 @@ func TestIstioctl_istioctlParseVerifyInstallArgs(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
actual := istioctlParseVerifyInstallArgs(c.args)
assert.Equal(t, c.exp, actual)
require.Equal(t, c.exp, actual)
})
}
}
Expand Down Expand Up @@ -277,7 +276,7 @@ func TestIstioctl_istioctPatchVersionCheck(t *testing.T) {
require.Error(t, istioctlPatchVersionCheck(current, m))
})

assert.Contains(t, buf.String(), "your current patch version 1.7.5 is not the latest version 1.7.6")
require.Contains(t, buf.String(), "your current patch version 1.7.5 is not the latest version 1.7.6")
t.Log(buf.String())
})

Expand Down Expand Up @@ -379,7 +378,7 @@ func TestIstioctl_istioctlPreProcessArgs(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
actual := istioctlPreProcessArgs(test.args)
assert.Equal(t, test.wants, actual)
require.Equal(t, test.wants, actual)
})
}
}
3 changes: 1 addition & 2 deletions cmd/prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"strconv"
"testing"

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

"github.com/tetratelabs/getmesh/api"
Expand Down Expand Up @@ -50,7 +49,7 @@ func Test_pruneCheckFlags(t *testing.T) {
} else {
require.NoError(t, err)
}
assert.Equal(t, c.exp, actual)
require.Equal(t, c.exp, actual)
})
}
}
1 change: 0 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func NewRoot(version, homeDir string) *cobra.Command {
cmd.AddCommand(newShowCmd(homeDir))
cmd.AddCommand(newConfigValidateCmd(homeDir))
cmd.AddCommand(newGenCACmd())
cmd.AddCommand(newUpgradeCmd(version))
cmd.AddCommand(newPruneCmd(homeDir))
cmd.AddCommand(newSetDefaultHubCmd(homeDir))

Expand Down
9 changes: 4 additions & 5 deletions cmd/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"strings"
"testing"

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

"github.com/tetratelabs/getmesh/api"
Expand Down Expand Up @@ -88,21 +87,21 @@ func Test_switchParse(t *testing.T) {
distro, err := switchParse(home, flag)
require.NoError(t, err)
exp := &api.IstioDistribution{Version: "1.7.6", Flavor: "istio", FlavorVersion: 0}
assert.Equal(t, distro, exp)
require.Equal(t, distro, exp)
})
t.Run("name", func(t *testing.T) {
flag := &switchFlags{name: "1.8.3-istio-v0"}
distro, err := switchParse(home, flag)
require.NoError(t, err)
exp := &api.IstioDistribution{Version: "1.8.3", Flavor: "istio", FlavorVersion: 0}
assert.Equal(t, distro, exp)
require.Equal(t, distro, exp)
})
t.Run("group", func(t *testing.T) {
flag := &switchFlags{version: "1.7", flavor: "istio", flavorVersion: 0}
distro, err := switchParse(home, flag)
require.NoError(t, err)
exp := &api.IstioDistribution{Version: "1.7.6", Flavor: "istio", FlavorVersion: 0}
assert.Equal(t, distro, exp)
require.Equal(t, distro, exp)
})
}

Expand Down Expand Up @@ -135,6 +134,6 @@ func Test_switchHandleDistro(t *testing.T) {
} {
v, err := switchHandleDistro(c.curr, c.flags)
require.NoError(t, err)
assert.Equal(t, c.exp, v)
require.Equal(t, c.exp, v)
}
}
32 changes: 0 additions & 32 deletions cmd/upgrade.go

This file was deleted.

Loading

0 comments on commit eb21f30

Please sign in to comment.