github.com/safing/portbase@v0.19.5/updater/indexes_test.go (about)

     1  package updater
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  var (
    11  	oldFormat = `{
    12  	"all/ui/modules/assets.zip": "0.3.0",
    13  	"all/ui/modules/portmaster.zip": "0.2.4",
    14  	"linux_amd64/core/portmaster-core": "0.8.13"
    15  }`
    16  
    17  	newFormat = `{
    18  	"Channel": "stable",
    19  	"Published": "2022-01-02T00:00:00Z",
    20  	"Releases": {
    21  		"all/ui/modules/assets.zip": "0.3.0",
    22  		"all/ui/modules/portmaster.zip": "0.2.4",
    23  		"linux_amd64/core/portmaster-core": "0.8.13"
    24  	}
    25  }`
    26  
    27  	formatTestChannel  = "stable"
    28  	formatTestReleases = map[string]string{
    29  		"all/ui/modules/assets.zip":        "0.3.0",
    30  		"all/ui/modules/portmaster.zip":    "0.2.4",
    31  		"linux_amd64/core/portmaster-core": "0.8.13",
    32  	}
    33  )
    34  
    35  func TestIndexParsing(t *testing.T) {
    36  	t.Parallel()
    37  
    38  	lastRelease, err := time.Parse(time.RFC3339, "2022-01-01T00:00:00Z")
    39  	if err != nil {
    40  		t.Fatal(err)
    41  	}
    42  
    43  	oldIndexFile, err := ParseIndexFile([]byte(oldFormat), formatTestChannel, lastRelease)
    44  	if err != nil {
    45  		t.Fatal(err)
    46  	}
    47  
    48  	newIndexFile, err := ParseIndexFile([]byte(newFormat), formatTestChannel, lastRelease)
    49  	if err != nil {
    50  		t.Fatal(err)
    51  	}
    52  
    53  	assert.Equal(t, formatTestChannel, oldIndexFile.Channel, "channel should be the same")
    54  	assert.Equal(t, formatTestChannel, newIndexFile.Channel, "channel should be the same")
    55  	assert.Equal(t, formatTestReleases, oldIndexFile.Releases, "releases should be the same")
    56  	assert.Equal(t, formatTestReleases, newIndexFile.Releases, "releases should be the same")
    57  }