github.com/posener/gitfs@v1.2.2-0.20200410105819-ea4e48d73ab9/cmd/gitfs/templates_test.go (about)

     1  // Code generated by gitfs; DO NOT EDIT
     2  package main
     3  
     4  import (
     5  	"context"
     6  	"testing"
     7  
     8  	"github.com/posener/gitfs"
     9  	"github.com/posener/gitfs/fsutil"
    10  )
    11  
    12  // TestTemplates checks that packed binary matches the local conent.
    13  // To skip generating this test run gitfs with -skip-test-gen flag.
    14  func TestTemplates(t *testing.T) {
    15  	ctx := context.Background()
    16  	projects := []struct {
    17  		project string
    18  		glob    []string
    19  	}{
    20  		{
    21  			project: "github.com/posener/gitfs/cmd/gitfs/templates",
    22  		},
    23  	}
    24  	for _, tt := range projects {
    25  		t.Run(tt.project, func(t *testing.T) {
    26  			binary, err := gitfs.New(ctx, tt.project, gitfs.OptGlob(tt.glob...))
    27  			if err != nil {
    28  				t.Fatalf("Failed loading binary project %q: %s", tt.project, err)
    29  			}
    30  			local, err := gitfs.New(ctx, tt.project, gitfs.OptLocal("."), gitfs.OptGlob(tt.glob...))
    31  			if err != nil {
    32  				t.Fatalf("Failed loading local project %q: %s", tt.project, err)
    33  			}
    34  			diff, err := fsutil.Diff(local, binary)
    35  			if err != nil {
    36  				t.Fatalf("Failed performing filesystem diff: %s", err)
    37  			}
    38  			diff.A = "local"
    39  			diff.B = "binary"
    40  
    41  			if d := diff.String(); d != "" {
    42  				t.Errorf("Filesystem was modified after last binary generated. Please regenerae.\nDiff:\n%s", d)
    43  			}
    44  		})
    45  	}
    46  }