|
| 1 | +package state |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestShim_MarshalJSON(t *testing.T) { |
| 8 | + type fields struct { |
| 9 | + Sha256 []byte |
| 10 | + Path string |
| 11 | + } |
| 12 | + tests := []struct { |
| 13 | + name string |
| 14 | + fields fields |
| 15 | + want string |
| 16 | + wantErr bool |
| 17 | + }{ |
| 18 | + {"default", fields{Sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}, Path: "/opt/kwasm/bin/containerd-shim-spin-v1"}, `{"sha256":"6da5e8f17a9bfa9cb04cf22c87b6475394ecec3af4fdc337f72d6dbf3319ea52","path":"/opt/kwasm/bin/containerd-shim-spin-v1"}`, false}, |
| 19 | + } |
| 20 | + for _, tt := range tests { |
| 21 | + t.Run(tt.name, func(t *testing.T) { |
| 22 | + s := &Shim{ |
| 23 | + Sha256: tt.fields.Sha256, |
| 24 | + Path: tt.fields.Path, |
| 25 | + } |
| 26 | + got, err := s.MarshalJSON() |
| 27 | + if (err != nil) != tt.wantErr { |
| 28 | + t.Errorf("Shim.MarshalJSON() error = %v, wantErr %v", err, tt.wantErr) |
| 29 | + return |
| 30 | + } |
| 31 | + if string(got) != string(tt.want) { |
| 32 | + t.Errorf("Shim.MarshalJSON() = %v, want %v", string(got), tt.want) |
| 33 | + } |
| 34 | + }) |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +func TestShim_UnmarshalJSON(t *testing.T) { |
| 39 | + type wants struct { |
| 40 | + path string |
| 41 | + sha256 []byte |
| 42 | + } |
| 43 | + type args struct { |
| 44 | + data string |
| 45 | + } |
| 46 | + tests := []struct { |
| 47 | + name string |
| 48 | + args args |
| 49 | + want wants |
| 50 | + wantErr bool |
| 51 | + }{ |
| 52 | + {"default", args{`{"sha256":"6da5e8f17a9bfa9cb04cf22c87b6475394ecec3af4fdc337f72d6dbf3319ea52","path":"/opt/kwasm/bin/containerd-shim-spin-v1"}`}, wants{path: "/opt/kwasm/bin/containerd-shim-spin-v1", sha256: []byte{109, 165, 232, 241, 122, 155, 250, 156, 176, 76, 242, 44, 135, 182, 71, 83, 148, 236, 236, 58, 244, 253, 195, 55, 247, 45, 109, 191, 51, 25, 234, 82}}, false}, |
| 53 | + // TODO: Add test cases. |
| 54 | + } |
| 55 | + for _, tt := range tests { |
| 56 | + t.Run(tt.name, func(t *testing.T) { |
| 57 | + s := Shim{} |
| 58 | + if err := s.UnmarshalJSON([]byte(tt.args.data)); (err != nil) != tt.wantErr { |
| 59 | + t.Errorf("Shim.UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr) |
| 60 | + } |
| 61 | + if string(s.Path) != string(tt.want.path) { |
| 62 | + t.Errorf("path = %v, want %v", string(s.Path), tt.want.path) |
| 63 | + } |
| 64 | + if string(s.Sha256) != string(tt.want.sha256) { |
| 65 | + t.Errorf("sha256 = %v, want %v", string(s.Sha256), tt.want.sha256) |
| 66 | + } |
| 67 | + }) |
| 68 | + } |
| 69 | +} |
0 commit comments