Skip to content

Commit

Permalink
Add test for configmap checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Jun 21, 2018
1 parent d183c34 commit 0abbd2b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions internal/ingress/controller/template/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ limitations under the License.
package template

import (
"fmt"
"reflect"
"testing"
"time"

"github.com/kylelemons/godebug/pretty"
"github.com/mitchellh/hashstructure"

"k8s.io/ingress-nginx/internal/ingress/controller/config"
)
Expand Down Expand Up @@ -88,6 +90,14 @@ func TestMergeConfigMapToStruct(t *testing.T) {
def.NginxStatusIpv6Whitelist = []string{"::1", "2001::/16"}
def.ProxyAddOriginalUriHeader = false

hash, err := hashstructure.Hash(def, &hashstructure.HashOptions{
TagName: "json",
})
if err != nil {
t.Fatalf("unexpected error obtaining hash: %v", err)
}
def.Checksum = fmt.Sprintf("%v", hash)

to := ReadConfig(conf)
if diff := pretty.Compare(to, def); diff != "" {
t.Errorf("unexpected diff: (-got +want)\n%s", diff)
Expand All @@ -107,13 +117,30 @@ func TestMergeConfigMapToStruct(t *testing.T) {
}

def = config.NewDefault()
hash, err = hashstructure.Hash(def, &hashstructure.HashOptions{
TagName: "json",
})
if err != nil {
t.Fatalf("unexpected error obtaining hash: %v", err)
}
def.Checksum = fmt.Sprintf("%v", hash)

to = ReadConfig(map[string]string{})
if diff := pretty.Compare(to, def); diff != "" {
t.Errorf("unexpected diff: (-got +want)\n%s", diff)
}

def = config.NewDefault()
def.WhitelistSourceRange = []string{"1.1.1.1/32"}

hash, err = hashstructure.Hash(def, &hashstructure.HashOptions{
TagName: "json",
})
if err != nil {
t.Fatalf("unexpected error obtaining hash: %v", err)
}
def.Checksum = fmt.Sprintf("%v", hash)

to = ReadConfig(map[string]string{
"whitelist-source-range": "1.1.1.1/32",
})
Expand Down

0 comments on commit 0abbd2b

Please sign in to comment.