...
1
16
17 package container
18
19 import (
20 "encoding/json"
21 "testing"
22
23 "k8s.io/api/core/v1"
24 )
25
26 var (
27 sampleContainer = `
28 {
29 "name": "test_container",
30 "image": "foo/image:v1",
31 "command": [
32 "/bin/testcmd"
33 ],
34 "args": [
35 "/bin/sh",
36 "-c",
37 "echo abc"
38 ],
39 "ports": [
40 {
41 "containerPort": 8001
42 }
43 ],
44 "env": [
45 {
46 "name": "ENV_FOO",
47 "value": "bar"
48 },
49 {
50 "name": "ENV_BAR",
51 "valueFrom": {
52 "secretKeyRef": {
53 "name": "foo",
54 "key": "bar",
55 "optional": true
56 }
57 }
58 }
59 ],
60 "resources": {
61 "limits": {
62 "foo": "1G"
63 },
64 "requests": {
65 "foo": "500M"
66 }
67 }
68 }
69 `
70
71 sampleV115HashValue = uint64(0x311670a)
72 sampleV116HashValue = sampleV115HashValue
73 )
74
75 func TestConsistentHashContainer(t *testing.T) {
76 container := &v1.Container{}
77 if err := json.Unmarshal([]byte(sampleContainer), container); err != nil {
78 t.Error(err)
79 }
80
81 currentHash := HashContainer(container)
82 if currentHash != sampleV116HashValue {
83 t.Errorf("mismatched hash value with v1.16")
84 }
85
86 if currentHash != sampleV115HashValue {
87 t.Errorf("mismatched hash value with v1.15")
88 }
89 }
90
View as plain text