github.com/apptainer/singularity@v3.1.1+incompatible/internal/pkg/client/cache/net_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 TestNet(t *testing.T) {
    15  	tests := []struct {
    16  		name     string
    17  		env      string
    18  		expected string
    19  	}{
    20  		{"Default Net", "", filepath.Join(cacheDefault, "net")},
    21  		{"Custom Net", cacheCustom, filepath.Join(cacheCustom, "net")},
    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 := Net(); r != tt.expected {
    32  				t.Errorf("Unexpected result: %s (expected %s)", r, tt.expected)
    33  			}
    34  		})
    35  	}
    36  }