github.com/auxten/ginkgo@v0.0.0-20220130172820-7d98ad59d232/seed/scan_test.go (about)

     1  package seed
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"testing"
     7  
     8  	log "github.com/sirupsen/logrus"
     9  )
    10  
    11  func TestMakeSeed(t *testing.T) {
    12  	log.SetLevel(log.DebugLevel)
    13  	var testData = []struct {
    14  		blockSize int64
    15  		js        string
    16  	}{
    17  		{-1, `{"path":"","fileCount":10,"files":[{"mode":2147484141,"size":-1,"symPath":"","path":"../test","checkSum":null},{"mode":2147484141,"size":-1,"symPath":"","path":"../test/dir1","checkSum":null},{"mode":420,"size":0,"symPath":"","path":"../test/dir1/emptyFile","checkSum":null},{"mode":420,"size":9,"symPath":"","path":"../test/dir1/file11","checkSum":null},{"mode":420,"size":21,"symPath":"","path":"../test/dir1/file12","checkSum":null},{"mode":420,"size":13,"symPath":"","path":"../test/dir1/file13","checkSum":null},{"mode":2147484141,"size":-1,"symPath":"","path":"../test/dir2","checkSum":null},{"mode":2147484141,"size":-1,"symPath":"","path":"../test/dir2/dir21","checkSum":null},{"mode":134218221,"size":-2,"symPath":"dir1/file11","path":"../test/dir2/dir21/ln211","checkSum":null},{"mode":2147484141,"size":-1,"symPath":"","path":"../test/emptyDir","checkSum":null}],"blocks":[{"size":43,"startFile":3,"startOffset":0,"checkSum":null}],"blockSize":4194304,"vnodeCount":0,"hosts":null,"totalSize":43}`},
    18  		{10, `{"path":"","fileCount":10,"files":[{"mode":2147484141,"size":-1,"symPath":"","path":"../test","checkSum":null},{"mode":2147484141,"size":-1,"symPath":"","path":"../test/dir1","checkSum":null},{"mode":420,"size":0,"symPath":"","path":"../test/dir1/emptyFile","checkSum":null},{"mode":420,"size":9,"symPath":"","path":"../test/dir1/file11","checkSum":null},{"mode":420,"size":21,"symPath":"","path":"../test/dir1/file12","checkSum":null},{"mode":420,"size":13,"symPath":"","path":"../test/dir1/file13","checkSum":null},{"mode":2147484141,"size":-1,"symPath":"","path":"../test/dir2","checkSum":null},{"mode":2147484141,"size":-1,"symPath":"","path":"../test/dir2/dir21","checkSum":null},{"mode":134218221,"size":-2,"symPath":"dir1/file11","path":"../test/dir2/dir21/ln211","checkSum":null},{"mode":2147484141,"size":-1,"symPath":"","path":"../test/emptyDir","checkSum":null}],"blocks":[{"size":10,"startFile":3,"startOffset":0,"checkSum":null},{"size":10,"startFile":4,"startOffset":1,"checkSum":null},{"size":10,"startFile":4,"startOffset":11,"checkSum":null},{"size":10,"startFile":5,"startOffset":0,"checkSum":null},{"size":3,"startFile":5,"startOffset":10,"checkSum":null}],"blockSize":10,"vnodeCount":0,"hosts":null,"totalSize":43}`},
    19  	}
    20  	for i, d := range testData {
    21  		t.Run(fmt.Sprintf("make seed %d", i), func(t *testing.T) {
    22  
    23  			seed, err := MakeSeed("../test/../test", d.blockSize)
    24  			if err != nil {
    25  				t.Error(err)
    26  			}
    27  			jb, err := json.Marshal(seed)
    28  			if err != nil {
    29  				t.Error(err)
    30  			}
    31  			if string(jb) != d.js {
    32  				t.Errorf("Expected %s, got %s", d.js, string(jb))
    33  			}
    34  		})
    35  	}
    36  
    37  	seed2, err := MakeSeed("./notExist", 0)
    38  	if err == nil || seed2 != nil {
    39  		t.Error(err)
    40  	}
    41  }