core/plan/layer_test.go
core/plan/layer_test.goBrowse 1970 files
571 tokens
1,778 bytes
Token encoding: o200k_base
Snapshot 21a254f
← Back to SKILL.md
1package plan2 3import (4 "encoding/json"5 "testing"6 7 "github.com/google/go-cmp/cmp"8)9 10func TestUnmarshalInput(t *testing.T) {11 tests := []struct {12 name string13 input []byte14 expected Layer15 wantErr bool16 }{17 {18 name: "JSON step input",19 input: []byte(`{"step": "build", "include": ["src"]}`),20 expected: NewStepLayer("build", Filter{Include: []string{"src"}}),21 wantErr: false,22 },23 {24 name: "JSON image input",25 input: []byte(`{"image": "golang:1.21", "exclude": ["tmp"]}`),26 expected: NewImageLayer("golang:1.21", Filter{Exclude: []string{"tmp"}}),27 wantErr: false,28 },29 {30 name: "JSON local input",31 input: []byte(`{"local": true, "include": ["."]}`),32 expected: NewLocalLayer(),33 wantErr: false,34 },35 {36 name: "String local input with dot",37 input: []byte(`"."`),38 expected: NewLocalLayer(),39 wantErr: false,40 },41 {42 name: "String spread input",43 input: []byte(`"..."`),44 expected: Layer{Spread: true},45 wantErr: false,46 },47 {48 name: "String step input",49 input: []byte(`"$build"`),50 expected: NewStepLayer("build"),51 wantErr: false,52 },53 {54 name: "Invalid string input",55 input: []byte(`"invalid"`),56 wantErr: true,57 },58 {59 name: "Invalid JSON input",60 input: []byte(`{"invalid": json}`),61 wantErr: true,62 },63 }64 65 for _, tt := range tests {66 t.Run(tt.name, func(t *testing.T) {67 var got Layer68 err := json.Unmarshal(tt.input, &got)69 if (err != nil) != tt.wantErr {70 t.Errorf("UnmarshalInput() error = %v, wantErr %v", err, tt.wantErr)71 return72 }73 if !tt.wantErr {74 if diff := cmp.Diff(tt.expected, got); diff != "" {75 t.Errorf("UnmarshalInput() mismatch (-want +got):\n%s", diff)76 }77 }78 })79 }80}81