github.com/apptainer/singularity@v3.1.1+incompatible/internal/pkg/client/cache/oci_test.go (about)

     1  // Copyright (c) 2018, Sylabs Inc. All rights reserved.
     2  // This software is licensed under a 3-clause BSD license. Please consult the
     3  // LICENSE.md file distributed with the sources of this project regarding your
     4  // rights to use or distribute this software.
     5  
     6  package cache
     7  
     8  import (
     9  	"os"
    10  	"path/filepath"
    11  	"testing"
    12  )
    13  
    14  func TestOciBlob(t *testing.T) {
    15  	tests := []struct {
    16  		name     string
    17  		env      string
    18  		expected string
    19  	}{
    20  		{"Default OCI blob", "", filepath.Join(cacheDefault, "oci")},
    21  		{"Custom OCI blob", cacheCustom, filepath.Join(cacheCustom, "oci")},
    22  	}
    23  
    24  	for _, tt := range tests {
    25  		t.Run(tt.name, func(t *testing.T) {
    26  			defer Clean()
    27  			defer os.Unsetenv(DirEnv)
    28  
    29  			os.Setenv(DirEnv, tt.env)
    30  
    31  			if r := OciBlob(); r != tt.expected {
    32  				t.Errorf("Unexpected result: %s (expected %s)", r, tt.expected)
    33  			}
    34  		})
    35  	}
    36  }
    37  
    38  func TestOciTemp(t *testing.T) {
    39  	tests := []struct {
    40  		name     string
    41  		env      string
    42  		expected string
    43  	}{
    44  		{"Default OCI temp", "", filepath.Join(cacheDefault, "oci-tmp")},
    45  		{"Custom OCI temp", cacheCustom, filepath.Join(cacheCustom, "oci-tmp")},
    46  	}
    47  
    48  	for _, tt := range tests {
    49  		t.Run(tt.name, func(t *testing.T) {
    50  			defer Clean()
    51  			defer os.Unsetenv(DirEnv)
    52  
    53  			os.Setenv(DirEnv, tt.env)
    54  
    55  			if r := OciTemp(); r != tt.expected {
    56  				t.Errorf("Unexpected result: %s (expected %s)", r, tt.expected)
    57  			}
    58  		})
    59  	}
    60  }