@@ -521,11 +521,56 @@ func TestMapFields(t *testing.T) {
521521 optimizer := types .ObjectValueMust (optimizerTypes , map [string ]attr.Value {
522522 "enabled" : types .BoolValue (true ),
523523 })
524+
525+ redirectsAttrTypes := configTypes ["redirects" ].(basetypes.ObjectType ).AttrTypes
526+
524527 config := types .ObjectValueMust (configTypes , map [string ]attr.Value {
525528 "backend" : backend ,
526529 "regions" : regionsFixture ,
527530 "blocked_countries" : blockedCountriesFixture ,
528531 "optimizer" : types .ObjectNull (optimizerTypes ),
532+ "redirects" : types .ObjectNull (redirectsAttrTypes ),
533+ })
534+
535+ redirectsInput := & cdn.RedirectConfig {
536+ Rules : & []cdn.RedirectRule {
537+ {
538+ Description : cdn .PtrString ("Test redirect" ),
539+ Enabled : cdn .PtrBool (true ),
540+ TargetUrl : cdn .PtrString ("https://example.com/redirect" ),
541+ StatusCode : cdn .RedirectRuleStatusCode (301 ).Ptr (),
542+ RuleMatchCondition : cdn .MatchCondition ("ANY" ).Ptr (),
543+ Matchers : & []cdn.Matcher {
544+ {
545+ Values : & []string {"/shop/*" },
546+ ValueMatchCondition : cdn .MatchCondition ("ANY" ).Ptr (),
547+ },
548+ },
549+ },
550+ },
551+ }
552+
553+ matcherValuesExpected := types .ListValueMust (types .StringType , []attr.Value {
554+ types .StringValue ("/shop/*" ),
555+ })
556+ matcherValExpected := types .ObjectValueMust (matcherTypes , map [string ]attr.Value {
557+ "values" : matcherValuesExpected ,
558+ "value_match_condition" : types .StringValue ("ANY" ),
559+ })
560+ matchersListExpected := types .ListValueMust (types.ObjectType {AttrTypes : matcherTypes }, []attr.Value {matcherValExpected })
561+
562+ ruleValExpected := types .ObjectValueMust (redirectRuleTypes , map [string ]attr.Value {
563+ "description" : types .StringValue ("Test redirect" ),
564+ "enabled" : types .BoolValue (true ),
565+ "target_url" : types .StringValue ("https://example.com/redirect" ),
566+ "status_code" : types .Int32Value (301 ),
567+ "rule_match_condition" : types .StringValue ("ANY" ),
568+ "matchers" : matchersListExpected ,
569+ })
570+ rulesListExpected := types .ListValueMust (types.ObjectType {AttrTypes : redirectRuleTypes }, []attr.Value {ruleValExpected })
571+
572+ redirectsConfigExpected := types .ObjectValueMust (redirectsTypes , map [string ]attr.Value {
573+ "rules" : rulesListExpected ,
529574 })
530575
531576 emtpyErrorsList := types .ListValueMust (types .StringType , []attr.Value {})
@@ -607,6 +652,7 @@ func TestMapFields(t *testing.T) {
607652 "regions" : regionsFixture ,
608653 "blocked_countries" : blockedCountriesFixture ,
609654 "optimizer" : types .ObjectNull (optimizerTypes ),
655+ "redirects" : types .ObjectNull (redirectsAttrTypes ),
610656 })
611657 tests := map [string ]struct {
612658 Input * cdn.Distribution
@@ -626,6 +672,7 @@ func TestMapFields(t *testing.T) {
626672 "regions" : regionsFixture ,
627673 "optimizer" : optimizer ,
628674 "blocked_countries" : blockedCountriesFixture ,
675+ "redirects" : types .ObjectNull (redirectsAttrTypes ),
629676 })
630677 }),
631678 Input : distributionFixture (func (d * cdn.Distribution ) {
@@ -651,13 +698,29 @@ func TestMapFields(t *testing.T) {
651698 "regions" : regionsFixture ,
652699 "optimizer" : types .ObjectNull (optimizerTypes ),
653700 "blocked_countries" : blockedCountriesFixture ,
701+ "redirects" : types .ObjectNull (redirectsAttrTypes ),
654702 })
655703 }),
656704 Input : distributionFixture (func (d * cdn.Distribution ) {
657705 d .Config .Backend .HttpBackend .Geofencing = & geofencingInput
658706 }),
659707 IsValid : true ,
660708 },
709+ "happy_path_with_redirects" : {
710+ Expected : expectedModel (func (m * Model ) {
711+ m .Config = types .ObjectValueMust (configTypes , map [string ]attr.Value {
712+ "backend" : backend ,
713+ "regions" : regionsFixture ,
714+ "optimizer" : types .ObjectNull (optimizerTypes ),
715+ "blocked_countries" : blockedCountriesFixture ,
716+ "redirects" : redirectsConfigExpected ,
717+ })
718+ }),
719+ Input : distributionFixture (func (d * cdn.Distribution ) {
720+ d .Config .Redirects = redirectsInput
721+ }),
722+ IsValid : true ,
723+ },
661724 "happy_path_status_error" : {
662725 Expected : expectedModel (func (m * Model ) {
663726 m .Status = types .StringValue ("ERROR" )
0 commit comments