github.com/arduino/arduino-cloud-cli@v0.0.0-20240517070944-e7a449561083/internal/lzss/lzss_test.go (about)

     1  package lzss
     2  
     3  import (
     4  	"bytes"
     5  	"io/ioutil"
     6  	"testing"
     7  )
     8  
     9  func TestEncode(t *testing.T) {
    10  	tests := []struct {
    11  		name    string
    12  		infile  string
    13  		outfile string
    14  	}{
    15  		{
    16  			name:    "blink",
    17  			infile:  "testdata/blink.bin",
    18  			outfile: "testdata/blink.lzss",
    19  		},
    20  		{
    21  			name:    "cloud sketch",
    22  			infile:  "testdata/cloud.bin",
    23  			outfile: "testdata/cloud.lzss",
    24  		},
    25  	}
    26  
    27  	for _, tt := range tests {
    28  		t.Run(tt.name, func(t *testing.T) {
    29  			input, err := ioutil.ReadFile(tt.infile)
    30  			if err != nil {
    31  				t.Fatal("couldn't open test file")
    32  			}
    33  
    34  			want, err := ioutil.ReadFile(tt.outfile)
    35  			if err != nil {
    36  				t.Fatal("couldn't open test file")
    37  			}
    38  
    39  			got := Encode(input)
    40  			if !bytes.Equal(want, got) {
    41  				t.Error("encoding failed")
    42  			}
    43  		})
    44  	}
    45  }