TestValidateStringEnumField tests the validateStringEnumField helper.
(t *testing.T)
| 805 | |
| 806 | // TestValidateStringEnumField tests the validateStringEnumField helper. |
| 807 | func TestValidateStringEnumField(t *testing.T) { |
| 808 | allowed := []string{"am", "bundle"} |
| 809 | tests := []struct { |
| 810 | name string |
| 811 | configData map[string]any |
| 812 | wantPresent bool |
| 813 | wantValue any |
| 814 | }{ |
| 815 | { |
| 816 | name: "valid enum value is kept", |
| 817 | configData: map[string]any{"patch-format": "am"}, |
| 818 | wantPresent: true, |
| 819 | wantValue: "am", |
| 820 | }, |
| 821 | { |
| 822 | name: "another valid enum value is kept", |
| 823 | configData: map[string]any{"patch-format": "bundle"}, |
| 824 | wantPresent: true, |
| 825 | wantValue: "bundle", |
| 826 | }, |
| 827 | { |
| 828 | name: "invalid literal string is removed", |
| 829 | configData: map[string]any{"patch-format": "invalid"}, |
| 830 | wantPresent: false, |
| 831 | }, |
| 832 | { |
| 833 | name: "non-string value is removed", |
| 834 | configData: map[string]any{"patch-format": 42}, |
| 835 | wantPresent: false, |
| 836 | }, |
| 837 | { |
| 838 | name: "absent field is a no-op", |
| 839 | configData: map[string]any{"other": "value"}, |
| 840 | wantPresent: false, |
| 841 | }, |
| 842 | { |
| 843 | name: "nil configData is a no-op", |
| 844 | configData: nil, |
| 845 | wantPresent: false, |
| 846 | }, |
| 847 | { |
| 848 | name: "GitHub Actions expression is passed through", |
| 849 | configData: map[string]any{"patch-format": "${{ inputs.patch-format }}"}, |
| 850 | wantPresent: true, |
| 851 | wantValue: "${{ inputs.patch-format }}", |
| 852 | }, |
| 853 | { |
| 854 | name: "expression with spaces is passed through", |
| 855 | configData: map[string]any{"patch-format": "${{ inputs.format || 'am' }}"}, |
| 856 | wantPresent: true, |
| 857 | wantValue: "${{ inputs.format || 'am' }}", |
| 858 | }, |
| 859 | } |
| 860 | |
| 861 | for _, tt := range tests { |
| 862 | t.Run(tt.name, func(t *testing.T) { |
| 863 | validateStringEnumField(tt.configData, "patch-format", allowed, nil) |
| 864 | if tt.configData == nil { |
nothing calls this directly
no test coverage detected