github.com/DataDog/datadog-agent/pkg/security/secl@v0.55.0-devel.0.20240517055856-10c4965fea94/model/consts_test.go (about) 1 // Unless explicitly stated otherwise all files in this repository are licensed 2 // under the Apache License Version 2.0. 3 // This product includes software developed at Datadog (https://www.datadoghq.com/). 4 // Copyright 2016-present Datadog, Inc. 5 6 //go:build linux 7 8 // Package model holds model related files 9 package model 10 11 import ( 12 "fmt" 13 "syscall" 14 "testing" 15 ) 16 17 func TestFlagsToString(t *testing.T) { 18 initConstants() 19 20 str := OpenFlags(syscall.O_EXCL | syscall.O_TRUNC).String() 21 if str != "O_RDONLY | O_EXCL | O_TRUNC" { 22 t.Errorf("expected flags not found, got: %s", str) 23 } 24 25 str = FileMode(syscall.S_IWGRP | syscall.S_IRUSR).String() 26 if str != "S_IRUSR | S_IWGRP" { 27 t.Errorf("expected flags not found, got: %s", str) 28 } 29 30 str = OpenFlags(syscall.O_EXCL | syscall.O_TRUNC | 1<<32).String() 31 if str != fmt.Sprintf("O_RDONLY | %d | O_EXCL | O_TRUNC", 1<<32) { 32 t.Errorf("expected flags not found, got: %s", str) 33 } 34 35 str = OpenFlags(syscall.O_RDONLY).String() 36 if str != "O_RDONLY" { 37 t.Errorf("expected flags not found, got: %s", str) 38 } 39 40 str = OpenFlags(syscall.O_RDONLY | syscall.O_RDWR).String() 41 if str != "O_RDWR" { 42 t.Errorf("expected flags not found, got: %s", str) 43 } 44 45 str = OpenFlags(syscall.O_RDONLY | syscall.O_CLOEXEC).String() 46 if str != "O_RDONLY | O_CLOEXEC" { 47 t.Errorf("expected flags not found, got: %s", str) 48 } 49 }