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

     1  // This file is part of arduino-cloud-cli.
     2  //
     3  // Copyright (C) 2021 ARDUINO SA (http://www.arduino.cc/)
     4  //
     5  // This program is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU Affero General Public License as published
     7  // by the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // This program is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU Affero General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Affero General Public License
    16  // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    17  
    18  package ota
    19  
    20  import (
    21  	"bytes"
    22  	"fmt"
    23  	"os"
    24  	"testing"
    25  	"text/tabwriter"
    26  
    27  	"gotest.tools/assert"
    28  )
    29  
    30  func TestVersionWithCompressionEnabled(t *testing.T) {
    31  
    32  	version := Version{
    33  		Compression: true,
    34  	}
    35  
    36  	expected := []byte{0, 0, 0, 0, 0, 0, 0, 0x40}
    37  	actual := version.Bytes()
    38  
    39  	// create a tabwriter for formatting the output
    40  	w := new(tabwriter.Writer)
    41  
    42  	// Format in tab-separated columns with a tab stop of 8.
    43  	w.Init(os.Stdout, 0, 8, 0, '\t', 0)
    44  
    45  	fmt.Fprintf(w, "Binary:\t%0.8bb (expected)\n", expected)
    46  	fmt.Fprintf(w, "Binary:\t%0.8bb (actual)\n", actual)
    47  	w.Flush()
    48  
    49  	res := bytes.Compare(expected, actual)
    50  	assert.Assert(t, res == 0) // 0 means equal
    51  }