From c9e28b468c14ae92327c6c6366ba67507ae0a3d4 Mon Sep 17 00:00:00 2001 From: zhangzujian Date: Wed, 4 Dec 2024 07:08:05 +0000 Subject: [PATCH] add some unittests Signed-off-by: zhangzujian --- pkg/util/hash_test.go | 73 ++++++++ pkg/util/k8s_test.go | 342 ++++++++++++++++++++++++++++++++++++ pkg/util/patch_test.go | 76 ++++++-- pkg/util/pod_routes.go | 9 +- pkg/util/pod_routes_test.go | 61 +++++++ pkg/util/strings_test.go | 28 --- 6 files changed, 542 insertions(+), 47 deletions(-) create mode 100644 pkg/util/hash_test.go create mode 100644 pkg/util/pod_routes_test.go diff --git a/pkg/util/hash_test.go b/pkg/util/hash_test.go new file mode 100644 index 00000000000..c0ab50439d2 --- /dev/null +++ b/pkg/util/hash_test.go @@ -0,0 +1,73 @@ +package util + +import "testing" + +func TestSha256Hash(t *testing.T) { + tests := []struct { + name string + input []byte + output string + }{ + { + name: "Empty input", + input: []byte(""), + output: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + }, + { + name: "Non empty input", + input: []byte("hello"), + output: "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := Sha256Hash(tt.input) + if got != tt.output { + t.Errorf("got %v, but want %v", got, tt.output) + } + }) + } +} + +func TestSha256HashObject(t *testing.T) { + tests := []struct { + name string + arg any + wantErr bool + hash string + }{ + { + name: "nil", + arg: nil, + hash: "74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b", + }, + { + name: "string slice", + arg: []string{"hello", "world"}, + hash: "94bedb26fb1cb9547b5b77902e89522f313c7f7fe2e9f0175cfb0a244878ee07", + }, + { + name: "string map", + arg: map[string]string{"hello": "world"}, + hash: "93a23971a914e5eacbf0a8d25154cda309c3c1c72fbb9914d47c60f3cb681588", + }, + { + name: "unsupported type", + arg: make(chan struct{}), + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + hash, err := Sha256HashObject(tt.arg) + if (err != nil) != tt.wantErr { + t.Errorf("got error = %#v, but wantErr = %v", err, tt.wantErr) + } + if hash != tt.hash { + t.Errorf("got hash %v, but want %v", hash, tt.hash) + } + }) + } +} diff --git a/pkg/util/k8s_test.go b/pkg/util/k8s_test.go index 024e0ff8fa9..5f5ba293155 100644 --- a/pkg/util/k8s_test.go +++ b/pkg/util/k8s_test.go @@ -3,6 +3,8 @@ package util import ( "context" "errors" + "fmt" + "math/rand/v2" "net" "net/http" "net/http/httptest" @@ -10,12 +12,19 @@ import ( "testing" "time" + "github.com/google/uuid" + nadv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" "github.com/stretchr/testify/require" + appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/fake" clientv1 "k8s.io/client-go/kubernetes/typed/core/v1" "k8s.io/klog/v2" + "k8s.io/utils/ptr" + + kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1" ) func TestDialTCP(t *testing.T) { @@ -526,3 +535,336 @@ func TestGetTruncatedUID(t *testing.T) { uid := "12345678-1234-1234-1234-123456789012" require.Equal(t, "123456789012", GetTruncatedUID(uid)) } + +func TestSetOwnerReference(t *testing.T) { + tests := []struct { + name string + owner metav1.Object + object metav1.Object + wantErr bool + }{ + { + name: "base", + owner: &kubeovnv1.VpcEgressGateway{ + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("veg-%05d", rand.IntN(10000)), + UID: types.UID(uuid.New().String()), + }, + }, + object: &v1.Pod{}, + }, + { + name: "not registered", + owner: &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("veg-%05d", rand.IntN(10000)), + UID: types.UID(uuid.New().String()), + }, + }, + object: &v1.Pod{}, + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := SetOwnerReference(tt.owner, tt.object) + if (err != nil) != tt.wantErr { + t.Errorf("SetOwnerReference() error = %#v, wantErr = %v", err, tt.wantErr) + } + if err != nil { + return + } + + refer := tt.object.GetOwnerReferences() + require.Len(t, refer, 1) + require.Equal(t, tt.owner.GetName(), refer[0].Name) + require.Equal(t, tt.owner.GetUID(), refer[0].UID) + }) + } +} + +func TestPodAttachmentIPs(t *testing.T) { + tests := []struct { + name string + pod *v1.Pod + network string + wantErr bool + ips []string + }{ + { + name: "ipv4", + pod: &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{ + nadv1.NetworkStatusAnnot: `[{"name": "default/ipv4", "ips": ["1.1.1.1"]}]`, + }, + }, + }, + network: "default/ipv4", + ips: []string{"1.1.1.1"}, + }, + { + name: "ipv6", + pod: &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{ + nadv1.NetworkStatusAnnot: `[{"name": "default/ipv6", "ips": ["fd00::1"]}]`, + }, + }, + }, + network: "default/ipv6", + ips: []string{"fd00::1"}, + }, + { + name: "dual-stack", + pod: &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{ + nadv1.NetworkStatusAnnot: `[{"name": "default/dual", "ips": ["1.1.1.1", "fd00::1"]}]`, + }, + }, + }, + network: "default/dual", + ips: []string{"1.1.1.1", "fd00::1"}, + }, + { + name: "nil pod", + pod: nil, + wantErr: true, + }, + { + name: "no network status annotation", + pod: &v1.Pod{}, + wantErr: true, + }, + { + name: "unexpected network status annotation", + pod: &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{ + nadv1.NetworkStatusAnnot: `foo_bar`, + }, + }, + }, + wantErr: true, + }, + { + name: "empty network name", + pod: &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{ + nadv1.NetworkStatusAnnot: `[{"name": "default/xxx", "ips": ["1.1.1.1", "fd00::1"]}]`, + }, + }, + }, + network: "", + wantErr: true, + }, + { + name: "network status not found", + pod: &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{ + nadv1.NetworkStatusAnnot: `[{"name": "default/xyz", "ips": ["1.1.1.1", "fd00::1"]}]`, + }, + }, + }, + network: "default/abc", + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + ips, err := PodAttachmentIPs(tt.pod, tt.network) + if (err != nil) != tt.wantErr { + t.Errorf("PodAttachmentIPs() error = %#v, wantErr = %v", err, tt.wantErr) + } + if err != nil { + return + } + + require.ElementsMatch(t, tt.ips, ips) + }) + } +} + +func TestDeploymentIsReady(t *testing.T) { + tests := []struct { + name string + deploy *appsv1.Deployment + ready bool + }{ + { + name: "ready", + deploy: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Generation: 2, + }, + Spec: appsv1.DeploymentSpec{ + Replicas: ptr.To[int32](1), + }, + Status: appsv1.DeploymentStatus{ + ObservedGeneration: 2, + Replicas: 1, + UpdatedReplicas: 1, + AvailableReplicas: 1, + }, + }, + ready: true, + }, + { + name: "generation mismatch", + deploy: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Generation: 2, + }, + Status: appsv1.DeploymentStatus{ + ObservedGeneration: 1, + }, + }, + ready: false, + }, + { + name: "condition Processing", + deploy: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Generation: 2, + }, + Spec: appsv1.DeploymentSpec{ + Replicas: ptr.To[int32](1), + }, + Status: appsv1.DeploymentStatus{ + ObservedGeneration: 2, + Replicas: 1, + UpdatedReplicas: 1, + AvailableReplicas: 1, + Conditions: []appsv1.DeploymentCondition{ + { + Type: appsv1.DeploymentProgressing, + }, + }, + }, + }, + ready: true, + }, + { + name: "ProgressDeadlineExceeded", + deploy: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Generation: 2, + }, + Status: appsv1.DeploymentStatus{ + ObservedGeneration: 2, + Conditions: []appsv1.DeploymentCondition{ + { + Type: appsv1.DeploymentProgressing, + Reason: "ProgressDeadlineExceeded", + }, + }, + }, + }, + ready: false, + }, + { + name: "updated replicas less than desired replicas", + deploy: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Generation: 2, + }, + Spec: appsv1.DeploymentSpec{ + Replicas: ptr.To[int32](2), + }, + Status: appsv1.DeploymentStatus{ + ObservedGeneration: 2, + Replicas: 2, + UpdatedReplicas: 1, + AvailableReplicas: 1, + }, + }, + ready: false, + }, + { + name: "updated replicas less than current replicas", + deploy: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Generation: 2, + }, + Spec: appsv1.DeploymentSpec{ + Replicas: ptr.To[int32](1), + }, + Status: appsv1.DeploymentStatus{ + ObservedGeneration: 2, + Replicas: 2, + UpdatedReplicas: 1, + AvailableReplicas: 1, + }, + }, + ready: false, + }, + { + name: "available replicas less than updated replicas", + deploy: &appsv1.Deployment{ + ObjectMeta: metav1.ObjectMeta{ + Generation: 2, + }, + Spec: appsv1.DeploymentSpec{ + Replicas: ptr.To[int32](2), + }, + Status: appsv1.DeploymentStatus{ + ObservedGeneration: 2, + Replicas: 2, + UpdatedReplicas: 2, + AvailableReplicas: 1, + }, + }, + ready: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + ready := DeploymentIsReady(tt.deploy) + require.Equal(t, tt.ready, ready) + }) + } +} + +func Test_nodeMergePatch(t *testing.T) { + tests := []struct { + name string + patch string + wantErr bool + }{ + { + name: "valid_merge_patch", + patch: `{"metadata":{"labels":{"key1":"value1"}}}`, + wantErr: false, + }, + { + name: "invalid_merge_patch", + patch: "invalid_merge_patch", + wantErr: true, + }, + } + + client := fake.NewClientset(&v1.Node{}).CoreV1().Nodes() + _, err := client.Create(context.TODO(), &v1.Node{ + ObjectMeta: metav1.ObjectMeta{ + Name: "node1", + }, + }, metav1.CreateOptions{}) + require.NoError(t, err) + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err = nodeMergePatch(client, "node1", tt.patch) + if tt.wantErr { + require.Error(t, err) + return + } + require.NoError(t, err) + }) + } +} diff --git a/pkg/util/patch_test.go b/pkg/util/patch_test.go index 0dc5c877777..6c3453e4adc 100644 --- a/pkg/util/patch_test.go +++ b/pkg/util/patch_test.go @@ -13,6 +13,12 @@ import ( ) func TestGenerateStrategicMergePatchPayload(t *testing.T) { + type C chan struct{} + type unsupportedType struct { + C + *v1.Pod + } + type args struct { // original stands for the original object we seen before we handle original runtime.Object @@ -24,7 +30,7 @@ func TestGenerateStrategicMergePatchPayload(t *testing.T) { tests := []struct { name string args args - want v1.Pod + want runtime.Object wantErr bool }{ { @@ -34,7 +40,7 @@ func TestGenerateStrategicMergePatchPayload(t *testing.T) { modified: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"ovn1": "1", "ovn2": "2"}}}, remote: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{}}}, }, - want: v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"ovn1": "1", "ovn2": "2"}}}, + want: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"ovn1": "1", "ovn2": "2"}}}, wantErr: false, }, { @@ -44,7 +50,7 @@ func TestGenerateStrategicMergePatchPayload(t *testing.T) { modified: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"ovn1": "1", "ovn2": "2"}}}, remote: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"calico1": "1"}}}, }, - want: v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"calico1": "1", "ovn1": "1", "ovn2": "2"}}}, + want: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"calico1": "1", "ovn1": "1", "ovn2": "2"}}}, wantErr: false, }, { @@ -54,7 +60,7 @@ func TestGenerateStrategicMergePatchPayload(t *testing.T) { modified: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{}}}, remote: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{}}}, }, - want: v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: nil}}, + want: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: nil}}, wantErr: false, }, { @@ -64,9 +70,25 @@ func TestGenerateStrategicMergePatchPayload(t *testing.T) { modified: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{}}}, remote: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"calico1": "1"}}}, }, - want: v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: nil}}, + want: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: nil}}, wantErr: false, }, + { + name: "argument original is of unsupported type", + args: args{ + original: &unsupportedType{}, + modified: &v1.Pod{}, + }, + wantErr: true, + }, + { + name: "argument modified is of unsupported type", + args: args{ + original: &v1.Pod{}, + modified: &unsupportedType{}, + }, + wantErr: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -75,12 +97,16 @@ func TestGenerateStrategicMergePatchPayload(t *testing.T) { t.Errorf("GenerateStrategicMergePatchPayload() error = %v, wantErr %v", err, tt.wantErr) return } + if err != nil { + return + } + b, _ := json.Marshal(tt.args.remote) // apply patch for remote obj newB, _ := strategicpatch.StrategicMergePatch(b, got, v1.Pod{}) patchedPod := v1.Pod{} _ = json.Unmarshal(newB, &patchedPod) - if !assert.Equal(t, tt.want, patchedPod, "patch: %s", got) { + if !assert.Equal(t, tt.want, runtime.Object(&patchedPod), "patch: %s", got) { t.Errorf("patch not correct, got = %+v, want= %+v", patchedPod, tt.want) } }) @@ -88,6 +114,12 @@ func TestGenerateStrategicMergePatchPayload(t *testing.T) { } func TestGenerateMergePatchPayload(t *testing.T) { + type C chan struct{} + type unsupportedType struct { + C + *v1.Pod + } + type args struct { // original stands for the original object we seen before we handle original runtime.Object @@ -99,7 +131,7 @@ func TestGenerateMergePatchPayload(t *testing.T) { tests := []struct { name string args args - want v1.Pod + want runtime.Object wantErr bool }{ { @@ -109,7 +141,7 @@ func TestGenerateMergePatchPayload(t *testing.T) { modified: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"ovn1": "1", "ovn2": "2"}}}, remote: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{}}}, }, - want: v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"ovn1": "1", "ovn2": "2"}}}, + want: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"ovn1": "1", "ovn2": "2"}}}, wantErr: false, }, { @@ -119,7 +151,7 @@ func TestGenerateMergePatchPayload(t *testing.T) { modified: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"ovn1": "1", "ovn2": "2"}}}, remote: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"calico1": "1"}}}, }, - want: v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"calico1": "1", "ovn1": "1", "ovn2": "2"}}}, + want: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"calico1": "1", "ovn1": "1", "ovn2": "2"}}}, wantErr: false, }, { @@ -129,7 +161,7 @@ func TestGenerateMergePatchPayload(t *testing.T) { modified: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{}}}, remote: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{}}}, }, - want: v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: nil}}, + want: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: nil}}, wantErr: false, }, { @@ -139,9 +171,25 @@ func TestGenerateMergePatchPayload(t *testing.T) { modified: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{}}}, remote: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{"calico1": "1"}}}, }, - want: v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: nil}}, + want: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Annotations: nil}}, wantErr: false, }, + { + name: "argument original is of unsupported type", + args: args{ + original: &unsupportedType{}, + modified: &v1.Pod{}, + }, + wantErr: true, + }, + { + name: "argument modified is of unsupported type", + args: args{ + original: &v1.Pod{}, + modified: &unsupportedType{}, + }, + wantErr: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -150,12 +198,16 @@ func TestGenerateMergePatchPayload(t *testing.T) { t.Errorf("GenerateMergePatchPayload() error = %v, wantErr %v", err, tt.wantErr) return } + if err != nil { + return + } + b, _ := json.Marshal(tt.args.remote) // apply patch for remote obj newB, _ := strategicpatch.StrategicMergePatch(b, got, v1.Pod{}) patchedPod := v1.Pod{} _ = json.Unmarshal(newB, &patchedPod) - if !assert.Equal(t, tt.want, patchedPod, "patch: %s", got) { + if !assert.Equal(t, tt.want, runtime.Object(&patchedPod), "patch: %s", got) { t.Errorf("patch not correct, got = %+v, want= %+v", patchedPod, tt.want) } }) diff --git a/pkg/util/pod_routes.go b/pkg/util/pod_routes.go index 55274baee2d..c84a79bb7d2 100644 --- a/pkg/util/pod_routes.go +++ b/pkg/util/pod_routes.go @@ -4,8 +4,6 @@ import ( "encoding/json" "fmt" - "k8s.io/klog/v2" - "github.com/kubeovn/kube-ovn/pkg/request" ) @@ -50,11 +48,8 @@ func (r PodRoutes) ToAnnotations() (map[string]string, error) { continue } - buf, err := json.Marshal(routes) - if err != nil { - klog.Error(err) - return nil, err - } + // no error will be returned here + buf, _ := json.Marshal(routes) annotations[fmt.Sprintf(RoutesAnnotationTemplate, provider)] = string(buf) } return annotations, nil diff --git a/pkg/util/pod_routes_test.go b/pkg/util/pod_routes_test.go new file mode 100644 index 00000000000..39b30b61fc5 --- /dev/null +++ b/pkg/util/pod_routes_test.go @@ -0,0 +1,61 @@ +package util + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestPodRoutes(t *testing.T) { + routes := NewPodRoutes() + require.NotNil(t, routes) + require.Empty(t, routes) + annotations, err := routes.ToAnnotations() + require.NoError(t, err) + require.Len(t, annotations, 0) + + routes.Add("foo", "0.0.0.1", "1.1.1.1") + routes.Add("foo", "0.0.1.0/24", "1.1.1.1") + routes.Add("foo", "0.1.0.0/16", "1.1.1.2") + require.Len(t, routes, 1) + require.Len(t, routes["foo"], 2) + require.Len(t, routes["foo"]["1.1.1.1"], 2) + require.Len(t, routes["foo"]["1.1.1.2"], 1) + annotations, err = routes.ToAnnotations() + require.NoError(t, err) + require.Len(t, annotations, 1) + + routes.Add("foo", "0.0.0.1", "") + routes.Add("foo", "", "1.1.1.3") + routes.Add("foo", "", "") + require.Len(t, routes, 1) + require.Len(t, routes["foo"], 2) + require.Len(t, routes["foo"]["1.1.1.1"], 2) + require.Len(t, routes["foo"]["1.1.1.2"], 1) + annotations, err = routes.ToAnnotations() + require.NoError(t, err) + require.Len(t, annotations, 1) + + routes.Add("bar", "192.168.0.1/32", "2.2.2.2") + require.Len(t, routes, 2) + require.Len(t, routes["foo"], 2) + require.Len(t, routes["foo"]["1.1.1.1"], 2) + require.Len(t, routes["foo"]["1.1.1.2"], 1) + require.Len(t, routes["bar"], 1) + require.Len(t, routes["bar"]["2.2.2.2"], 1) + annotations, err = routes.ToAnnotations() + require.NoError(t, err) + require.Len(t, annotations, 2) + + // empty routes + routes = PodRoutes{"foo": PodProviderRoutes{}} + annotations, err = routes.ToAnnotations() + require.NoError(t, err) + require.Empty(t, annotations) + + // empty gateway + routes["foo"] = PodProviderRoutes{"": []string{"1.1.1.1"}} + annotations, err = routes.ToAnnotations() + require.NoError(t, err) + require.Empty(t, annotations) +} diff --git a/pkg/util/strings_test.go b/pkg/util/strings_test.go index e2b90ce80af..c7d0b5cd657 100644 --- a/pkg/util/strings_test.go +++ b/pkg/util/strings_test.go @@ -48,31 +48,3 @@ func TestDoubleQuotedFields(t *testing.T) { }) } } - -func TestSha256Hash(t *testing.T) { - tests := []struct { - name string - input []byte - output string - }{ - { - name: "Empty input", - input: []byte(""), - output: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - }, - { - name: "Non empty input", - input: []byte("hello"), - output: "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824", - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got := Sha256Hash(tt.input) - if got != tt.output { - t.Errorf("got %v, but want %v", got, tt.output) - } - }) - } -}