(t *testing.T)
| 126 | } |
| 127 | |
| 128 | func TestValFromJqPath(t *testing.T) { |
| 129 | tests := []struct { |
| 130 | name string |
| 131 | path string |
| 132 | jsn string |
| 133 | want any |
| 134 | wantErr string |
| 135 | }{ |
| 136 | { |
| 137 | name: "returns one value", |
| 138 | path: `.token`, |
| 139 | jsn: `{"token":"abc123"}`, |
| 140 | want: "abc123", |
| 141 | }, |
| 142 | { |
| 143 | name: "errors on missing value", |
| 144 | path: `.missing`, |
| 145 | jsn: `{"token":"abc123"}`, |
| 146 | wantErr: "value not found", |
| 147 | }, |
| 148 | { |
| 149 | name: "errors on multiple values", |
| 150 | path: `.items[].id`, |
| 151 | jsn: `{"items":[{"id":1},{"id":2}]}`, |
| 152 | wantErr: "invalid number of values found", |
| 153 | }, |
| 154 | } |
| 155 | |
| 156 | for _, tt := range tests { |
| 157 | t.Run(tt.name, func(t *testing.T) { |
| 158 | got, err := valFromJqPath(tt.path, tt.jsn) |
| 159 | if tt.wantErr != "" { |
| 160 | if err == nil { |
| 161 | t.Fatalf("expected error %q", tt.wantErr) |
| 162 | } |
| 163 | if err.Error() != tt.wantErr { |
| 164 | t.Fatalf("expected error %q, got %q", tt.wantErr, err.Error()) |
| 165 | } |
| 166 | return |
| 167 | } |
| 168 | if err != nil { |
| 169 | t.Fatalf("unexpected error: %v", err) |
| 170 | } |
| 171 | if !reflect.DeepEqual(got, tt.want) { |
| 172 | t.Fatalf("valFromJqPath() = %#v, want %#v", got, tt.want) |
| 173 | } |
| 174 | }) |
| 175 | } |
| 176 | } |
nothing calls this directly
no test coverage detected