...

Source file src/github.com/google/go-containerregistry/internal/windows/windows_test.go

Documentation: github.com/google/go-containerregistry/internal/windows

     1  // Copyright 2021 Google LLC All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //    http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package windows
    16  
    17  import (
    18  	"archive/tar"
    19  	"errors"
    20  	"io"
    21  	"reflect"
    22  	"strings"
    23  	"testing"
    24  
    25  	"github.com/google/go-containerregistry/pkg/v1/tarball"
    26  )
    27  
    28  func TestWindows(t *testing.T) {
    29  	tarLayer, err := tarball.LayerFromFile("../../pkg/v1/tarball/testdata/content.tar")
    30  	if err != nil {
    31  		t.Fatalf("Unable to create layer from tar file: %v", err)
    32  	}
    33  
    34  	win, err := Windows(tarLayer)
    35  	if err != nil {
    36  		t.Fatalf("Windows: %v", err)
    37  	}
    38  	if _, err := Windows(win); err == nil {
    39  		t.Error("expected an error double-Windowsifying a layer; got nil")
    40  	}
    41  
    42  	rc, err := win.Uncompressed()
    43  	if err != nil {
    44  		t.Fatalf("Uncompressed: %v", err)
    45  	}
    46  	defer rc.Close()
    47  	tr := tar.NewReader(rc)
    48  	var sawHives, sawFiles bool
    49  	for {
    50  		h, err := tr.Next()
    51  		if errors.Is(err, io.EOF) {
    52  			break
    53  		}
    54  		if h.Name == "Hives" && h.Typeflag == tar.TypeDir {
    55  			sawHives = true
    56  			continue
    57  		}
    58  		if h.Name == "Files" && h.Typeflag == tar.TypeDir {
    59  			sawFiles = true
    60  			continue
    61  		}
    62  		if !strings.HasPrefix(h.Name, "Files/") {
    63  			t.Errorf("tar entry %q didn't have Files prefix", h.Name)
    64  		}
    65  		if h.Format != tar.FormatPAX {
    66  			t.Errorf("tar entry %q had unexpected Format; got %v, want %v", h.Name, h.Format, tar.FormatPAX)
    67  		}
    68  		want := map[string]string{
    69  			"MSWINDOWS.rawsd": userOwnerAndGroupSID,
    70  		}
    71  		if !reflect.DeepEqual(h.PAXRecords, want) {
    72  			t.Errorf("tar entry %q: got %v, want %v", h.Name, h.PAXRecords, want)
    73  		}
    74  	}
    75  	if !sawHives {
    76  		t.Errorf("didn't see Hives/ directory")
    77  	}
    78  	if !sawFiles {
    79  		t.Errorf("didn't see Files/ directory")
    80  	}
    81  }
    82  

View as plain text