-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3151 from terraform-providers/f/api-management-en…
…hancements r/api_management: support for `sign_in`, `sign_up` and `policy` blocks
- Loading branch information
Showing
7 changed files
with
734 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package suppress | ||
|
||
import ( | ||
"encoding/xml" | ||
"io" | ||
"reflect" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func XmlDiff(_, old, new string, _ *schema.ResourceData) bool { | ||
oldTokens, err := expandXmlTokensFromString(old) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
newTokens, err := expandXmlTokensFromString(new) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
return reflect.DeepEqual(oldTokens, newTokens) | ||
} | ||
|
||
// This function will extract all XML tokens from a string, but ignoring all white-space tokens | ||
func expandXmlTokensFromString(input string) ([]xml.Token, error) { | ||
decoder := xml.NewDecoder(strings.NewReader(input)) | ||
tokens := make([]xml.Token, 0) | ||
for { | ||
token, err := decoder.Token() | ||
if err != nil { | ||
if err == io.EOF { | ||
break | ||
} | ||
return nil, err | ||
} | ||
if chars, ok := token.(xml.CharData); ok { | ||
text := string(chars) | ||
if strings.TrimSpace(text) == "" { | ||
continue | ||
} | ||
} | ||
tokens = append(tokens, xml.CopyToken(token)) | ||
} | ||
return tokens, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package suppress | ||
|
||
import "testing" | ||
|
||
func TestXmlDiff(t *testing.T) { | ||
cases := []struct { | ||
Name string | ||
XmlA string | ||
XmlB string | ||
Suppress bool | ||
}{ | ||
{ | ||
Name: "empty", | ||
XmlA: "", | ||
XmlB: "", | ||
Suppress: true, | ||
}, | ||
{ | ||
Name: "neither are xml", | ||
XmlA: "this is not an xml", | ||
XmlB: "neither is this", | ||
Suppress: false, | ||
}, | ||
{ | ||
Name: "identical texts", | ||
XmlA: "this is not an xml", | ||
XmlB: "this is not an xml", | ||
Suppress: true, | ||
}, | ||
{ | ||
Name: "xml vs text", | ||
XmlA: "<r></r>", | ||
XmlB: "this is not an xml", | ||
Suppress: false, | ||
}, | ||
{ | ||
Name: "text vs xml", | ||
XmlA: "this is not an xml", | ||
XmlB: "<r></r>", | ||
Suppress: false, | ||
}, | ||
{ | ||
Name: "identical xml", | ||
XmlA: "<r><c></c></r>", | ||
XmlB: "<r><c></c></r>", | ||
Suppress: true, | ||
}, | ||
{ | ||
Name: "xml with different line endings", | ||
XmlA: "<r>\n<c>\n</c>\n</r>", | ||
XmlB: "<r>\r\n<c>\r\n</c>\r\n</r>", | ||
Suppress: true, | ||
}, | ||
{ | ||
Name: "xml with different indentations", | ||
XmlA: "<r>\n <c>\n </c>\n</r>", | ||
XmlB: "<r>\r\n\t<c>\r\n\t</c>\r\n</r>", | ||
Suppress: true, | ||
}, | ||
{ | ||
Name: "xml with different quotation marks", | ||
XmlA: "<r><c attr=\"test\"></c></r>", | ||
XmlB: "<r>\r\n\t<c attr='test'>\r\n\t</c>\r\n</r>", | ||
Suppress: true, | ||
}, | ||
{ | ||
Name: "xml with different spaces", | ||
XmlA: "<r><c attr = 'test'></c></r>", | ||
XmlB: "<r>\r\n\t<c attr='test'>\r\n\t</c>\r\n</r>", | ||
Suppress: true, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.Name, func(t *testing.T) { | ||
if XmlDiff("test", tc.XmlA, tc.XmlB, nil) != tc.Suppress { | ||
t.Fatalf("Expected XmlDiff to return %t for '%q' == '%q'", tc.Suppress, tc.XmlA, tc.XmlB) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.