github.com/abemedia/appcast@v0.4.0/integrations/sparkle/rss_test.go (about)

     1  package sparkle_test
     2  
     3  import (
     4  	"encoding/xml"
     5  	"testing"
     6  
     7  	"github.com/abemedia/appcast/integrations/sparkle"
     8  	"github.com/google/go-cmp/cmp"
     9  )
    10  
    11  func TestRSSMarshalUnmarshal(t *testing.T) {
    12  	in := &sparkle.RSS{
    13  		Channels: []*sparkle.Channel{{
    14  			Title:       "Title",
    15  			Description: "Description",
    16  			Link:        "https://example.com/sparkle.xml",
    17  			Language:    "en-gb",
    18  			Items: []*sparkle.Item{
    19  				{
    20  					Title:       "v1.0.0",
    21  					Description: &sparkle.CdataString{"Test"},
    22  					PubDate:     "Mon, 02 Jan 2006 15:04:05 +0000",
    23  					Version:     "1.0.0",
    24  					Tags:        &sparkle.Tags{CriticalUpdate: true},
    25  					Enclosure: &sparkle.Enclosure{
    26  						URL:         "https://example.com/test_v1.0.0.dmg",
    27  						OS:          "macos",
    28  						Version:     "1.0.0",
    29  						EDSignature: "test",
    30  						Length:      100,
    31  						Type:        "application/x-apple-diskimage",
    32  					},
    33  				},
    34  				{
    35  					Title:          "v1.1.0",
    36  					Description:    &sparkle.CdataString{"\n\t\t\t\t<h2>Test</h2>\n\t\t\t"},
    37  					PubDate:        "Mon, 02 Jan 2007 15:04:05 +0000",
    38  					Version:        "1.1.0",
    39  					CriticalUpdate: &sparkle.CriticalUpdate{Version: "1.0.0"},
    40  					Enclosure: &sparkle.Enclosure{
    41  						URL:         "https://example.com/test_v1.1.0.dmg",
    42  						OS:          "macos",
    43  						Version:     "1.1.0",
    44  						EDSignature: "test",
    45  						Length:      100,
    46  						Type:        "application/x-apple-diskimage",
    47  					},
    48  				},
    49  			},
    50  		}},
    51  	}
    52  
    53  	want := `<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/">
    54  	<channel>
    55  		<title>Title</title>
    56  		<link>https://example.com/sparkle.xml</link>
    57  		<description>Description</description>
    58  		<language>en-gb</language>
    59  		<item>
    60  			<title>v1.0.0</title>
    61  			<pubDate>Mon, 02 Jan 2006 15:04:05 +0000</pubDate>
    62  			<description><![CDATA[Test]]></description>
    63  			<sparkle:version>1.0.0</sparkle:version>
    64  			<sparkle:tags>
    65  				<sparkle:criticalUpdate></sparkle:criticalUpdate>
    66  			</sparkle:tags>
    67  			<enclosure url="https://example.com/test_v1.0.0.dmg" sparkle:os="macos" sparkle:version="1.0.0" sparkle:edSignature="test" length="100" type="application/x-apple-diskimage"></enclosure>
    68  		</item>
    69  		<item>
    70  			<title>v1.1.0</title>
    71  			<pubDate>Mon, 02 Jan 2007 15:04:05 +0000</pubDate>
    72  			<description><![CDATA[
    73  				<h2>Test</h2>
    74  			]]></description>
    75  			<sparkle:version>1.1.0</sparkle:version>
    76  			<sparkle:criticalUpdate sparkle:version="1.0.0"></sparkle:criticalUpdate>
    77  			<enclosure url="https://example.com/test_v1.1.0.dmg" sparkle:os="macos" sparkle:version="1.1.0" sparkle:edSignature="test" length="100" type="application/x-apple-diskimage"></enclosure>
    78  		</item>
    79  	</channel>
    80  </rss>`
    81  
    82  	b, err := xml.MarshalIndent(in, "", "\t")
    83  	if err != nil {
    84  		t.Fatal(err)
    85  	}
    86  
    87  	if diff := cmp.Diff(want, string(b)); diff != "" {
    88  		t.Fatal(diff)
    89  	}
    90  
    91  	got := &sparkle.RSS{}
    92  	if err = xml.Unmarshal(b, got); err != nil {
    93  		t.Fatal(err)
    94  	}
    95  
    96  	if diff := cmp.Diff(in, got); diff != "" {
    97  		t.Fatal(diff)
    98  	}
    99  }