From c69d8d251d5cbbe5ac6f3185ac2303967eba0596 Mon Sep 17 00:00:00 2001
From: Ian Howell <ian.howell0@gmail.com>
Date: Mon, 23 Mar 2020 15:57:40 -0500
Subject: [PATCH] Remove the various Equals methods from pkg/config

This change removes the `Equals` methods from the types defined in
pkg/config. They are not being used anywhere in the code base and as
such are dead code.

A user who wishes to compare objects from pkg/config should defer to
using reflect.DeepEqual (several of the objects in pkg/config were
already using DeepEqual, ending up with the same result).

Change-Id: I12bb88b4bf1646f597af70fc8cca93e8d9f7c653
---
 pkg/config/config.go      |  81 ----------------------------
 pkg/config/config_test.go | 109 --------------------------------------
 pkg/config/repo.go        |  32 -----------
 3 files changed, 222 deletions(-)

diff --git a/pkg/config/config.go b/pkg/config/config.go
index 46f49734a..703115db5 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -23,7 +23,6 @@ import (
 	"os"
 	"path"
 	"path/filepath"
-	"reflect"
 	"sort"
 	"strings"
 
@@ -741,29 +740,6 @@ func (c *Config) Purge() error {
 	return os.Remove(c.loadedConfigPath)
 }
 
-func (c *Config) Equal(d *Config) bool {
-	if d == nil {
-		return d == c
-	}
-	clusterEq := reflect.DeepEqual(c.Clusters, d.Clusters)
-	authInfoEq := reflect.DeepEqual(c.AuthInfos, d.AuthInfos)
-	contextEq := reflect.DeepEqual(c.Contexts, d.Contexts)
-	manifestEq := reflect.DeepEqual(c.Manifests, d.Manifests)
-	modulesEq := reflect.DeepEqual(c.ModulesConfig, d.ModulesConfig)
-	return c.Kind == d.Kind &&
-		c.APIVersion == d.APIVersion &&
-		clusterEq && authInfoEq && contextEq && manifestEq && modulesEq
-}
-
-// Cluster functions
-func (c *Cluster) Equal(d *Cluster) bool {
-	if d == nil {
-		return d == c
-	}
-	return c.NameInKubeconf == d.NameInKubeconf &&
-		c.Bootstrap == d.Bootstrap
-}
-
 func (c *Cluster) String() string {
 	cyaml, err := yaml.Marshal(&c)
 	if err != nil {
@@ -794,15 +770,6 @@ func (c *Cluster) SetKubeCluster(kc *clientcmdapi.Cluster) {
 }
 
 // Context functions
-func (c *Context) Equal(d *Context) bool {
-	if d == nil {
-		return d == c
-	}
-	return c.NameInKubeconf == d.NameInKubeconf &&
-		c.Manifest == d.Manifest &&
-		c.context == d.context
-}
-
 func (c *Context) String() string {
 	cyaml, err := yaml.Marshal(&c)
 	if err != nil {
@@ -839,13 +806,6 @@ func (c *Context) ClusterType() string {
 }
 
 // AuthInfo functions
-func (c *AuthInfo) Equal(d *AuthInfo) bool {
-	if d == nil {
-		return c == d
-	}
-	return c.authInfo == d.authInfo
-}
-
 func (c *AuthInfo) String() string {
 	kauthinfo := c.KubeAuthInfo()
 	kyaml, err := yaml.Marshal(&kauthinfo)
@@ -863,14 +823,6 @@ func (c *AuthInfo) SetKubeAuthInfo(kc *clientcmdapi.AuthInfo) {
 }
 
 // Manifest functions
-func (m *Manifest) Equal(n *Manifest) bool {
-	if n == nil {
-		return n == m
-	}
-	reposEq := reflect.DeepEqual(m.Repositories, n.Repositories)
-	return reposEq && m.TargetPath == n.TargetPath && m.SubPath == n.SubPath
-}
-
 func (m *Manifest) String() string {
 	yamlData, err := yaml.Marshal(&m)
 	if err != nil {
@@ -880,12 +832,6 @@ func (m *Manifest) String() string {
 }
 
 // Modules functions
-func (m *Modules) Equal(n *Modules) bool {
-	if n == nil {
-		return n == m
-	}
-	return reflect.DeepEqual(m.BootstrapInfo, n.BootstrapInfo)
-}
 func (m *Modules) String() string {
 	yamlData, err := yaml.Marshal(&m)
 	if err != nil {
@@ -895,15 +841,6 @@ func (m *Modules) String() string {
 }
 
 // Bootstrap functions
-func (b *Bootstrap) Equal(c *Bootstrap) bool {
-	if c == nil {
-		return b == c
-	}
-	contEq := reflect.DeepEqual(b.Container, c.Container)
-	bldrEq := reflect.DeepEqual(b.Builder, c.Builder)
-	return contEq && bldrEq
-}
-
 func (b *Bootstrap) String() string {
 	yamlData, err := yaml.Marshal(&b)
 	if err != nil {
@@ -913,15 +850,6 @@ func (b *Bootstrap) String() string {
 }
 
 // Container functions
-func (c *Container) Equal(d *Container) bool {
-	if d == nil {
-		return d == c
-	}
-	return c.Volume == d.Volume &&
-		c.Image == d.Image &&
-		c.ContainerRuntime == d.ContainerRuntime
-}
-
 func (c *Container) String() string {
 	yamlData, err := yaml.Marshal(&c)
 	if err != nil {
@@ -931,15 +859,6 @@ func (c *Container) String() string {
 }
 
 // Builder functions
-func (b *Builder) Equal(c *Builder) bool {
-	if c == nil {
-		return b == c
-	}
-	return b.UserDataFileName == c.UserDataFileName &&
-		b.NetworkConfigFileName == c.NetworkConfigFileName &&
-		b.OutputMetadataFileName == c.OutputMetadataFileName
-}
-
 func (b *Builder) String() string {
 	yamlData, err := yaml.Marshal(&b)
 	if err != nil {
diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go
index 06563b943..326197dd1 100644
--- a/pkg/config/config_test.go
+++ b/pkg/config/config_test.go
@@ -124,115 +124,6 @@ func TestPrettyString(t *testing.T) {
 	assert.EqualValues(t, cluster.PrettyString(), string(data))
 }
 
-func TestEqual(t *testing.T) {
-	t.Run("config-equal", func(t *testing.T) {
-		testConfig1 := config.NewConfig()
-		testConfig2 := config.NewConfig()
-		testConfig2.Kind = "Different"
-		assert.True(t, testConfig1.Equal(testConfig1))
-		assert.False(t, testConfig1.Equal(testConfig2))
-		assert.False(t, testConfig1.Equal(nil))
-	})
-
-	t.Run("cluster-equal", func(t *testing.T) {
-		testCluster1 := &config.Cluster{NameInKubeconf: "same"}
-		testCluster2 := &config.Cluster{NameInKubeconf: "different"}
-		assert.True(t, testCluster1.Equal(testCluster1))
-		assert.False(t, testCluster1.Equal(testCluster2))
-		assert.False(t, testCluster1.Equal(nil))
-	})
-
-	t.Run("context-equal", func(t *testing.T) {
-		testContext1 := &config.Context{NameInKubeconf: "same"}
-		testContext2 := &config.Context{NameInKubeconf: "different"}
-		assert.True(t, testContext1.Equal(testContext1))
-		assert.False(t, testContext1.Equal(testContext2))
-		assert.False(t, testContext1.Equal(nil))
-	})
-
-	// TODO(howell): this needs to be fleshed out when the AuthInfo type is finished
-	t.Run("authinfo-equal", func(t *testing.T) {
-		testAuthInfo1 := &config.AuthInfo{}
-		assert.True(t, testAuthInfo1.Equal(testAuthInfo1))
-		assert.False(t, testAuthInfo1.Equal(nil))
-	})
-
-	t.Run("manifest-equal", func(t *testing.T) {
-		testManifest1 := &config.Manifest{TargetPath: "same"}
-		testManifest2 := &config.Manifest{TargetPath: "different"}
-		assert.True(t, testManifest1.Equal(testManifest1))
-		assert.False(t, testManifest1.Equal(testManifest2))
-		assert.False(t, testManifest1.Equal(nil))
-	})
-
-	t.Run("repository-equal", func(t *testing.T) {
-		testRepository1 := &config.Repository{URLString: "same"}
-		testRepository2 := &config.Repository{URLString: "different"}
-		assert.True(t, testRepository1.Equal(testRepository1))
-		assert.False(t, testRepository1.Equal(testRepository2))
-		assert.False(t, testRepository1.Equal(nil))
-	})
-	t.Run("auth-equal", func(t *testing.T) {
-		testSpec1 := &config.RepoAuth{}
-		testSpec2 := &config.RepoAuth{}
-		testSpec2.Type = "ssh-key"
-		assert.True(t, testSpec1.Equal(testSpec1))
-		assert.False(t, testSpec1.Equal(testSpec2))
-		assert.False(t, testSpec1.Equal(nil))
-	})
-	t.Run("checkout-equal", func(t *testing.T) {
-		testSpec1 := &config.RepoCheckout{}
-		testSpec2 := &config.RepoCheckout{}
-		testSpec2.Branch = "Master"
-		assert.True(t, testSpec1.Equal(testSpec1))
-		assert.False(t, testSpec1.Equal(testSpec2))
-		assert.False(t, testSpec1.Equal(nil))
-	})
-
-	t.Run("modules-equal", func(t *testing.T) {
-		testModules1 := config.NewModules()
-		testModules2 := config.NewModules()
-		testModules2.BootstrapInfo["different"] = &config.Bootstrap{
-			Container: &config.Container{Volume: "different"},
-		}
-		assert.True(t, testModules1.Equal(testModules1))
-		assert.False(t, testModules1.Equal(testModules2))
-		assert.False(t, testModules1.Equal(nil))
-	})
-
-	t.Run("bootstrap-equal", func(t *testing.T) {
-		testBootstrap1 := &config.Bootstrap{
-			Container: &config.Container{
-				Image: "same",
-			},
-		}
-		testBootstrap2 := &config.Bootstrap{
-			Container: &config.Container{
-				Image: "different",
-			},
-		}
-		assert.True(t, testBootstrap1.Equal(testBootstrap1))
-		assert.False(t, testBootstrap1.Equal(testBootstrap2))
-		assert.False(t, testBootstrap1.Equal(nil))
-	})
-
-	t.Run("container-equal", func(t *testing.T) {
-		testContainer1 := &config.Container{Image: "same"}
-		testContainer2 := &config.Container{Image: "different"}
-		assert.True(t, testContainer1.Equal(testContainer1))
-		assert.False(t, testContainer1.Equal(testContainer2))
-		assert.False(t, testContainer1.Equal(nil))
-	})
-
-	t.Run("builder-equal", func(t *testing.T) {
-		testBuilder1 := &config.Builder{UserDataFileName: "same"}
-		testBuilder2 := &config.Builder{UserDataFileName: "different"}
-		assert.True(t, testBuilder1.Equal(testBuilder1))
-		assert.False(t, testBuilder1.Equal(testBuilder2))
-		assert.False(t, testBuilder1.Equal(nil))
-	})
-}
-
 func TestLoadConfig(t *testing.T) {
 	conf, cleanup := testutil.InitConfig(t)
 	defer cleanup(t)
diff --git a/pkg/config/repo.go b/pkg/config/repo.go
index 224d57013..7768fb684 100644
--- a/pkg/config/repo.go
+++ b/pkg/config/repo.go
@@ -2,7 +2,6 @@ package config
 
 import (
 	"fmt"
-	"reflect"
 
 	"gopkg.in/src-d/go-git.v4"
 	"gopkg.in/src-d/go-git.v4/plumbing"
@@ -22,16 +21,6 @@ const (
 
 // RepoCheckout methods
 
-func (c *RepoCheckout) Equal(s *RepoCheckout) bool {
-	if s == nil {
-		return s == c
-	}
-	return c.CommitHash == s.CommitHash &&
-		c.Branch == s.Branch &&
-		c.Tag == s.Tag &&
-		c.RemoteRef == s.RemoteRef
-}
-
 func (c *RepoCheckout) String() string {
 	yaml, err := yaml.Marshal(&c)
 	if err != nil {
@@ -62,17 +51,6 @@ var (
 	AllowedAuthTypes = []string{SSHAuth, SSHPass, HTTPBasic}
 )
 
-func (auth *RepoAuth) Equal(s *RepoAuth) bool {
-	if s == nil {
-		return s == auth
-	}
-	return auth.Type == s.Type &&
-		auth.KeyPassword == s.KeyPassword &&
-		auth.KeyPath == s.KeyPath &&
-		auth.SSHPassword == s.SSHPassword &&
-		auth.Username == s.Username
-}
-
 func (auth *RepoAuth) String() string {
 	yaml, err := yaml.Marshal(&auth)
 	if err != nil {
@@ -113,16 +91,6 @@ func stringInSlice(a string, list []string) bool {
 }
 
 // Repository functions
-// Equal compares repository specs
-func (repo *Repository) Equal(s *Repository) bool {
-	if s == nil {
-		return s == repo
-	}
-
-	return repo.URLString == s.URLString &&
-		reflect.DeepEqual(s.Auth, repo.Auth) &&
-		reflect.DeepEqual(s.CheckoutOptions, repo.CheckoutOptions)
-}
 
 func (repo *Repository) String() string {
 	yaml, err := yaml.Marshal(&repo)