|
| 1 | +// Copyright 2023 RetailNext, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package puppet |
| 16 | + |
| 17 | +import ( |
| 18 | + "testing" |
| 19 | +) |
| 20 | + |
| 21 | +func TestParseAgentDisabledLockfile(t *testing.T) { |
| 22 | + testCases := map[string]struct { |
| 23 | + wantDisabledMessage string |
| 24 | + wantError bool |
| 25 | + }{ |
| 26 | + "404": {wantError: true}, |
| 27 | + "empty": {wantError: true}, |
| 28 | + "malformed": {wantError: true}, |
| 29 | + "empty_hash": {}, |
| 30 | + "disabled_message": {wantDisabledMessage: "testing unmarshalling"}, |
| 31 | + } |
| 32 | + |
| 33 | + for name, tc := range testCases { |
| 34 | + t.Run(name, func(t *testing.T) { |
| 35 | + got, err := ParseAgentDisabledLockfile("testdata/agent_disabled_lockfile/" + name + ".json") |
| 36 | + |
| 37 | + if tc.wantError { |
| 38 | + if err == nil { |
| 39 | + t.Errorf("expected fixture %q to produce error but got none", name) |
| 40 | + } |
| 41 | + } else { |
| 42 | + if err != nil { |
| 43 | + t.Errorf("expected fixture %q to parse properly but got error\n%s", name, err) |
| 44 | + } |
| 45 | + if got == nil { |
| 46 | + t.Errorf("expected fixture %q to parse properly but got nil as result", name) |
| 47 | + } |
| 48 | + } |
| 49 | + }) |
| 50 | + } |
| 51 | +} |
0 commit comments