mirror of
				https://github.com/containers/podman.git
				synced 2025-10-25 18:25:59 +08:00 
			
		
		
		
	 97c9115c02
			
		
	
	97c9115c02
	
	
	
		
			
			Don't sort OCI hooks using the locale collation order; it does not make sense for the same system-wide directory to be interpreted differently depending on the user's LC_COLLATE setting, and the language-specific collation order can even change over time. Besides, the current collation order determination code has never worked with the most common LC_COLLATE values like en_US.UTF-8. Ideally, we would like to just order based on Unicode code points to be reliably stable, but the existing implementation is case-insensitive, so we are forced to rely on the unicode case mapping tables at least. (This gives up on canonicalization and width-insensitivity, potentially breaking users who rely on these previously documented properties.) Signed-off-by: Miloslav Trmač <mitr@redhat.com>
		
			
				
	
	
		
			82 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			82 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package libpod
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"fmt"
 | |
| 	"io/ioutil"
 | |
| 	"os"
 | |
| 	"path/filepath"
 | |
| 	"runtime"
 | |
| 	"strings"
 | |
| 	"testing"
 | |
| 
 | |
| 	rspec "github.com/opencontainers/runtime-spec/specs-go"
 | |
| 	"github.com/stretchr/testify/assert"
 | |
| )
 | |
| 
 | |
| // hookPath is the path to an example hook executable.
 | |
| var hookPath string
 | |
| 
 | |
| func TestPostDeleteHooks(t *testing.T) {
 | |
| 	ctx := context.Background()
 | |
| 	dir, err := ioutil.TempDir("", "libpod_test_")
 | |
| 	if err != nil {
 | |
| 		t.Fatal(err)
 | |
| 	}
 | |
| 	defer os.RemoveAll(dir)
 | |
| 
 | |
| 	statePath := filepath.Join(dir, "state")
 | |
| 	copyPath := filepath.Join(dir, "copy")
 | |
| 	c := Container{
 | |
| 		config: &ContainerConfig{
 | |
| 			ID: "123abc",
 | |
| 			Spec: &rspec.Spec{
 | |
| 				Annotations: map[string]string{
 | |
| 					"a": "b",
 | |
| 				},
 | |
| 			},
 | |
| 			StaticDir: dir, // not the bundle, but good enough for this test
 | |
| 		},
 | |
| 		state: &ContainerState{
 | |
| 			ExtensionStageHooks: map[string][]rspec.Hook{
 | |
| 				"poststop": {
 | |
| 					rspec.Hook{
 | |
| 						Path: hookPath,
 | |
| 						Args: []string{"sh", "-c", fmt.Sprintf("cat >%s", statePath)},
 | |
| 					},
 | |
| 					rspec.Hook{
 | |
| 						Path: "/does/not/exist",
 | |
| 					},
 | |
| 					rspec.Hook{
 | |
| 						Path: hookPath,
 | |
| 						Args: []string{"sh", "-c", fmt.Sprintf("cp %s %s", statePath, copyPath)},
 | |
| 					},
 | |
| 				},
 | |
| 			},
 | |
| 		},
 | |
| 	}
 | |
| 	err = c.postDeleteHooks(ctx)
 | |
| 	if err != nil {
 | |
| 		t.Fatal(err)
 | |
| 	}
 | |
| 
 | |
| 	stateRegexp := `{"ociVersion":"1\.0\.1-dev","id":"123abc","status":"stopped","bundle":"` + strings.TrimSuffix(os.TempDir(), "/") + `/libpod_test_[0-9]*","annotations":{"a":"b"}}`
 | |
| 	for _, path := range []string{statePath, copyPath} {
 | |
| 		t.Run(path, func(t *testing.T) {
 | |
| 			content, err := ioutil.ReadFile(path)
 | |
| 			if err != nil {
 | |
| 				t.Fatal(err)
 | |
| 			}
 | |
| 			assert.Regexp(t, stateRegexp, string(content))
 | |
| 		})
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func init() {
 | |
| 	if runtime.GOOS != "windows" {
 | |
| 		hookPath = "/bin/sh"
 | |
| 	} else {
 | |
| 		panic("we need a reliable executable path on Windows")
 | |
| 	}
 | |
| }
 |