TestBuildAWFConfigSchemaURL verifies that buildAWFConfigSchemaURL returns a release-pinned URL that tracks the AWF version in use.
(t *testing.T)
| 935 | // TestBuildAWFConfigSchemaURL verifies that buildAWFConfigSchemaURL returns a release-pinned |
| 936 | // URL that tracks the AWF version in use. |
| 937 | func TestBuildAWFConfigSchemaURL(t *testing.T) { |
| 938 | tests := []struct { |
| 939 | name string |
| 940 | firewallConfig *FirewallConfig |
| 941 | wantContains string |
| 942 | wantURL string // exact URL match, takes precedence over wantContains when set |
| 943 | }{ |
| 944 | { |
| 945 | name: "nil config uses DefaultFirewallVersion", |
| 946 | firewallConfig: nil, |
| 947 | wantContains: string(constants.DefaultFirewallVersion), |
| 948 | }, |
| 949 | { |
| 950 | name: "empty version uses DefaultFirewallVersion", |
| 951 | firewallConfig: &FirewallConfig{Enabled: true}, |
| 952 | wantContains: string(constants.DefaultFirewallVersion), |
| 953 | }, |
| 954 | { |
| 955 | name: "pinned version with v prefix", |
| 956 | firewallConfig: &FirewallConfig{Enabled: true, Version: "v0.24.0"}, |
| 957 | wantContains: "v0.24.0", |
| 958 | }, |
| 959 | { |
| 960 | name: "pinned version without v prefix gets v added", |
| 961 | firewallConfig: &FirewallConfig{Enabled: true, Version: "0.24.0"}, |
| 962 | wantContains: "v0.24.0", |
| 963 | }, |
| 964 | { |
| 965 | name: "latest version uses /releases/latest/download/ URL", |
| 966 | firewallConfig: &FirewallConfig{Enabled: true, Version: "latest"}, |
| 967 | wantURL: "https://github.com/github/gh-aw-firewall/releases/latest/download/awf-config.schema.json", |
| 968 | }, |
| 969 | } |
| 970 | |
| 971 | for _, tt := range tests { |
| 972 | t.Run(tt.name, func(t *testing.T) { |
| 973 | url := buildAWFConfigSchemaURL(tt.firewallConfig) |
| 974 | |
| 975 | if tt.wantURL != "" { |
| 976 | assert.Equal(t, tt.wantURL, url, "schema URL should match the expected URL exactly") |
| 977 | return |
| 978 | } |
| 979 | |
| 980 | assert.Contains(t, url, tt.wantContains, "schema URL should contain the expected version") |
| 981 | assert.Contains(t, url, "https://github.com/github/gh-aw-firewall/releases/download/", "schema URL should use the release download path") |
| 982 | assert.True(t, strings.HasSuffix(url, "awf-config.schema.json"), "schema URL should end with awf-config.schema.json") |
| 983 | }) |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | // TestBuildAWFConfigJSON_SchemaURLIsVersionPinned verifies that the $schema field in the |
| 988 | // generated config uses a release-pinned URL that matches the AWF version in use. |
nothing calls this directly
no test coverage detected